#pragma once #include #include #include #include #include #include #include namespace DB { class ExpressionActions; using ExpressionActionsPtr = std::shared_ptr; class ActionsDAG; using ActionsDAGPtr = std::shared_ptr; struct PrewhereInfo; using PrewhereInfoPtr = std::shared_ptr; struct FilterInfo; using FilterInfoPtr = std::shared_ptr; struct FilterDAGInfo; using FilterDAGInfoPtr = std::shared_ptr; struct InputOrderInfo; using InputOrderInfoPtr = std::shared_ptr; struct TreeRewriterResult; using TreeRewriterResultPtr = std::shared_ptr; class ReadInOrderOptimizer; using ReadInOrderOptimizerPtr = std::shared_ptr; class Cluster; using ClusterPtr = std::shared_ptr; struct MergeTreeDataSelectAnalysisResult; using MergeTreeDataSelectAnalysisResultPtr = std::shared_ptr; struct SubqueryForSet; using SubqueriesForSets = std::unordered_map; struct PrewhereInfo { /// Actions which are executed in order to alias columns are used for prewhere actions. ActionsDAGPtr alias_actions; /// 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. ActionsDAGPtr row_level_filter; /// Actions which are executed on block in order to get filter column for prewhere step. ActionsDAGPtr prewhere_actions; String row_level_column_name; String prewhere_column_name; bool remove_prewhere_column = false; bool need_filter = false; PrewhereInfo() = default; explicit PrewhereInfo(ActionsDAGPtr prewhere_actions_, String prewhere_column_name_) : prewhere_actions(std::move(prewhere_actions_)), prewhere_column_name(std::move(prewhere_column_name_)) {} std::string dump() const; }; /// Helper struct to store all the information about the filter expression. struct FilterInfo { ExpressionActionsPtr alias_actions; ExpressionActionsPtr actions; String column_name; bool do_remove_column = false; }; /// Same as FilterInfo, but with ActionsDAG. struct FilterDAGInfo { ActionsDAGPtr actions; String column_name; bool do_remove_column = false; std::string dump() const; }; struct InputOrderInfo { SortDescription order_key_fixed_prefix_descr; SortDescription order_key_prefix_descr; int direction; UInt64 limit; InputOrderInfo( const SortDescription & order_key_fixed_prefix_descr_, const SortDescription & order_key_prefix_descr_, int direction_, UInt64 limit_) : order_key_fixed_prefix_descr(order_key_fixed_prefix_descr_) , order_key_prefix_descr(order_key_prefix_descr_) , direction(direction_), limit(limit_) { } bool operator==(const InputOrderInfo &) const = default; }; class IMergeTreeDataPart; using ManyExpressionActions = std::vector; // The projection selected to execute current query struct ProjectionCandidate { ProjectionDescriptionRawPtr desc{}; PrewhereInfoPtr prewhere_info; ActionsDAGPtr before_where; String where_column_name; bool remove_where_filter = false; ActionsDAGPtr before_aggregation; Names required_columns; NamesAndTypesList aggregation_keys; AggregateDescriptions aggregate_descriptions; bool aggregate_overflow_row = false; bool aggregate_final = false; bool complete = false; ReadInOrderOptimizerPtr order_optimizer; InputOrderInfoPtr input_order_info; ManyExpressionActions group_by_elements_actions; std::shared_ptr subqueries_for_sets; MergeTreeDataSelectAnalysisResultPtr merge_tree_projection_select_result_ptr; MergeTreeDataSelectAnalysisResultPtr merge_tree_normal_select_result_ptr; }; /** Query along with some additional data, * that can be used during query processing * inside storage engines. */ struct SelectQueryInfo { ASTPtr query; ASTPtr view_query; /// Optimized VIEW query ASTPtr original_query; /// Unmodified query for projection analysis /// Cluster for the query. ClusterPtr cluster; /// 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; TreeRewriterResultPtr syntax_analyzer_result; PrewhereInfoPtr prewhere_info; ReadInOrderOptimizerPtr order_optimizer; /// Can be modified while reading from storage InputOrderInfoPtr input_order_info; /// Prepared sets are used for indices by storage engine. /// Example: x IN (1, 2, 3) PreparedSets sets; /// Cached value of ExpressionAnalysisResult::has_window bool has_window = false; ClusterPtr getCluster() const { return !optimized_cluster ? cluster : optimized_cluster; } /// If not null, it means we choose a projection to execute current query. std::optional projection; bool ignore_projections = false; bool is_projection_query = false; bool merge_tree_empty_result = false; bool settings_limit_offset_done = false; Block minmax_count_projection_block; MergeTreeDataSelectAnalysisResultPtr merge_tree_select_result_ptr; }; }