1#pragma once
2
3#include <Interpreters/PreparedSets.h>
4#include <Core/SortDescription.h>
5#include <memory>
6
7namespace DB
8{
9
10class ExpressionActions;
11using ExpressionActionsPtr = std::shared_ptr<ExpressionActions>;
12
13struct PrewhereInfo
14{
15 /// Actions which are executed in order to alias columns are used for prewhere actions.
16 ExpressionActionsPtr alias_actions;
17 /// Actions which are executed on block in order to get filter column for prewhere step.
18 ExpressionActionsPtr prewhere_actions;
19 /// Actions which are executed after reading from storage in order to remove unused columns.
20 ExpressionActionsPtr remove_columns_actions;
21 String prewhere_column_name;
22 bool remove_prewhere_column = false;
23 bool need_filter = false;
24
25 PrewhereInfo() = default;
26 explicit PrewhereInfo(ExpressionActionsPtr prewhere_actions_, String prewhere_column_name_)
27 : prewhere_actions(std::move(prewhere_actions_)), prewhere_column_name(std::move(prewhere_column_name_)) {}
28};
29
30/// Helper struct to store all the information about the filter expression.
31struct FilterInfo
32{
33 ExpressionActionsPtr actions;
34 String column_name;
35 bool do_remove_column = false;
36};
37
38struct InputSortingInfo
39{
40 SortDescription order_key_prefix_descr;
41 int direction;
42
43 InputSortingInfo(const SortDescription & order_key_prefix_descr_, int direction_)
44 : order_key_prefix_descr(order_key_prefix_descr_), direction(direction_) {}
45
46 bool operator ==(const InputSortingInfo & other) const
47 {
48 return order_key_prefix_descr == other.order_key_prefix_descr && direction == other.direction;
49 }
50
51 bool operator !=(const InputSortingInfo & other) const { return !(*this == other); }
52};
53
54using PrewhereInfoPtr = std::shared_ptr<PrewhereInfo>;
55using FilterInfoPtr = std::shared_ptr<FilterInfo>;
56using InputSortingInfoPtr = std::shared_ptr<const InputSortingInfo>;
57
58struct SyntaxAnalyzerResult;
59using SyntaxAnalyzerResultPtr = std::shared_ptr<const SyntaxAnalyzerResult>;
60
61class ReadInOrderOptimizer;
62using ReadInOrderOptimizerPtr = std::shared_ptr<const ReadInOrderOptimizer>;
63
64/** Query along with some additional data,
65 * that can be used during query processing
66 * inside storage engines.
67 */
68struct SelectQueryInfo
69{
70 ASTPtr query;
71
72 SyntaxAnalyzerResultPtr syntax_analyzer_result;
73
74 PrewhereInfoPtr prewhere_info;
75
76 ReadInOrderOptimizerPtr order_by_optimizer;
77 /// We can modify it while reading from storage
78 mutable InputSortingInfoPtr input_sorting_info;
79
80 /// Prepared sets are used for indices by storage engine.
81 /// Example: x IN (1, 2, 3)
82 PreparedSets sets;
83};
84
85}
86