2017-04-06 17:21:45 +00:00
|
|
|
#pragma once
|
2017-12-01 13:32:37 +00:00
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2017-04-10 14:06:44 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeBlockReadUtils.h>
|
2017-04-06 17:21:45 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
2018-04-11 14:31:54 +00:00
|
|
|
#include <Storages/SelectQueryInfo.h>
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2019-10-04 15:40:05 +00:00
|
|
|
#include <Processors/Sources/SourceWithProgress.h>
|
2019-09-13 15:41:09 +00:00
|
|
|
|
2017-04-06 17:21:45 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2019-10-10 16:30:30 +00:00
|
|
|
class IMergeTreeReader;
|
2017-04-06 17:21:45 +00:00
|
|
|
class UncompressedCache;
|
|
|
|
class MarkCache;
|
|
|
|
|
|
|
|
|
2019-10-10 14:16:15 +00:00
|
|
|
/// Base class for MergeTreeThreadSelectProcessor and MergeTreeSelectProcessor
|
2019-10-04 15:40:05 +00:00
|
|
|
class MergeTreeBaseSelectProcessor : public SourceWithProgress
|
2017-04-06 17:21:45 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-10-01 16:50:08 +00:00
|
|
|
MergeTreeBaseSelectProcessor(
|
2019-09-13 15:41:09 +00:00
|
|
|
Block header,
|
2019-08-03 11:02:40 +00:00
|
|
|
const MergeTreeData & storage_,
|
2020-06-16 14:25:08 +00:00
|
|
|
const StorageMetadataPtr & metadata_snapshot_,
|
2019-08-03 11:02:40 +00:00
|
|
|
const PrewhereInfoPtr & prewhere_info_,
|
|
|
|
UInt64 max_block_size_rows_,
|
|
|
|
UInt64 preferred_block_size_bytes_,
|
|
|
|
UInt64 preferred_max_column_in_block_size_bytes_,
|
2019-12-18 15:54:45 +00:00
|
|
|
const MergeTreeReaderSettings & reader_settings_,
|
2019-08-03 11:02:40 +00:00
|
|
|
bool use_uncompressed_cache_,
|
|
|
|
const Names & virt_column_names_ = {});
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2019-10-01 16:50:08 +00:00
|
|
|
~MergeTreeBaseSelectProcessor() override;
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2021-04-27 08:15:59 +00:00
|
|
|
static Block transformHeader(
|
|
|
|
Block block, const PrewhereInfoPtr & prewhere_info, const DataTypePtr & partition_value_type, const Names & virtual_columns);
|
2021-03-30 10:25:26 +00:00
|
|
|
|
2018-04-16 12:21:36 +00:00
|
|
|
static void executePrewhereActions(Block & block, const PrewhereInfoPtr & prewhere_info);
|
|
|
|
|
2017-04-06 17:21:45 +00:00
|
|
|
protected:
|
2019-09-13 15:41:09 +00:00
|
|
|
Chunk generate() final;
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2019-10-04 15:40:05 +00:00
|
|
|
/// Creates new this->task, and initializes readers.
|
2017-04-06 17:21:45 +00:00
|
|
|
virtual bool getNewTask() = 0;
|
|
|
|
|
2019-09-13 15:41:09 +00:00
|
|
|
virtual Chunk readFromPart();
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2019-09-13 15:41:09 +00:00
|
|
|
Chunk readFromPartImpl();
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2019-10-10 14:16:15 +00:00
|
|
|
/// Two versions for header and chunk.
|
2021-04-27 08:15:59 +00:00
|
|
|
static void
|
|
|
|
injectVirtualColumns(Block & block, MergeTreeReadTask * task, const DataTypePtr & partition_value_type, const Names & virtual_columns);
|
|
|
|
static void
|
|
|
|
injectVirtualColumns(Chunk & chunk, MergeTreeReadTask * task, const DataTypePtr & partition_value_type, const Names & virtual_columns);
|
2019-07-19 14:56:00 +00:00
|
|
|
|
2019-07-18 14:41:11 +00:00
|
|
|
void initializeRangeReaders(MergeTreeReadTask & task);
|
|
|
|
|
2017-04-06 17:21:45 +00:00
|
|
|
protected:
|
2018-10-17 03:13:00 +00:00
|
|
|
const MergeTreeData & storage;
|
2020-06-16 14:25:08 +00:00
|
|
|
StorageMetadataPtr metadata_snapshot;
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2018-04-11 14:31:54 +00:00
|
|
|
PrewhereInfoPtr prewhere_info;
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2018-06-06 17:16:05 +00:00
|
|
|
UInt64 max_block_size_rows;
|
|
|
|
UInt64 preferred_block_size_bytes;
|
|
|
|
UInt64 preferred_max_column_in_block_size_bytes;
|
2017-04-06 17:21:45 +00:00
|
|
|
|
2019-12-18 15:54:45 +00:00
|
|
|
MergeTreeReaderSettings reader_settings;
|
2017-04-06 17:21:45 +00:00
|
|
|
|
|
|
|
bool use_uncompressed_cache;
|
|
|
|
|
|
|
|
Names virt_column_names;
|
2021-04-27 08:15:59 +00:00
|
|
|
|
|
|
|
DataTypePtr partition_value_type;
|
|
|
|
|
2019-10-10 14:16:15 +00:00
|
|
|
/// This header is used for chunks from readFromPart().
|
2019-10-02 11:57:17 +00:00
|
|
|
Block header_without_virtual_columns;
|
2017-04-06 17:21:45 +00:00
|
|
|
|
|
|
|
std::unique_ptr<MergeTreeReadTask> task;
|
|
|
|
|
|
|
|
std::shared_ptr<UncompressedCache> owned_uncompressed_cache;
|
|
|
|
std::shared_ptr<MarkCache> owned_mark_cache;
|
|
|
|
|
2019-10-10 16:30:30 +00:00
|
|
|
using MergeTreeReaderPtr = std::unique_ptr<IMergeTreeReader>;
|
2017-04-06 17:21:45 +00:00
|
|
|
MergeTreeReaderPtr reader;
|
|
|
|
MergeTreeReaderPtr pre_reader;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|