| 743 | } |
| 744 | |
| 745 | void 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 |
no test coverage detected