IMergingAlgorithmWithSharedChunks.h 1.2 KB
Newer Older
1
#pragma once
2 3
#include <Processors/Merges/Algorithms/IMergingAlgorithm.h>
#include <Processors/Merges/Algorithms/RowRef.h>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <Core/SortDescription.h>

namespace DB
{

class IMergingAlgorithmWithSharedChunks : public IMergingAlgorithm
{
public:
    IMergingAlgorithmWithSharedChunks(
        size_t num_inputs,
        SortDescription description_,
        WriteBuffer * out_row_sources_buf_,
        size_t max_row_refs);

    void initialize(Chunks chunks) override;
N
Nikolai Kochetov 已提交
19
    void consume(Chunk & chunk, size_t source_num) override;
20 21 22 23 24 25 26

private:
    SortDescription description;

    /// Allocator must be destroyed after source_chunks.
    detail::SharedChunkAllocator chunk_allocator;

27 28 29
    SortCursorImpls cursors;

protected:
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
    /// Chunks currently being merged.
    using SourceChunks = std::vector<detail::SharedChunkPtr>;
    SourceChunks source_chunks;

    SortingHeap<SortCursor> queue;

    /// Used in Vertical merge algorithm to gather non-PK/non-index columns (on next step)
    /// If it is not nullptr then it should be populated during execution
    WriteBuffer * out_row_sources_buf = nullptr;

    using RowRef = detail::RowRefWithOwnedChunk;
    void setRowRef(RowRef & row, SortCursor & cursor) { row.set(cursor, source_chunks[cursor.impl->order]); }
};

}