| 2070 | } |
| 2071 | |
| 2072 | ExpressionAnalysisResult::ExpressionAnalysisResult( |
| 2073 | SelectQueryExpressionAnalyzer & query_analyzer, |
| 2074 | const StorageMetadataPtr & metadata_snapshot, |
| 2075 | bool first_stage_, |
| 2076 | bool second_stage_, |
| 2077 | bool only_types, |
| 2078 | const FilterDAGInfoPtr & filter_info_, |
| 2079 | const Block & source_header, |
| 2080 | const std::vector<ASTPtr> & additional_predicates) |
| 2081 | : first_stage(first_stage_) |
| 2082 | , second_stage(second_stage_) |
| 2083 | , need_aggregate(query_analyzer.hasAggregation()) |
| 2084 | , has_window(query_analyzer.hasWindow()) |
| 2085 | , use_grouping_set_key(query_analyzer.useGroupingSetKey()) |
| 2086 | { |
| 2087 | /// first_stage: Do I need to perform the first part of the pipeline - running on remote servers during distributed processing. |
| 2088 | /// second_stage: Do I need to execute the second part of the pipeline - running on the initiating server during distributed processing. |
| 2089 | |
| 2090 | /** First we compose a chain of actions and remember the necessary steps from it. |
| 2091 | * Regardless of from_stage and to_stage, we will compose a complete sequence of actions to perform optimization and |
| 2092 | * throw out unnecessary columns based on the entire query. In unnecessary parts of the query, we will not execute subqueries. |
| 2093 | */ |
| 2094 | |
| 2095 | const ASTSelectQuery & query = *query_analyzer.getSelectQuery(); |
| 2096 | auto context = query_analyzer.getContext(); |
| 2097 | const Settings & settings = context->getSettingsRef(); |
| 2098 | const ConstStoragePtr & storage = query_analyzer.storage(); |
| 2099 | Block precomputed_header; |
| 2100 | auto index_context = query_analyzer.getIndexContext(); |
| 2101 | if (auto * bitmap_index_info = dynamic_cast<BitmapIndexInfo *>(index_context->get(MergeTreeIndexInfo::Type::BITMAP).get())) |
| 2102 | { |
| 2103 | for (auto & ele : bitmap_index_info->return_types) |
| 2104 | { |
| 2105 | if (ele.second == BitmapIndexReturnType::EXPRESSION) |
| 2106 | precomputed_header.insert({std::make_shared<DataTypeUInt8>(), ele.first}); |
| 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | bool finalized = false; |
| 2111 | size_t where_step_num = 0; |
| 2112 | |
| 2113 | auto finalize_chain = [&](ExpressionActionsChain & chain) { |
| 2114 | chain.finalize(); |
| 2115 | |
| 2116 | if (!finalized) |
| 2117 | { |
| 2118 | finalize(chain, where_step_num, query); |
| 2119 | finalized = true; |
| 2120 | } |
| 2121 | |
| 2122 | // fmt::print("After finallize ---------- \n{}\n", chain.dumpChain()); |
| 2123 | |
| 2124 | chain.clear(); |
| 2125 | }; |
| 2126 | |
| 2127 | if (storage) |
| 2128 | { |
| 2129 | query_analyzer.makeSetsForIndex(query.where()); |
nothing calls this directly
no test coverage detected