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

Method buildInsertPipeline

src/Interpreters/InterpreterInsertQuery.cpp:744–852  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

742
743
744QueryPipeline InterpreterInsertQuery::buildInsertPipeline(ASTInsertQuery & query, StoragePtr table)
745{
746 auto context = getContext();
747
748 // disable parallel replicas for inserts if enabled
749 // the insert can trigger update for dependent materialized views
750 // using parallel replicas in this context is unnecessary
751 if (context->canUseParallelReplicasOnInitiator())
752 {
753 auto mutable_context = Context::createCopy(context);
754 mutable_context->setSetting("enable_parallel_replicas", Field{0});
755 context = mutable_context;
756 }
757
758 const Settings & settings = context->getSettingsRef();
759 auto metadata_snapshot = table->getInMemoryMetadataPtr(context, false);
760 auto query_sample_block
761 = std::make_shared<const Block>(getSampleBlock(query, table, metadata_snapshot, context, no_destination, allow_materialized));
762 if (query_sample_block->empty())
763 throw Exception(ErrorCodes::EMPTY_LIST_OF_COLUMNS_PASSED, "Empty list of columns to insert");
764
765 // when insert is initiated from FileLog or similar storages
766 // they are allowed to expose its virtuals columns to the dependent views
767 auto insert_dependencies = InsertDependenciesBuilder::create(
768 table,
769 query_ptr,
770 query_sample_block,
771 async_insert,
772 /*skip_destination_table*/ no_destination,
773 /*max_insert_threads*/ 1,
774 context);
775
776 auto chains = insert_dependencies->createChainWithDependenciesForAllStreams();
777 chassert(chains.size() == 1);
778 auto chain = std::move(chains.front());
779 bool squash_with_strict_limits = settings[Setting::use_strict_insert_block_limits] && !async_insert;
780
781 if (squash_with_strict_limits)
782 {
783 chain.addSource(
784 std::make_shared<AddDeduplicationInfoTransform>(
785 insert_dependencies,
786 insert_dependencies->getRootViewID(),
787 settings[Setting::insert_deduplication_token].value,
788 context->getServerSettings()[ServerSetting::insert_deduplication_version].value,
789 chain.getInputSharedHeader())
790 );
791 }
792
793 if (shouldAddSquashingForStorage(table, context) && !no_squash)
794 {
795 auto applying = std::make_shared<ApplySquashingTransform>(chain.getInputSharedHeader());
796 chain.addSource(std::move(applying));
797 }
798
799 if (shouldAddSquashingForStorage(table, context) && !no_squash)
800 {
801 bool table_prefers_large_blocks = table->prefersLargeBlocks();

Callers

nothing calls this directly

Calls 15

getSourceFromInputFormatFunction · 0.85
getRootViewIDMethod · 0.80
getProgressCallbackMethod · 0.80
hasInlinedDataMethod · 0.80
getSampleBlockFunction · 0.70
ExceptionClass · 0.70
getContextFunction · 0.50
createFunction · 0.50
QueryPipelineClass · 0.50

Tested by

no test coverage detected