diff --git a/src/Processors/QueryPlan/CreatingSetsStep.cpp b/src/Processors/QueryPlan/CreatingSetsStep.cpp index f63b657c029..bf2a0aa1929 100644 --- a/src/Processors/QueryPlan/CreatingSetsStep.cpp +++ b/src/Processors/QueryPlan/CreatingSetsStep.cpp @@ -121,6 +121,9 @@ void addCreatingSetsStep( for (auto & [description, set] : subqueries_for_sets) { + if (!set.source) + continue; + auto plan = std::move(set.source); std::string type = (set.join != nullptr) ? "JOIN" : "subquery"; @@ -139,6 +142,12 @@ void addCreatingSetsStep( plans.emplace_back(std::move(plan)); } + if (plans.size() == 1) + { + query_plan = std::move(*plans.front()); + return; + } + auto creating_sets = std::make_unique(std::move(input_streams)); creating_sets->setStepDescription("Create sets before main query execution"); query_plan.unitePlans(std::move(creating_sets), std::move(plans));