2017-07-15 04:06:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-18 16:30:35 +00:00
|
|
|
#include <Interpreters/PreparedSets.h>
|
2020-06-15 12:36:10 +00:00
|
|
|
#include <Interpreters/DatabaseAndTableWithAlias.h>
|
2019-07-18 14:41:11 +00:00
|
|
|
#include <Core/SortDescription.h>
|
2020-02-14 07:12:04 +00:00
|
|
|
#include <Core/Names.h>
|
2021-02-10 14:12:49 +00:00
|
|
|
#include <Storages/ProjectionsDescription.h>
|
|
|
|
#include <Storages/MergeTree/ProjectionKeyActions.h>
|
2021-04-21 16:00:27 +00:00
|
|
|
#include <Interpreters/AggregateDescription.h>
|
2021-02-10 14:12:49 +00:00
|
|
|
|
2017-07-15 04:06:51 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2018-04-06 13:58:06 +00:00
|
|
|
class ExpressionActions;
|
|
|
|
using ExpressionActionsPtr = std::shared_ptr<ExpressionActions>;
|
|
|
|
|
2020-11-03 11:28:28 +00:00
|
|
|
class ActionsDAG;
|
|
|
|
using ActionsDAGPtr = std::shared_ptr<ActionsDAG>;
|
|
|
|
|
2021-02-13 22:07:13 +00:00
|
|
|
struct PrewhereInfo;
|
|
|
|
using PrewhereInfoPtr = std::shared_ptr<PrewhereInfo>;
|
|
|
|
|
|
|
|
struct PrewhereDAGInfo;
|
|
|
|
using PrewhereDAGInfoPtr = std::shared_ptr<PrewhereDAGInfo>;
|
|
|
|
|
|
|
|
struct FilterInfo;
|
|
|
|
using FilterInfoPtr = std::shared_ptr<FilterInfo>;
|
|
|
|
|
|
|
|
struct FilterDAGInfo;
|
|
|
|
using FilterDAGInfoPtr = std::shared_ptr<FilterDAGInfo>;
|
|
|
|
|
|
|
|
struct InputOrderInfo;
|
|
|
|
using InputOrderInfoPtr = std::shared_ptr<const InputOrderInfo>;
|
|
|
|
|
|
|
|
struct TreeRewriterResult;
|
|
|
|
using TreeRewriterResultPtr = std::shared_ptr<const TreeRewriterResult>;
|
|
|
|
|
|
|
|
class ReadInOrderOptimizer;
|
|
|
|
using ReadInOrderOptimizerPtr = std::shared_ptr<const ReadInOrderOptimizer>;
|
|
|
|
|
|
|
|
class Cluster;
|
|
|
|
using ClusterPtr = std::shared_ptr<Cluster>;
|
|
|
|
|
2018-04-11 14:31:54 +00:00
|
|
|
struct PrewhereInfo
|
|
|
|
{
|
2018-09-07 15:13:08 +00:00
|
|
|
/// Actions which are executed in order to alias columns are used for prewhere actions.
|
2020-11-03 19:05:47 +00:00
|
|
|
ExpressionActionsPtr alias_actions;
|
2021-02-15 19:48:06 +00:00
|
|
|
/// Actions for row level security filter. Applied separately before prewhere_actions.
|
|
|
|
/// This actions are separate because prewhere condition should not be executed over filtered rows.
|
|
|
|
ExpressionActionsPtr row_level_filter;
|
2018-04-11 14:31:54 +00:00
|
|
|
/// Actions which are executed on block in order to get filter column for prewhere step.
|
2020-11-03 19:05:47 +00:00
|
|
|
ExpressionActionsPtr prewhere_actions;
|
2018-10-04 08:58:19 +00:00
|
|
|
/// Actions which are executed after reading from storage in order to remove unused columns.
|
2020-11-03 19:05:47 +00:00
|
|
|
ExpressionActionsPtr remove_columns_actions;
|
2021-02-15 19:48:06 +00:00
|
|
|
String row_level_column_name;
|
2018-04-11 14:31:54 +00:00
|
|
|
String prewhere_column_name;
|
|
|
|
bool remove_prewhere_column = false;
|
2019-11-15 03:38:35 +00:00
|
|
|
bool need_filter = false;
|
2018-04-11 14:31:54 +00:00
|
|
|
};
|
|
|
|
|
2021-02-13 22:07:13 +00:00
|
|
|
/// Same as PrewhereInfo, but with ActionsDAG.
|
2020-11-03 19:05:47 +00:00
|
|
|
struct PrewhereDAGInfo
|
|
|
|
{
|
|
|
|
ActionsDAGPtr alias_actions;
|
2021-02-15 19:48:06 +00:00
|
|
|
ActionsDAGPtr row_level_filter_actions;
|
2020-11-03 19:05:47 +00:00
|
|
|
ActionsDAGPtr prewhere_actions;
|
|
|
|
ActionsDAGPtr remove_columns_actions;
|
2021-02-15 19:48:06 +00:00
|
|
|
String row_level_column_name;
|
2020-11-03 19:05:47 +00:00
|
|
|
String prewhere_column_name;
|
|
|
|
bool remove_prewhere_column = false;
|
|
|
|
bool need_filter = false;
|
|
|
|
|
|
|
|
PrewhereDAGInfo() = default;
|
|
|
|
explicit PrewhereDAGInfo(ActionsDAGPtr prewhere_actions_, String prewhere_column_name_)
|
|
|
|
: prewhere_actions(std::move(prewhere_actions_)), prewhere_column_name(std::move(prewhere_column_name_)) {}
|
2020-12-02 18:16:31 +00:00
|
|
|
|
|
|
|
std::string dump() const;
|
2020-11-03 19:05:47 +00:00
|
|
|
};
|
|
|
|
|
2019-03-29 20:31:06 +00:00
|
|
|
/// Helper struct to store all the information about the filter expression.
|
|
|
|
struct FilterInfo
|
|
|
|
{
|
2021-02-14 17:16:40 +00:00
|
|
|
ExpressionActionsPtr alias_actions;
|
2021-02-13 22:07:13 +00:00
|
|
|
ExpressionActionsPtr actions;
|
|
|
|
String column_name;
|
|
|
|
bool do_remove_column = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Same as FilterInfo, but with ActionsDAG.
|
|
|
|
struct FilterDAGInfo
|
|
|
|
{
|
|
|
|
ActionsDAGPtr actions;
|
2019-03-29 20:31:06 +00:00
|
|
|
String column_name;
|
|
|
|
bool do_remove_column = false;
|
2020-12-02 18:16:31 +00:00
|
|
|
|
|
|
|
std::string dump() const;
|
2019-03-29 20:31:06 +00:00
|
|
|
};
|
|
|
|
|
2020-05-13 13:49:10 +00:00
|
|
|
struct InputOrderInfo
|
2019-07-18 14:41:11 +00:00
|
|
|
{
|
2019-11-15 14:03:42 +00:00
|
|
|
SortDescription order_key_prefix_descr;
|
2019-07-25 10:45:01 +00:00
|
|
|
int direction;
|
2019-07-19 10:14:27 +00:00
|
|
|
|
2020-05-13 13:49:10 +00:00
|
|
|
InputOrderInfo(const SortDescription & order_key_prefix_descr_, int direction_)
|
2019-11-15 14:03:42 +00:00
|
|
|
: order_key_prefix_descr(order_key_prefix_descr_), direction(direction_) {}
|
2019-12-10 23:18:24 +00:00
|
|
|
|
2020-05-13 13:49:10 +00:00
|
|
|
bool operator ==(const InputOrderInfo & other) const
|
2019-12-10 23:18:24 +00:00
|
|
|
{
|
|
|
|
return order_key_prefix_descr == other.order_key_prefix_descr && direction == other.direction;
|
|
|
|
}
|
2019-12-11 01:34:39 +00:00
|
|
|
|
2020-05-13 13:49:10 +00:00
|
|
|
bool operator !=(const InputOrderInfo & other) const { return !(*this == other); }
|
2019-07-18 14:41:11 +00:00
|
|
|
};
|
|
|
|
|
2021-04-22 13:32:17 +00:00
|
|
|
class IMergeTreeDataPart;
|
|
|
|
|
2021-04-29 07:38:47 +00:00
|
|
|
// The projection selected to execute current query
|
|
|
|
struct ProjectionCandidate
|
|
|
|
{
|
|
|
|
const ProjectionDescription * desc;
|
|
|
|
PrewhereInfoPtr prewhere_info;
|
|
|
|
ActionsDAGPtr before_where;
|
|
|
|
ActionsDAGPtr before_aggregation;
|
|
|
|
Names required_columns;
|
|
|
|
NamesAndTypesList aggregation_keys;
|
|
|
|
AggregateDescriptions aggregate_descriptions;
|
|
|
|
};
|
|
|
|
|
2017-07-15 04:06:51 +00:00
|
|
|
/** Query along with some additional data,
|
|
|
|
* that can be used during query processing
|
|
|
|
* inside storage engines.
|
|
|
|
*/
|
|
|
|
struct SelectQueryInfo
|
|
|
|
{
|
|
|
|
ASTPtr query;
|
2020-06-15 12:36:10 +00:00
|
|
|
ASTPtr view_query; /// Optimized VIEW query
|
2017-07-15 04:06:51 +00:00
|
|
|
|
2021-03-29 19:02:34 +00:00
|
|
|
/// Cluster for the query.
|
2020-09-20 17:52:17 +00:00
|
|
|
ClusterPtr cluster;
|
2021-03-29 19:02:34 +00:00
|
|
|
/// Optimized cluster for the query.
|
|
|
|
/// In case of optimize_skip_unused_shards it may differs from original cluster.
|
|
|
|
///
|
|
|
|
/// Configured in StorageDistributed::getQueryProcessingStage()
|
|
|
|
ClusterPtr optimized_cluster;
|
2020-09-10 19:55:36 +00:00
|
|
|
|
2020-07-22 17:13:05 +00:00
|
|
|
TreeRewriterResultPtr syntax_analyzer_result;
|
2018-11-08 15:43:14 +00:00
|
|
|
|
2021-02-13 22:07:13 +00:00
|
|
|
PrewhereInfoPtr prewhere_info;
|
2018-04-06 13:58:06 +00:00
|
|
|
|
2020-05-13 13:49:10 +00:00
|
|
|
ReadInOrderOptimizerPtr order_optimizer;
|
2020-09-20 17:52:17 +00:00
|
|
|
/// Can be modified while reading from storage
|
|
|
|
InputOrderInfoPtr input_order_info;
|
2019-12-10 23:18:24 +00:00
|
|
|
|
2017-07-15 04:06:51 +00:00
|
|
|
/// Prepared sets are used for indices by storage engine.
|
|
|
|
/// Example: x IN (1, 2, 3)
|
|
|
|
PreparedSets sets;
|
2021-03-29 19:02:34 +00:00
|
|
|
|
|
|
|
ClusterPtr getCluster() const { return !optimized_cluster ? cluster : optimized_cluster; }
|
2021-02-10 14:12:49 +00:00
|
|
|
|
2021-04-25 02:26:36 +00:00
|
|
|
/// If not null, it means we choose a projection to execute current query.
|
2021-04-29 07:38:47 +00:00
|
|
|
std::optional<ProjectionCandidate> projection;
|
2021-04-21 16:00:27 +00:00
|
|
|
bool ignore_projections = false;
|
2017-07-15 04:06:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|