WindowTransform.cpp 21.9 KB
Newer Older
A
Alexander Kuzmenkov 已提交
1 2 3 4
#include <Processors/Transforms/WindowTransform.h>

#include <Interpreters/ExpressionActions.h>

A
Alexander Kuzmenkov 已提交
5 6
#include <Common/Arena.h>

A
Alexander Kuzmenkov 已提交
7 8 9
namespace DB
{

A
Alexander Kuzmenkov 已提交
10 11 12
WindowTransform::WindowTransform(const Block & input_header_,
        const Block & output_header_,
        const WindowDescription & window_description_,
A
Alexander Kuzmenkov 已提交
13 14 15 16
        const std::vector<WindowFunctionDescription> & functions)
    : IProcessor({input_header_}, {output_header_})
    , input(inputs.front())
    , output(outputs.front())
A
Alexander Kuzmenkov 已提交
17 18
    , input_header(input_header_)
    , window_description(window_description_)
A
Alexander Kuzmenkov 已提交
19
{
A
Alexander Kuzmenkov 已提交
20 21
    workspaces.reserve(functions.size());
    for (const auto & f : functions)
A
Alexander Kuzmenkov 已提交
22 23
    {
        WindowFunctionWorkspace workspace;
A
cleanup  
Alexander Kuzmenkov 已提交
24
        workspace.window_function = f;
A
Alexander Kuzmenkov 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53

        const auto & aggregate_function
            = workspace.window_function.aggregate_function;
        if (!arena && aggregate_function->allocatesMemoryInArena())
        {
            arena = std::make_unique<Arena>();
        }

        workspace.argument_column_indices.reserve(
            workspace.window_function.argument_names.size());
        for (const auto & argument_name : workspace.window_function.argument_names)
        {
            workspace.argument_column_indices.push_back(
                input_header.getPositionByName(argument_name));
        }

        workspace.aggregate_function_state.reset(aggregate_function->sizeOfData(),
            aggregate_function->alignOfData());
        aggregate_function->create(workspace.aggregate_function_state.data());

        workspaces.push_back(std::move(workspace));
    }

    partition_by_indices.reserve(window_description.partition_by.size());
    for (const auto & column : window_description.partition_by)
    {
        partition_by_indices.push_back(
            input_header.getPositionByName(column.column_name));
    }
54 55 56 57 58 59 60

    order_by_indices.reserve(window_description.order_by.size());
    for (const auto & column : window_description.order_by)
    {
        order_by_indices.push_back(
            input_header.getPositionByName(column.column_name));
    }
A
Alexander Kuzmenkov 已提交
61
}
A
Alexander Kuzmenkov 已提交
62

A
Alexander Kuzmenkov 已提交
63
WindowTransform::~WindowTransform()
A
Alexander Kuzmenkov 已提交
64
{
A
Alexander Kuzmenkov 已提交
65
    // Some states may be not created yet if the creation failed.
66
    for (auto & ws : workspaces)
A
Alexander Kuzmenkov 已提交
67
    {
68 69
        ws.window_function.aggregate_function->destroy(
            ws.aggregate_function_state.data());
A
Alexander Kuzmenkov 已提交
70
    }
A
Alexander Kuzmenkov 已提交
71 72
}

73
void WindowTransform::advancePartitionEnd()
A
Alexander Kuzmenkov 已提交
74
{
75 76 77 78
    if (partition_ended)
    {
        return;
    }
A
Alexander Kuzmenkov 已提交
79

80 81 82 83 84 85 86 87 88 89
    const RowNumber end = blocksEnd();

    // If we're at the total end of data, we must end the partition. This is the
    // only place in calculations where we need special handling for end of data,
    // other places will work as usual based on `partition_ended` = true, because
    // end of data is logically the same as any other end of partition.
    // We must check this first, because other calculations might not be valid
    // when we're at the end of data.
    // FIXME not true, we also handle it elsewhere
    if (input_is_finished)
A
Alexander Kuzmenkov 已提交
90
    {
91 92 93 94 95 96 97 98 99
        partition_ended = true;
        partition_end = end;
        return;
    }

    // Try to advance the partition end pointer.
    const size_t n = partition_by_indices.size();
    if (n == 0)
    {
A
cleanup  
Alexander Kuzmenkov 已提交
100
//        fmt::print(stderr, "no partition by\n");
101 102 103 104 105 106 107 108 109
        // No PARTITION BY. All input is one partition, which will end when the
        // input ends.
        partition_end = end;
        return;
    }

    // The partition ends when the PARTITION BY columns change. We need an array
    // of reference columns for comparison. We might have already dropped the
    // blocks where the partition starts, but any row in the partition will do.
A
cleanup  
Alexander Kuzmenkov 已提交
110 111 112
    // Use group_start -- it's always in the valid region, because it points to
    // the start of the current group, which we haven't fully processed yet, and
    // hence cannot drop.
113 114 115
    auto reference_row = group_start;
    if (reference_row == partition_end)
    {
A
cleanup  
Alexander Kuzmenkov 已提交
116 117
        // This is for the very first partition and its first row. Try to get
        // rid of this logic.
118 119 120 121 122 123 124 125 126 127
        advanceRowNumber(partition_end);
    }
    assert(reference_row < blocksEnd());
    assert(reference_row.block >= first_block_number);
    Columns reference_partition_by;
    for (const auto i : partition_by_indices)
    {
        reference_partition_by.push_back(inputAt(reference_row)[i]);
    }

A
cleanup  
Alexander Kuzmenkov 已提交
128
//    fmt::print(stderr, "{} cols to compare, reference at {}\n", n, group_start);
129

A
cleanup  
Alexander Kuzmenkov 已提交
130
    for (; partition_end < end; advanceRowNumber(partition_end))
131 132 133
    {
        // Check for partition end.
        size_t i = 0;
A
cleanup  
Alexander Kuzmenkov 已提交
134
        for (; i < n; i++)
A
Alexander Kuzmenkov 已提交
135
        {
136 137 138 139 140 141 142 143
            const auto * c = inputAt(partition_end)[partition_by_indices[i]].get();
            if (c->compareAt(partition_end.row,
                    group_start.row, *reference_partition_by[i],
                    1 /* nan_direction_hint */) != 0)
            {
                break;
            }
        }
A
Alexander Kuzmenkov 已提交
144

145 146 147 148 149 150
        if (i < n)
        {
//            fmt::print(stderr, "col {} doesn't match at {}: ref {}, val {}\n",
//                i, partition_end, inputAt(partition_end)[i]);
            partition_ended = true;
            return;
A
Alexander Kuzmenkov 已提交
151
        }
152 153 154 155 156 157 158 159 160 161 162 163
    }

    // Went until the end of data and didn't find the new partition.
    assert(!partition_ended && partition_end == blocksEnd());
}

void WindowTransform::advanceGroupEnd()
{
    if (group_ended)
    {
        return;
    }
A
Alexander Kuzmenkov 已提交
164

165 166 167 168 169 170 171 172 173
    switch (window_description.frame.type)
    {
        case WindowFrame::FrameType::Groups:
            advanceGroupEndGroups();
            break;
        case WindowFrame::FrameType::Rows:
            advanceGroupEndRows();
            break;
        case WindowFrame::FrameType::Range:
A
cleanup  
Alexander Kuzmenkov 已提交
174
            assert(false);
175
            break;
176
    }
177
}
A
Alexander Kuzmenkov 已提交
178

179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
void WindowTransform::advanceGroupEndRows()
{
    // ROWS mode, peer groups always contains only the current row.
    // We cannot advance the groups if the group start is already beyond the
    // end of partition.
    assert(group_start < partition_end);
    group_end = group_start;
    advanceRowNumber(group_end);
    group_ended = true;
}

void WindowTransform::advanceGroupEndGroups()
{
    const size_t n = order_by_indices.size();
    if (n == 0)
    {
        // No ORDER BY, so all rows are the same group. The group will end
        // with the partition.
        group_end = partition_end;
        group_ended = partition_ended;
    }

    Columns reference_order_by;
    for (const auto i : order_by_indices)
    {
        reference_order_by.push_back(inputAt(group_start)[i]);
    }

    // `partition_end` is either end of partition or end of data.
A
cleanup  
Alexander Kuzmenkov 已提交
208
    for (; group_end < partition_end; advanceRowNumber(group_end))
209 210 211
    {
        // Check for group end.
        size_t i = 0;
A
cleanup  
Alexander Kuzmenkov 已提交
212
        for (; i < n; i++)
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
        {
            const auto * c = inputAt(partition_end)[partition_by_indices[i]].get();
            if (c->compareAt(group_end.row,
                    group_start.row, *reference_order_by[i],
                    1 /* nan_direction_hint */) != 0)
            {
                break;
            }
        }

        if (i < n)
        {
            group_ended = true;
            return;
        }
    }

    assert(group_end == partition_end);
    if (partition_ended)
    {
        // A corner case -- the ORDER BY columns were the same, but the group
        // still ended because the partition has ended.
        group_ended = true;
    }
}

void WindowTransform::advanceFrameStart()
{
    // Frame start is always UNBOUNDED PRECEDING for now, so we don't have to
    // move it. It is initialized when the new partition starts.
}

void WindowTransform::advanceFrameEnd()
{
    // This should be called when we know the boundaries of the group (probably
    // not a fundamental requirement, but currently it's written this way).
    assert(group_ended);

    const auto frame_end_before = frame_end;

    // Frame end is always the current group end, for now.
    // In ROWS mode the group is going to contain only the current row.
    frame_end = group_end;
    frame_ended = true;

    // Add the columns over which we advanced the frame to the aggregate function
    // states.
    std::vector<const IColumn *> argument_columns;
    for (auto & ws : workspaces)
    {
        const auto & f = ws.window_function;
        const auto * a = f.aggregate_function.get();
        auto * buf = ws.aggregate_function_state.data();

        // We use two explicit loops here instead of using advanceRowNumber(),
        // because we want to cache the argument columns array per block. Later
        // we also use batch add.
        // Unfortunately this leads to tricky loop conditions, because the
        // frame_end might be either a past-the-end block, or a valid block, in
        // which case we also have to process its head.
        // And we also have to remember to reset the row number when moving to
        // the next block.

        uint64_t past_the_end_block;
        // Note that the past-the-end row is not in the past-the-end block, but
        // in the block before it.
        uint32_t past_the_end_row;

        if (frame_end.block < first_block_number + blocks.size())
        {
            // The past-the-end row is in some valid block.
            past_the_end_block = frame_end.block + 1;
            past_the_end_row = frame_end.row;
        }
        else
288
        {
289 290 291 292
            // The past-the-end row is at the total end of data.
            past_the_end_block = first_block_number + blocks.size();
            // It's in the previous block!
            past_the_end_row = blocks.back().numRows();
293
        }
294 295 296
        for (auto r = frame_end_before;
            r.block < past_the_end_block;
            ++r.block, r.row = 0)
A
Alexander Kuzmenkov 已提交
297
        {
298 299 300 301
            const auto & block = blocks[r.block - first_block_number];

            argument_columns.clear();
            for (const auto i : ws.argument_column_indices)
A
Alexander Kuzmenkov 已提交
302
            {
303
                argument_columns.push_back(block.input_columns[i].get());
A
Alexander Kuzmenkov 已提交
304
            }
305 306 307 308 309 310

            // We process all rows of intermediate blocks, and the head of the
            // last block.
            const auto end = ((r.block + 1) == past_the_end_block)
                ? past_the_end_row
                : block.numRows();
A
cleanup  
Alexander Kuzmenkov 已提交
311
            for (; r.row < end; ++r.row)
312 313 314 315 316 317 318 319 320 321 322 323
            {
                a->add(buf,
                    argument_columns.data(),
                    r.row,
                    arena.get());
            }
        }
    }
}

void WindowTransform::writeOutGroup()
{
A
cleanup  
Alexander Kuzmenkov 已提交
324 325
//    fmt::print(stderr, "write out group [{}..{})\n",
//        group_start, group_end);
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346

    // Empty groups don't make sense.
    assert(group_start < group_end);

    std::vector<const IColumn *> argument_columns;
    for (size_t wi = 0; wi < workspaces.size(); ++wi)
    {
        auto & ws = workspaces[wi];
        const auto & f = ws.window_function;
        const auto * a = f.aggregate_function.get();
        auto * buf = ws.aggregate_function_state.data();

        // Need to use a tricky loop to be able to batch per-block (but we don't
        // do it yet...). See the comments to the similar loop in
        // advanceFrameEnd() above.
        uint64_t past_the_end_block;
        uint32_t past_the_end_row;
        if (frame_end.block < first_block_number + blocks.size())
        {
            past_the_end_block = frame_end.block + 1;
            past_the_end_row = frame_end.row;
347 348 349
        }
        else
        {
350 351 352 353 354 355 356 357 358 359 360
            past_the_end_block = first_block_number + blocks.size();
            past_the_end_row = blocks.back().numRows();
        }
        for ( auto r = group_start;
            r.block < past_the_end_block;
            ++r.block, r.row = 0)
        {
            const auto & block = blocks[r.block - first_block_number];

            argument_columns.clear();
            for (const auto ai : ws.argument_column_indices)
A
Alexander Kuzmenkov 已提交
361
            {
362 363
                argument_columns.push_back(block.input_columns[ai].get());
            }
364

365 366 367 368 369
            // We process all rows of intermediate blocks, and the head of the
            // last block.
            const auto end = ((r.block + 1) == past_the_end_block)
                ? past_the_end_row
                : block.numRows();
A
cleanup  
Alexander Kuzmenkov 已提交
370
            for (; r.row < end; ++r.row)
371 372 373 374 375 376
            {
                // FIXME does it also allocate the result on the arena?
                // We'll have to pass it out with blocks then...
                a->insertResultInto(buf,
                    *block.output_columns[wi],
                    arena.get());
377
            }
378 379 380 381 382
        }
    }

    first_not_ready_row = group_end;
}
383

384 385
void WindowTransform::appendChunk(Chunk & chunk)
{
A
cleanup  
Alexander Kuzmenkov 已提交
386 387
//    fmt::print(stderr, "new chunk, {} rows, finished={}\n", chunk.getNumRows(),
//        input_is_finished);
388 389 390 391 392 393 394 395 396 397 398 399 400 401

    // First, prepare the new input block and add it to the queue. We might not
    // have it if it's end of data, though.
    if (!input_is_finished)
    {
        blocks.push_back({});
        auto & block = blocks.back();
        block.input_columns = chunk.detachColumns();

        for (auto & ws : workspaces)
        {
            // Aggregate functions can't work with constant columns, so we have to
            // materialize them like the Aggregator does.
            for (const auto column_index : ws.argument_column_indices)
402
            {
403 404 405
                block.input_columns[column_index]
                    = std::move(block.input_columns[column_index])
                        ->convertToFullColumnIfConst();
A
Alexander Kuzmenkov 已提交
406
            }
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425

            block.output_columns.push_back(ws.window_function.aggregate_function
                ->getReturnType()->createColumn());
        }
    }

    // Start the calculations. First, advance the partition end.
    for (;;)
    {
        advancePartitionEnd();

        // Either we ran out of data or we found the end of partition (maybe
        // both, but this only happens at the total end of data).
        assert(partition_ended || partition_end == blocksEnd());
        if (partition_ended && partition_end == blocksEnd())
        {
            assert(input_is_finished);
        }

A
cleanup  
Alexander Kuzmenkov 已提交
426 427
//        fmt::print(stderr, "partition end '{}', {}\n", partition_end,
//            partition_ended);
428 429 430 431 432 433 434 435 436

        // After that, advance the peer groups. We can advance peer groups until
        // the end of partition or current end of data, which is precisely the
        // description of `partition_end`.
        while (group_end < partition_end)
        {
            group_start = group_end;
            advanceGroupEnd();

A
cleanup  
Alexander Kuzmenkov 已提交
437
//            fmt::print(stderr, "group end '{}'\n", group_end);
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487

            // If the group didn't end yet, wait.
            if (!group_ended)
            {
                return;
            }

            // The group ended.
            // Advance the frame start, updating the state of the aggregate
            // functions.
            advanceFrameStart();
            // Advance the frame end, updating the state of the aggregate
            // functions.
            advanceFrameEnd();

            if (!frame_ended)
            {
                return;
            }

            // Write out the aggregation results
            writeOutGroup();

            // Move to the next group.
            // The frame will have to be recalculated.
            frame_ended = false;

            // Move to the next group. Don't advance group_start yet, it's
            // convenient to use it as the PARTITION BY etalon.
            group_ended = false;

            if (group_end == partition_end)
            {
                break;
            }
            assert(group_end < partition_end);
        }

        if (!partition_ended)
        {
            // We haven't encountered the end of the partition yet, need more
            // data.
            assert(partition_end == blocksEnd());
            break;
        }

        if (input_is_finished)
        {
            // why?
            return;
488
        }
A
Alexander Kuzmenkov 已提交
489

490 491 492 493 494 495 496 497 498 499 500 501 502 503
        // Start the next partition.
        const auto new_partition_start = partition_end;
        advanceRowNumber(partition_end);
        partition_ended = false;
        // We have to reset the frame when the new partition starts. This is not a
        // generally correct way to do so, but we don't really support moving frame
        // for now.
        frame_start = new_partition_start;
        frame_end = new_partition_start;
        group_start = new_partition_start;
        group_end = new_partition_start;
        // The group pointers are already reset to the partition start, see the
        // above loop.

A
cleanup  
Alexander Kuzmenkov 已提交
504 505
//        fmt::print(stderr, "reinitialize agg data at start of {}\n",
//            new_partition_start);
506 507
        // Reinitialize the aggregate function states because the new partition
        // has started.
508 509 510 511 512 513
        for (auto & ws : workspaces)
        {
            const auto & f = ws.window_function;
            const auto * a = f.aggregate_function.get();
            auto * buf = ws.aggregate_function_state.data();

514 515
            a->destroy(buf);
        }
A
Alexander Kuzmenkov 已提交
516

517 518 519 520 521 522
        // Release the arena we use for aggregate function states, so that it
        // doesn't grow without limit. Not sure if it's actually correct, maybe
        // it allocates the return values in the Arena as well...
        if (arena)
        {
            arena = std::make_unique<Arena>();
A
Alexander Kuzmenkov 已提交
523 524
        }

525 526 527 528 529
        for (auto & ws : workspaces)
        {
            const auto & f = ws.window_function;
            const auto * a = f.aggregate_function.get();
            auto * buf = ws.aggregate_function_state.data();
A
Alexander Kuzmenkov 已提交
530

531 532 533
            a->create(buf);
        }
    }
A
Alexander Kuzmenkov 已提交
534 535
}

A
Alexander Kuzmenkov 已提交
536 537
IProcessor::Status WindowTransform::prepare()
{
A
cleanup  
Alexander Kuzmenkov 已提交
538 539 540
//    fmt::print(stderr, "prepare, next output {}, not ready row {}, first block {}, hold {} blocks\n",
//        next_output_block_number, first_not_ready_row, first_block_number,
//        blocks.size());
541

A
Alexander Kuzmenkov 已提交
542 543
    if (output.isFinished())
    {
544 545
        // The consumer asked us not to continue (or we decided it ourselves),
        // so we abort.
A
Alexander Kuzmenkov 已提交
546 547 548 549
        input.close();
        return Status::Finished;
    }

550 551 552 553
//    // Technically the past-the-end next_output_block_number is also valid if
//    // we haven't yet received the corresponding input block.
//    assert(next_output_block_number < first_block_number + blocks.size()
//        || blocks.empty());
A
Alexander Kuzmenkov 已提交
554

555 556 557 558 559 560 561 562 563
    assert(first_not_ready_row.block >= first_block_number);
    // Might be past-the-end, so equality also valid.
    assert(first_not_ready_row.block <= first_block_number + blocks.size());
    assert(next_output_block_number >= first_block_number);

    // Output the ready data prepared by work().
    // We inspect the calculation state and create the output chunk right here,
    // because this is pretty lightweight.
    if (next_output_block_number < first_not_ready_row.block)
A
Alexander Kuzmenkov 已提交
564
    {
565 566 567
        if (output.canPush())
        {
            // Output the ready block.
A
cleanup  
Alexander Kuzmenkov 已提交
568
//            fmt::print(stderr, "output block {}\n", next_output_block_number);
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586
            const auto i = next_output_block_number - first_block_number;
            ++next_output_block_number;
            auto & block = blocks[i];
            auto columns = block.input_columns;
            for (auto & res : block.output_columns)
            {
                columns.push_back(ColumnPtr(std::move(res)));
            }
            output_data.chunk.setColumns(columns, block.numRows());

            output.pushData(std::move(output_data));
        }
        else
        {
            // Not sure what this branch means. The output port is full and we
            // apply backoff pressure on the input?
            input.setNotNeeded();
        }
A
Alexander Kuzmenkov 已提交
587 588 589 590

        return Status::PortFull;
    }

591
    if (input_is_finished)
A
Alexander Kuzmenkov 已提交
592
    {
593 594 595 596 597
        // The input data ended at the previous prepare() + work() cycle,
        // and we don't have ready output data (checked above). We must be
        // finished.
        assert(next_output_block_number == first_block_number + blocks.size());
        assert(first_not_ready_row == blocksEnd());
A
Alexander Kuzmenkov 已提交
598

599 600
        // FIXME do we really have to do this?
        output.finish();
A
Alexander Kuzmenkov 已提交
601

602 603
        return Status::Finished;
    }
A
Alexander Kuzmenkov 已提交
604

605 606 607
    // Consume input data if we have any ready.
    if (!has_input && input.hasData())
    {
A
Alexander Kuzmenkov 已提交
608 609 610
        input_data = input.pullData(true /* set_not_needed */);
        has_input = true;

611 612 613 614 615 616 617 618 619 620 621 622 623 624
        // Now we have new input and can try to generate more output in work().
        return Status::Ready;
    }

    // We 1) don't have any ready output (checked above),
    // 2) don't have any more input (also checked above).
    // Will we get any more input?
    if (input.isFinished())
    {
        // We won't, time to finalize the calculation in work(). We should only
        // do this once.
        assert(!input_is_finished);
        input_is_finished = true;
        return Status::Ready;
A
Alexander Kuzmenkov 已提交
625 626
    }

627 628 629
    // We have to wait for more input.
    input.setNeeded();
    return Status::NeedData;
A
Alexander Kuzmenkov 已提交
630 631 632 633 634 635 636 637 638 639 640 641 642
}

void WindowTransform::work()
{
    if (input_data.exception)
    {
        /// Skip transform in case of exception.
        output_data = std::move(input_data);
        has_input = false;
        has_output = true;
        return;
    }

643 644
    assert(has_input || input_is_finished);

A
Alexander Kuzmenkov 已提交
645 646
    try
    {
647 648
        has_input = false;
        appendChunk(input_data.chunk);
A
Alexander Kuzmenkov 已提交
649 650 651 652 653 654 655 656 657
    }
    catch (DB::Exception &)
    {
        output_data.exception = std::current_exception();
        has_output = true;
        has_input = false;
        return;
    }

658 659 660 661 662 663
    // We don't really have to keep the entire partition, and it can be big, so
    // we want to drop the starting blocks to save memory.
    // We can drop the old blocks if we already returned them as output, and the
    // frame and group are already past them. Note that the frame start can be
    // further than group start for some frame specs, so we have to check both.
    const auto first_used_block = std::min(next_output_block_number,
A
cleanup  
Alexander Kuzmenkov 已提交
664
            std::min(frame_start.block, group_start.block));
665 666
    if (first_block_number < first_used_block)
    {
A
cleanup  
Alexander Kuzmenkov 已提交
667 668
//        fmt::print(stderr, "will drop blocks from {} to {}\n", first_block_number,
//            first_used_block);
669 670 671 672

        blocks.erase(blocks.begin(),
            blocks.begin() + first_used_block - first_block_number);
        first_block_number = first_used_block;
A
Alexander Kuzmenkov 已提交
673

674 675 676 677
        assert(next_output_block_number >= first_block_number);
        assert(frame_start.block >= first_block_number);
        assert(group_start.block >= first_block_number);
    }
A
Alexander Kuzmenkov 已提交
678 679 680
}


A
Alexander Kuzmenkov 已提交
681
}