2014-03-13 12:48:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeData.h>
|
|
|
|
#include <Storages/MergeTree/RangesInDataPart.h>
|
2015-04-12 04:39:20 +00:00
|
|
|
|
2014-03-13 12:48:07 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-01-14 09:00:19 +00:00
|
|
|
class PKCondition;
|
|
|
|
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** Executes SELECT queries on data from the merge tree.
|
2014-03-13 12:48:07 +00:00
|
|
|
*/
|
|
|
|
class MergeTreeDataSelectExecutor
|
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeDataSelectExecutor(MergeTreeData & data_);
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/** When reading, selects a set of parts that covers the desired range of the index.
|
|
|
|
* max_block_number_to_read - if not zero, do not read all the parts whose right border is greater than this threshold.
|
2017-04-01 07:20:54 +00:00
|
|
|
*/
|
|
|
|
BlockInputStreams read(
|
|
|
|
const Names & column_names,
|
2017-05-25 01:12:41 +00:00
|
|
|
const ASTPtr & query,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context,
|
|
|
|
QueryProcessingStage::Enum & processed_stage,
|
|
|
|
size_t max_block_size,
|
|
|
|
unsigned threads,
|
2017-05-09 19:07:35 +00:00
|
|
|
size_t * inout_part_index, /// If not nullptr, from this counter values are taken for the virtual column _part_index.
|
2017-04-01 07:20:54 +00:00
|
|
|
Int64 max_block_number_to_read) const;
|
2014-03-13 12:48:07 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
MergeTreeData & data;
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Logger * log;
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreams spreadMarkRangesAmongThreads(
|
|
|
|
RangesInDataParts parts,
|
|
|
|
size_t threads,
|
|
|
|
const Names & column_names,
|
|
|
|
size_t max_block_size,
|
|
|
|
bool use_uncompressed_cache,
|
|
|
|
ExpressionActionsPtr prewhere_actions,
|
|
|
|
const String & prewhere_column,
|
|
|
|
const Names & virt_columns,
|
|
|
|
const Settings & settings) const;
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreams spreadMarkRangesAmongThreadsFinal(
|
|
|
|
RangesInDataParts parts,
|
|
|
|
size_t threads,
|
|
|
|
const Names & column_names,
|
|
|
|
size_t max_block_size,
|
|
|
|
bool use_uncompressed_cache,
|
|
|
|
ExpressionActionsPtr prewhere_actions,
|
|
|
|
const String & prewhere_column,
|
|
|
|
const Names & virt_columns,
|
|
|
|
const Settings & settings,
|
|
|
|
const Context & context) const;
|
2015-11-18 21:37:28 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Get the approximate value (bottom estimate - only by full marks) of the number of rows falling under the index.
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t getApproximateTotalRowsToRead(
|
|
|
|
const MergeTreeData::DataPartsVector & parts,
|
|
|
|
const PKCondition & key_condition,
|
|
|
|
const Settings & settings) const;
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-04-16 15:00:33 +00:00
|
|
|
/// Create the expression "Sign == 1".
|
2017-04-01 07:20:54 +00:00
|
|
|
void createPositiveSignCondition(
|
|
|
|
ExpressionActionsPtr & out_expression,
|
|
|
|
String & out_column,
|
|
|
|
const Context & context) const;
|
2014-03-13 12:48:07 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
MarkRanges markRangesFromPKRange(
|
|
|
|
const MergeTreeData::DataPart::Index & index,
|
|
|
|
const PKCondition & key_condition,
|
|
|
|
const Settings & settings) const;
|
2014-03-13 12:48:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|