MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / buildSelectQueryPlan

Function buildSelectQueryPlan

src/Processors/QueryPlan/ReadFromLoopStep.cpp:45–87  ·  view source on GitHub ↗

Build a query plan by constructing a synthetic SELECT query and running it through the interpreter. The FROM clause is either a catalog table (database.table) or a table function AST — exactly one of the two must be provided.

Source from the content-addressed store, hash-verified

43 /// the interpreter. The FROM clause is either a catalog table (database.table) or a
44 /// table function AST — exactly one of the two must be provided.
45 void buildSelectQueryPlan(
46 QueryPlan & plan,
47 const Names & column_names,
48 const SelectQueryInfo & query_info,
49 ContextPtr context,
50 const String & database = {},
51 const String & table = {},
52 const ASTPtr & table_function_ast = nullptr)
53 {
54 auto select_query = make_intrusive<ASTSelectQuery>();
55
56 auto select_expr_list = make_intrusive<ASTExpressionList>();
57 for (const auto & col_name : column_names)
58 select_expr_list->children.push_back(make_intrusive<ASTIdentifier>(col_name));
59 select_query->setExpression(ASTSelectQuery::Expression::SELECT, std::move(select_expr_list));
60
61 if (table_function_ast)
62 select_query->addTableFunction(table_function_ast);
63 else
64 select_query->replaceDatabaseAndTable(database, table);
65
66 auto select_ast = make_intrusive<ASTSelectWithUnionQuery>();
67 select_ast->list_of_selects = make_intrusive<ASTExpressionList>();
68 select_ast->list_of_selects->children.push_back(select_query);
69 select_ast->children.push_back(select_ast->list_of_selects);
70
71 auto options = SelectQueryOptions(QueryProcessingStage::Complete, 0, false);
72
73 if (context->getSettingsRef()[Setting::allow_experimental_analyzer])
74 {
75 InterpreterSelectQueryAnalyzer interpreter(select_ast, context, options, column_names);
76 if (query_info.storage_limits)
77 interpreter.addStorageLimits(*query_info.storage_limits);
78 plan = std::move(interpreter).extractQueryPlan();
79 }
80 else
81 {
82 InterpreterSelectWithUnionQuery interpreter(select_ast, context, options, column_names);
83 if (query_info.storage_limits)
84 interpreter.addStorageLimits(*query_info.storage_limits);
85 interpreter.buildQueryPlan(plan);
86 }
87 }
88}
89
90class LoopSource : public ISource

Callers 1

initLoopMethod · 0.85

Calls 8

addTableFunctionMethod · 0.80
extractQueryPlanMethod · 0.80
SelectQueryOptionsClass · 0.50
push_backMethod · 0.45
setExpressionMethod · 0.45
addStorageLimitsMethod · 0.45
buildQueryPlanMethod · 0.45

Tested by

no test coverage detected