| 1001 | } |
| 1002 | |
| 1003 | std::optional<UUID> RefreshTask::executeRefreshUnlocked(int32_t root_znode_version, std::vector<StorageID> deps, const String & log_comment, String & out_error_message) |
| 1004 | { |
| 1005 | StorageID view_storage_id = view->getStorageID(); |
| 1006 | LOG_DEBUG(getLogger(), "Refreshing view"); |
| 1007 | execution.progress.reset(); |
| 1008 | |
| 1009 | static constexpr bool internal = true; |
| 1010 | |
| 1011 | ContextMutablePtr refresh_context = view->getContext(); |
| 1012 | ProcessList::EntryPtr process_list_entry; |
| 1013 | std::optional<StorageID> table_to_drop; |
| 1014 | auto new_table_id = StorageID::createEmpty(); |
| 1015 | |
| 1016 | std::optional<QueryLogElement> query_log_elem; |
| 1017 | boost::intrusive_ptr<ASTInsertQuery> refresh_query; |
| 1018 | String query_for_logging; |
| 1019 | UInt64 normalized_query_hash = 0; |
| 1020 | std::shared_ptr<OpenTelemetry::SpanHolder> query_span = std::make_shared<OpenTelemetry::SpanHolder>("query"); |
| 1021 | Stopwatch stopwatch; |
| 1022 | |
| 1023 | try |
| 1024 | { |
| 1025 | refresh_context = view->createRefreshContext(log_comment); |
| 1026 | |
| 1027 | syncDependenciesForRefresh(deps, refresh_context); |
| 1028 | |
| 1029 | if (!refresh_append) |
| 1030 | { |
| 1031 | refresh_context->setParentTable(view_storage_id.uuid); |
| 1032 | refresh_context->setDDLQueryCancellation(execution.cancel_ddl_queries.get_token()); |
| 1033 | if (root_znode_version != -1) |
| 1034 | refresh_context->setDDLAdditionalChecksOnEnqueue({zkutil::makeCheckRequest(coordination.path, root_znode_version)}); |
| 1035 | } |
| 1036 | |
| 1037 | { |
| 1038 | /// Create a table. |
| 1039 | query_for_logging = "(create target table)"; |
| 1040 | normalized_query_hash = normalizedQueryHash(query_for_logging, false); |
| 1041 | QueryScope query_scope; |
| 1042 | std::tie(refresh_query, query_scope) = view->prepareRefresh(refresh_append, refresh_context, table_to_drop); |
| 1043 | new_table_id = refresh_query->table_id; |
| 1044 | |
| 1045 | /// Add the query to system.processes and allow it to be killed with KILL QUERY. |
| 1046 | query_for_logging = refresh_query->formatForLogging( |
| 1047 | refresh_context->getSettingsRef()[Setting::log_queries_cut_to_length]); |
| 1048 | normalized_query_hash = normalizedQueryHash(query_for_logging, false); |
| 1049 | |
| 1050 | process_list_entry = refresh_context->getProcessList().insert( |
| 1051 | query_for_logging, normalized_query_hash, refresh_query.get(), refresh_context, Stopwatch{CLOCK_MONOTONIC}.getStart(), internal); |
| 1052 | |
| 1053 | refresh_context->setProcessListElement(process_list_entry->getQueryStatus()); |
| 1054 | refresh_context->setProgressCallback([this](const Progress & prog) |
| 1055 | { |
| 1056 | execution.progress.incrementPiecewiseAtomically(prog); |
| 1057 | }); |
| 1058 | |
| 1059 | /// Run the query. |
| 1060 |
nothing calls this directly
no test coverage detected