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

Method sendExternalTables

src/QueryPipeline/RemoteQueryExecutor.cpp:877–948  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

875}
876
877void RemoteQueryExecutor::sendExternalTables()
878{
879 size_t count = connections->size();
880
881 {
882 std::lock_guard lock(external_tables_mutex);
883
884 external_tables_data.clear();
885 external_tables_data.reserve(count);
886
887 StreamLocalLimits limits;
888 const auto & settings = context->getSettingsRef();
889 limits.mode = LimitsMode::LIMITS_TOTAL;
890 limits.speed_limits.max_execution_time = settings[Setting::max_execution_time];
891 limits.timeout_overflow_mode = settings[Setting::timeout_overflow_mode];
892 limits.speed_limits.max_estimated_execution_time = settings[Setting::max_estimated_execution_time];
893
894 for (size_t i = 0; i < count; ++i)
895 {
896 ExternalTablesData res;
897 for (const auto & table : external_tables)
898 {
899 StoragePtr cur = table.second;
900 /// Send only temporary tables with StorageMemory
901 auto storage_memory = std::dynamic_pointer_cast<StorageMemory>(cur);
902 if (!storage_memory)
903 continue;
904
905 /// Skip sending Materialized CTEs when they are not built.
906 /// It is required to be able CTE materialization plan with parallel replicas (avoiding
907 /// circular dependency between CTE materialization and parallel replicas external tables.
908 auto materialized_cte = storage_memory->getMaterializedCTE();
909 if (materialized_cte != nullptr && !materialized_cte->isBuilt())
910 {
911 LOG_DEBUG(log, "Skipping sending CTE '{}' because it has not been materialized yet", materialized_cte->cte_name);
912 continue;
913 }
914
915 auto data = std::make_unique<ExternalTableData>();
916 data->table_name = table.first;
917 data->creating_pipe_callback = [cur, limits, my_context = this->context]()
918 {
919 SelectQueryInfo query_info;
920 auto metadata_snapshot = cur->getInMemoryMetadataPtr(my_context, false);
921 auto storage_snapshot = cur->getStorageSnapshot(metadata_snapshot, my_context);
922 QueryProcessingStage::Enum read_from_table_stage = cur->getQueryProcessingStage(
923 my_context, QueryProcessingStage::Complete, storage_snapshot, query_info);
924
925 QueryPlan plan;
926 cur->read(
927 plan,
928 metadata_snapshot->getColumns().getNamesOfPhysical(),
929 storage_snapshot, query_info, my_context,
930 read_from_table_stage, DEFAULT_BLOCK_SIZE, 1);
931
932 auto builder = plan.buildQueryPipeline(QueryPlanOptimizationSettings(my_context), BuildQueryPipelineSettings(my_context));
933
934 builder->resize(1);

Callers

nothing calls this directly

Calls 15

getMaterializedCTEMethod · 0.80
isBuiltMethod · 0.80
getNamesOfPhysicalMethod · 0.80
getSharedHeaderMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
reserveMethod · 0.45
getStorageSnapshotMethod · 0.45

Tested by

no test coverage detected