MCPcopy Create free account
hub / github.com/ByConity/ByConity / check

Method check

src/Optimizer/QueryUseOptimizerChecker.cpp:105–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105bool QueryUseOptimizerChecker::check(ASTPtr node, ContextMutablePtr context, bool throw_exception)
106{
107 if (!node || (!context->getSettingsRef().enable_optimizer))
108 {
109 turnOffOptimizer(context, node);
110 return false;
111 }
112
113 // Optimizer only work for Server.
114 // for example INSERT INTO parallel_replicas_backup(d, x, u, s) SELECT d, x, u, s FROM parallel_replicas;
115 // will execute query : INSERT INTO test.parallel_replicas_backup_4313395779120660490 (d, x, u, s) SELECT d, x, u, s FROM test.parallel_replicas )
116 // will execute query : SELECT d, x, u, s FROM test.parallel_replicas_4313395779120660490
117 // in worker.
118 if (context->getServerType() == ServerType::cnch_worker)
119 {
120 turnOffOptimizer(context, node);
121 return false;
122 }
123
124 if (!context->getSettingsRef().enable_optimizer && context->getSettingsRef().enable_distributed_output)
125 throw Exception("Distributed output in non-optimizer mode is not supported, please enable optimizer.", ErrorCodes::UNSUPPORTED_PARAMETER);
126
127 String reason;
128 if (auto * explain = node->as<ASTExplainQuery>())
129 {
130 bool explain_plan = explain->getKind() == ASTExplainQuery::ExplainKind::OptimizerPlan
131 || explain->getKind() == ASTExplainQuery::ExplainKind::QueryPlan
132 || explain->getKind() == ASTExplainQuery::ExplainKind::QueryPipeline
133 || explain->getKind() == ASTExplainQuery::AnalyzedSyntax
134 || explain->getKind() == ASTExplainQuery::DistributedAnalyze
135 || explain->getKind() == ASTExplainQuery::LogicalAnalyze
136 || explain->getKind() == ASTExplainQuery::PipelineAnalyze
137 || explain->getKind() == ASTExplainQuery::Distributed
138 || explain->getKind() == ASTExplainQuery::TraceOptimizerRule
139 || explain->getKind() == ASTExplainQuery::TraceOptimizer
140 || explain->getKind() == ASTExplainQuery::MetaData;
141 if (!explain_plan)
142 reason = "unsupported explain type";
143 return explain_plan && check(explain->getExplainedQuery(), context, throw_exception);
144 }
145 if (auto * prepare = node->as<ASTCreatePreparedStatementQuery>())
146 {
147 return check(prepare->getQuery(), context, throw_exception);
148 }
149
150
151 bool support = false;
152
153 if (node->as<ASTSelectQuery>() || node->as<ASTSelectWithUnionQuery>() || node->as<ASTSelectIntersectExceptQuery>())
154 {
155 // disable system query, table function, no merge tree table
156 NameSet with_tables;
157
158 QueryUseOptimizerVisitor checker;
159 QueryUseOptimizerContext check_context{.context = context};
160 try
161 {
162 support = ASTVisitorUtil::accept(node, checker, check_context);

Callers

nothing calls this directly

Calls 11

turnOffOptimizerFunction · 0.85
checkDatabaseAndTableFunction · 0.85
getServerTypeMethod · 0.80
getCurrentDatabaseMethod · 0.80
ExceptionClass · 0.50
checkFunction · 0.50
getFunction · 0.50
getKindMethod · 0.45
getQueryMethod · 0.45
emptyMethod · 0.45
getTableNameMethod · 0.45

Tested by

no test coverage detected