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

Method buildQueryPlan

src/Interpreters/InterpreterSelectQuery.cpp:745–801  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

743}
744
745void InterpreterSelectQuery::buildQueryPlan(QueryPlan & query_plan)
746{
747 std::shared_ptr<InterpreterPerfectShard> interpreter_perfect_shard
748 = context->getSettingsRef().distributed_perfect_shard ? std::make_shared<InterpreterPerfectShard>(*this) : nullptr;
749
750 if (interpreter_perfect_shard && interpreter_perfect_shard->checkPerfectShardable())
751 {
752 interpreter_perfect_shard->buildQueryPlan(query_plan);
753 }
754 else
755 executeImpl(query_plan, input, std::move(input_pipe));
756
757 /// We must guarantee that result structure is the same as in getSampleBlock()
758 ///
759 /// But if it's a projection query, plan header does not match result_header.
760 /// TODO: add special stage for InterpreterSelectQuery?
761 if (!options.is_projection_query && !blocksHaveEqualStructure(query_plan.getCurrentDataStream().header, result_header))
762 {
763 auto convert_actions_dag = ActionsDAG::makeConvertingActions(
764 query_plan.getCurrentDataStream().header.getColumnsWithTypeAndName(),
765 result_header.getColumnsWithTypeAndName(),
766 ActionsDAG::MatchColumnsMode::Name,
767 true);
768
769 auto converting = std::make_unique<ExpressionStep>(query_plan.getCurrentDataStream(), convert_actions_dag);
770 query_plan.addStep(std::move(converting));
771 }
772
773 if (context->getSettingsRef().enable_final_sample)
774 {
775 auto & query = getSelectQuery();
776 if (query.sampleSize())
777 {
778 ASTSampleRatio * sample = query.sampleSize()->as<ASTSampleRatio>();
779 ASTSampleRatio::BigNum numerator = sample->ratio.numerator;
780 ASTSampleRatio::BigNum denominator = sample->ratio.denominator;
781 if (numerator <= 1 || denominator > 1)
782 return;
783
784 auto sampling
785 = std::make_unique<FinalSampleStep>(query_plan.getCurrentDataStream(), numerator, context->getSettingsRef().max_block_size);
786 query_plan.addStep(std::move(sampling));
787 }
788 }
789
790 if (!table_id.empty())
791 addUsedStorageID(table_id);
792 if (has_join)
793 setHasAllUsedStorageIDs(false);
794
795 if (interpreter_subquery)
796 {
797 addUsedStorageIDs(interpreter_subquery->getUsedStorageIDs());
798 if (!interpreter_subquery->hasAllUsedStorageIDs())
799 setHasAllUsedStorageIDs(false);
800 }
801}
802

Callers 15

readMethod · 0.45
readMethod · 0.45
readMethod · 0.45
readMethod · 0.45
readMethod · 0.45
makeTableJoinMethod · 0.45
makeSetMethod · 0.45
executeFetchColumnsMethod · 0.45
validateMethod · 0.45
executeMethod · 0.45
explainMethod · 0.45
explainMetaDataMethod · 0.45

Calls 9

blocksHaveEqualStructureFunction · 0.85
checkPerfectShardableMethod · 0.80
sampleSizeMethod · 0.80
executeImplFunction · 0.50
getSelectQueryFunction · 0.50
addStepMethod · 0.45
emptyMethod · 0.45
getUsedStorageIDsMethod · 0.45
hasAllUsedStorageIDsMethod · 0.45

Tested by

no test coverage detected