ClickHouse/src/DataStreams/MergingSortedBlockInputStream.h

92 lines
2.6 KiB
C++
Raw Normal View History

2012-07-25 19:53:43 +00:00
#pragma once
#include <Core/Row.h>
#include <Core/SortDescription.h>
#include <Core/SortCursor.h>
2012-07-25 19:53:43 +00:00
2018-06-05 19:46:49 +00:00
#include <IO/WriteHelpers.h>
#include <DataStreams/IBlockInputStream.h>
2012-07-25 19:53:43 +00:00
2020-03-20 03:32:47 +00:00
namespace Poco { class Logger; }
2012-07-25 19:53:43 +00:00
namespace DB
{
/** Merges several sorted streams into one sorted stream.
2012-07-25 19:53:43 +00:00
*/
class MergingSortedBlockInputStream : public IBlockInputStream
2012-07-25 19:53:43 +00:00
{
public:
/** limit - if isn't 0, then we can produce only first limit rows in sorted order.
* out_row_sources - if isn't nullptr, then at the end of execution it should contain part numbers of each readed row (and needed flag)
* quiet - don't log profiling info
*/
MergingSortedBlockInputStream(
const BlockInputStreams & inputs_, SortDescription description_, size_t max_block_size_,
UInt64 limit_ = 0, WriteBuffer * out_row_sources_buf_ = nullptr, bool quiet_ = false);
2012-07-25 19:53:43 +00:00
String getName() const override { return "MergingSorted"; }
2012-07-25 19:53:43 +00:00
bool isSortedOutput() const override { return true; }
const SortDescription & getSortDescription() const override { return description; }
Block getHeader() const override { return header; }
2012-08-14 20:33:37 +00:00
protected:
Block readImpl() override;
void readSuffixImpl() override;
/// Initializes the queue and the columns of next result block.
void init(MutableColumns & merged_columns);
2017-05-13 22:19:04 +00:00
/// Gets the next block from the source corresponding to the `current`.
template <typename TSortCursor>
2019-12-22 00:19:07 +00:00
void fetchNextBlock(const TSortCursor & current, SortingHeap<TSortCursor> & queue);
Block header;
const SortDescription description;
const size_t max_block_size;
2019-02-10 15:17:45 +00:00
UInt64 limit;
UInt64 total_merged_rows = 0;
bool first = true;
bool has_collation = false;
bool quiet = false;
/// May be smaller or equal to max_block_size. To do 'reserve' for columns.
size_t expected_block_size = 0;
2017-05-13 22:19:04 +00:00
/// Blocks currently being merged.
size_t num_columns = 0;
Blocks source_blocks;
SortCursorImpls cursors;
2019-12-22 00:19:07 +00:00
SortingHeap<SortCursor> queue_without_collation;
SortingHeap<SortCursorWithCollation> queue_with_collation;
Data Skipping Indices (#4143) * made index parser * added index parsing * some fixes * added index interface and factory * fixed compilation * ptrs * added indexParts * indextypes * index condition * IndexCondition * added indexes in selectexecutor * fix * changed comment * fix * added granularity * comments * fix * fix * added writing indexes * removed indexpart class * fix * added setSkipIndexes * add rw for MergeTreeIndexes * fixes * upd error * fix * fix * reading * test index * fixed nullptr error * fixed * fix * unique names * asts -> exprlist * minmax index * fix * fixed select * fixed merging * fixed mutation * working minmax * removed test index * fixed style * added indexes to checkDataPart * added tests for minmax index * fixed constructor * fix style * fixed includes * fixed setSkipIndexes * added indexes meta to zookeeper * added parsing * removed throw * alter cmds parse * fix * added alter * fix * alters fix * fix alters * fix "after" * fixed alter * alter fix + test * fixes * upd setSkipIndexes * fixed alter bug with drop all indices * fix metadata editing * new test and repl fix * rm test files * fixed repl alter * fix * fix * indices * MTReadStream * upd test for bug * fix * added useful parsers and ast classes * fix * fix comments * replaced columns * fix * fixed parsing * fixed printing * fix err * basic IndicesDescription * go to IndicesDescr * moved indices * go to indicesDescr * fix test minmax_index* * fixed MT alter * fixed bug with replMT indices storing in zk * rename * refactoring * docs ru * docs ru * docs en * refactor * rename tests * fix docs * refactoring * fix * fix * fix * fixed style * unique idx * unique * fix * better minmax calculation * upd * added getBlock * unique_condition * added termForAST * unique * fixed not * uniqueCondition::mayBeTrueOnGranule * fix * fixed bug with double column * is always true * fix * key set * spaces * test * tests * fix * unique * fix * fix * fixed bug with duplicate column * removed unused data * fix * fixes * __bitSwapLastTwo * fix
2019-02-05 14:50:25 +00:00
/// 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;
2012-08-14 20:33:37 +00:00
private:
2017-05-13 22:19:04 +00:00
/** We support two different cursors - with Collation and without.
2019-12-22 00:19:07 +00:00
* Templates are used instead of polymorphic SortCursor and calls to virtual functions.
*/
template <typename TSortingHeap>
void merge(MutableColumns & merged_columns, TSortingHeap & queue);
2020-03-20 03:32:47 +00:00
Poco::Logger * log;
2015-01-18 08:25:56 +00:00
2017-05-13 22:19:04 +00:00
/// Read is finished.
bool finished = false;
2012-07-25 19:53:43 +00:00
};
}