| 1244 | } |
| 1245 | |
| 1246 | Block InterpreterSelectQuery::getSampleBlockImpl() |
| 1247 | { |
| 1248 | auto & select_query = getSelectQuery(); |
| 1249 | |
| 1250 | query_info.query = query_ptr; |
| 1251 | |
| 1252 | /// NOTE: this is required for getQueryProcessingStage(), so should be initialized before ExpressionAnalysisResult. |
| 1253 | query_info.has_window = query_analyzer->hasWindow(); |
| 1254 | /// NOTE: this is required only for IStorage::read(), and to be precise MergeTreeData::read(), in case of projections. |
| 1255 | query_info.has_order_by = select_query.orderBy() != nullptr; |
| 1256 | query_info.need_aggregate = query_analyzer->hasAggregation(); |
| 1257 | |
| 1258 | if (storage && !options.only_analyze) |
| 1259 | { |
| 1260 | query_info.prepared_sets = query_analyzer->getPreparedSets(); |
| 1261 | from_stage = storage->getQueryProcessingStage(context, options.to_stage, storage_snapshot, query_info); |
| 1262 | } |
| 1263 | |
| 1264 | /// Do I need to perform the first part of the pipeline? |
| 1265 | /// Running on remote servers during distributed processing or if query is not distributed. |
| 1266 | /// |
| 1267 | /// Also note that with distributed_group_by_no_merge=1 or when there is |
| 1268 | /// only one remote server, it is equal to local query in terms of query |
| 1269 | /// stages (or when due to optimize_distributed_group_by_sharding_key the query was processed up to Complete stage). |
| 1270 | bool first_stage = from_stage < QueryProcessingStage::WithMergeableState |
| 1271 | && options.to_stage >= QueryProcessingStage::WithMergeableState; |
| 1272 | /// Do I need to execute the second part of the pipeline? |
| 1273 | /// Running on the initiating server during distributed processing or if query is not distributed. |
| 1274 | /// |
| 1275 | /// Also note that with distributed_group_by_no_merge=2 (i.e. when optimize_distributed_group_by_sharding_key takes place) |
| 1276 | /// the query on the remote server will be processed up to WithMergeableStateAfterAggregationAndLimit, |
| 1277 | /// So it will do partial second stage (second_stage=true), and initiator will do the final part. |
| 1278 | bool second_stage = from_stage <= QueryProcessingStage::WithMergeableState |
| 1279 | && options.to_stage > QueryProcessingStage::WithMergeableState; |
| 1280 | |
| 1281 | analysis_result = ExpressionAnalysisResult( |
| 1282 | *query_analyzer, metadata_snapshot, first_stage, second_stage, options.only_analyze, row_policy_info, additional_filter_info, *source_header); |
| 1283 | |
| 1284 | if (options.to_stage == QueryProcessingStage::Enum::FetchColumns) |
| 1285 | { |
| 1286 | auto header = *source_header; |
| 1287 | |
| 1288 | if (analysis_result.prewhere_info) |
| 1289 | { |
| 1290 | header = analysis_result.prewhere_info->prewhere_actions.updateHeader(header); |
| 1291 | if (analysis_result.prewhere_info->remove_prewhere_column) |
| 1292 | header.erase(analysis_result.prewhere_info->prewhere_column_name); |
| 1293 | } |
| 1294 | return header; |
| 1295 | } |
| 1296 | |
| 1297 | if (options.to_stage == QueryProcessingStage::Enum::WithMergeableState) |
| 1298 | { |
| 1299 | if (!analysis_result.need_aggregate) |
| 1300 | { |
| 1301 | // What's the difference with selected_columns? |
| 1302 | // Here we calculate the header we want from remote server after it |
| 1303 | // executes query up to WithMergeableState. When there is an ORDER BY, |
nothing calls this directly
no test coverage detected