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

Function executeQueryImpl

src/Interpreters/executeQuery.cpp:1092–1996  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1090
1091
1092static BlockIO executeQueryImpl(
1093 const char * begin,
1094 const char * end,
1095 ContextMutablePtr context,
1096 QueryFlags flags,
1097 QueryProcessingStage::Enum stage,
1098 ReadBufferUniquePtr & istr,
1099 ASTPtr & out_ast,
1100 ImplicitTransactionControlExecutorPtr implicit_tcl_executor,
1101 HTTPContinueCallback http_continue_callback,
1102 QueryResultDetails & result_details)
1103{
1104 const bool internal = flags.internal;
1105
1106 /// query_span is a special span, when this function exits, it's lifetime is not ended, but ends when the query finishes.
1107 /// Some internal queries might call this function recursively by setting 'internal' parameter to 'true',
1108 /// to make sure SpanHolders in current stack ends in correct order, we disable this span for these internal queries
1109 ///
1110 /// This does not have impact on the final span logs, because these internal queries are issued by external queries,
1111 /// we still have enough span logs for the execution of external queries.
1112 std::shared_ptr<OpenTelemetry::SpanHolder> query_span = internal ? nullptr : std::make_shared<OpenTelemetry::SpanHolder>("query");
1113 if (query_span && query_span->trace_id != UUID{})
1114 LOG_TRACE(getLogger("executeQuery"), "Query span trace_id for opentelemetry log: {}", query_span->trace_id);
1115
1116 /// Used for logging query start time in system.query_log
1117 auto query_start_time = std::chrono::system_clock::now();
1118
1119 /// Used for:
1120 /// * Setting the watch in QueryStatus (controls timeouts and progress) and the output formats
1121 /// * Logging query duration (system.query_log)
1122 Stopwatch start_watch{CLOCK_MONOTONIC};
1123
1124 const auto & client_info = context->getClientInfo();
1125
1126 if (client_info.initial_query_start_time == 0)
1127 {
1128 // If we don't see an initial_query_start_time yet, initialize it to current time.
1129 // It's possible to have unset initial_query_start_time for non-initial queries. For
1130 // example, the query is from an initiator that is running an old version of clickhouse.
1131 // On the other hand, if it's initialized then take it as the start of the query
1132 context->setInitialQueryStartTime(query_start_time);
1133 }
1134
1135 chassert(internal || CurrentThread::get().tryGetQueryContext());
1136 chassert(internal || CurrentThread::get().tryGetQueryContext()->getCurrentQueryId() == CurrentThread::getQueryId());
1137
1138 const Settings & settings = context->getSettingsRef();
1139
1140 size_t max_query_size = settings[Setting::max_query_size];
1141 /// Don't limit the size of internal queries or distributed subquery.
1142 if (internal || client_info.query_kind == ClientInfo::QueryKind::SECONDARY_QUERY)
1143 max_query_size = 0;
1144
1145 String query;
1146 String query_for_logging;
1147 UInt64 normalized_query_hash = 0;
1148 size_t log_queries_cut_to_length = settings[Setting::log_queries_cut_to_length];
1149

Callers 1

executeQueryFunction · 0.85

Calls 15

parseKQLQueryFunction · 0.85
parseQueryFunction · 0.85
normalizedQueryHashFunction · 0.85
logQueryFunction · 0.85
logExceptionBeforeStartFunction · 0.85
validateAnalyzerSettingsFunction · 0.85
checkASTSizeLimitsFunction · 0.85
logQueryStartFunction · 0.85

Tested by

no test coverage detected