IMergingAlgorithmWithDelayedChunk.h 1.1 KB
Newer Older
1 2
#pragma once

3 4
#include <Processors/Merges/Algorithms/IMergingAlgorithm.h>
#include <Processors/Merges/Algorithms/RowRef.h>
5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <Core/SortDescription.h>

namespace DB
{

class IMergingAlgorithmWithDelayedChunk : public IMergingAlgorithm
{
public:
    IMergingAlgorithmWithDelayedChunk(
        size_t num_inputs,
        SortDescription description_);

protected:
    SortingHeap<SortCursor> queue;
N
Nikolai Kochetov 已提交
19
    SortDescription description;
20 21 22 23 24 25 26

    /// Previous row. May refer to last_chunk_sort_columns or row from source_chunks.
    detail::RowRef last_key;

    ColumnRawPtrs last_chunk_sort_columns; /// Point to last_chunk if valid.

    void initializeQueue(Chunks chunks);
N
Nikolai Kochetov 已提交
27
    void updateCursor(Chunk & chunk, size_t source_num);
28 29 30 31 32 33 34 35 36 37 38 39 40

private:
    /// Chunks currently being merged.
    std::vector<Chunk> source_chunks;
    SortCursorImpls cursors;

    /// In merging algorithm, we need to compare current sort key with the last one.
    /// So, sorting columns for last row needed to be stored.
    /// In order to do it, we extend lifetime of last chunk and it's sort columns (from corresponding sort cursor).
    Chunk last_chunk;
};

}