mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
more fizes
This commit is contained in:
parent
ce40d84eef
commit
440e57769a
@ -15,28 +15,12 @@ namespace ErrorCodes
|
|||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
void swapSortingAndUnneededCalculations(DB::QueryPlan::Node * parent_node, DB::ActionsDAGPtr && unneeded_for_sorting)
|
const DB::DataStream & getChildOutputStream(DB::QueryPlan::Node & node)
|
||||||
{
|
{
|
||||||
DB::QueryPlan::Node * child_node = parent_node->children.front();
|
if (node.children.size() != 1)
|
||||||
|
throw DB::Exception(
|
||||||
auto & parent_step = parent_node->step;
|
DB::ErrorCodes::LOGICAL_ERROR, "Node \"{}\" is expected to have only one child.", node.step->getStepDescription());
|
||||||
auto & child_step = child_node->step;
|
return node.children.front()->step->getOutputStream();
|
||||||
auto * sorting_step = typeid_cast<DB::SortingStep *>(parent_step.get());
|
|
||||||
|
|
||||||
// Sorting -> Expression
|
|
||||||
std::swap(parent_step, child_step);
|
|
||||||
// Expression -> Sorting
|
|
||||||
|
|
||||||
if (child_node->children.size() != 1)
|
|
||||||
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "SortingStep is expected to have only one input stream.");
|
|
||||||
sorting_step->updateInputStream(child_node->children.front()->step->getOutputStream());
|
|
||||||
auto input_header = sorting_step->getInputStreams().front().header;
|
|
||||||
sorting_step->updateOutputStream(std::move(input_header));
|
|
||||||
|
|
||||||
auto description = parent_node->step->getStepDescription();
|
|
||||||
parent_step = std::make_unique<DB::ExpressionStep>(child_step->getOutputStream(), std::move(unneeded_for_sorting));
|
|
||||||
parent_step->setStepDescription(description + " [lifted up part]");
|
|
||||||
// UnneededCalculations -> Sorting
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -68,20 +52,26 @@ size_t tryExecuteFunctionsAfterSorting(QueryPlan::Node * parent_node, QueryPlan:
|
|||||||
if (unneeded_for_sorting->trivial())
|
if (unneeded_for_sorting->trivial())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (child_node->children.size() != 1)
|
|
||||||
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "ExpressionStep is expected to have only one input stream.");
|
|
||||||
|
|
||||||
// Sorting (parent_node) -> Expression (child_node)
|
// Sorting (parent_node) -> Expression (child_node)
|
||||||
auto & node_with_needed = nodes.emplace_back();
|
auto & node_with_needed = nodes.emplace_back();
|
||||||
std::swap(node_with_needed.children, child_node->children);
|
std::swap(node_with_needed.children, child_node->children);
|
||||||
child_node->children = {&node_with_needed};
|
child_node->children = {&node_with_needed};
|
||||||
node_with_needed.step
|
|
||||||
= std::make_unique<ExpressionStep>(node_with_needed.children.front()->step->getOutputStream(), std::move(needed_for_sorting));
|
|
||||||
node_with_needed.step->setStepDescription(child_step->getStepDescription());
|
|
||||||
|
|
||||||
|
node_with_needed.step = std::make_unique<ExpressionStep>(getChildOutputStream(node_with_needed), std::move(needed_for_sorting));
|
||||||
|
node_with_needed.step->setStepDescription(child_step->getStepDescription());
|
||||||
// Sorting (parent_node) -> so far the origin Expression (child_node) -> NeededCalculations (node_with_needed)
|
// Sorting (parent_node) -> so far the origin Expression (child_node) -> NeededCalculations (node_with_needed)
|
||||||
swapSortingAndUnneededCalculations(parent_node, std::move(unneeded_for_sorting));
|
|
||||||
// UneededCalculations (child_node) -> Sorting (parent_node) -> NeededCalculations (node_with_needed)
|
std::swap(parent_step, child_step);
|
||||||
|
// so far the origin Expression (parent_node) -> Sorting (child_node) -> NeededCalculations (node_with_needed)
|
||||||
|
|
||||||
|
sorting_step->updateInputStream(getChildOutputStream(*child_node));
|
||||||
|
auto input_header = sorting_step->getInputStreams().at(0).header;
|
||||||
|
sorting_step->updateOutputStream(std::move(input_header));
|
||||||
|
|
||||||
|
auto description = parent_step->getStepDescription();
|
||||||
|
parent_step = std::make_unique<DB::ExpressionStep>(child_step->getOutputStream(), std::move(unneeded_for_sorting));
|
||||||
|
parent_step->setStepDescription(description + " [lifted up part]");
|
||||||
|
// UneededCalculations (parent_node) -> Sorting (child_node) -> NeededCalculations (node_with_needed)
|
||||||
|
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ void SortingStep::updateInputStream(DataStream input_stream)
|
|||||||
|
|
||||||
void SortingStep::updateOutputStream(Block result_header)
|
void SortingStep::updateOutputStream(Block result_header)
|
||||||
{
|
{
|
||||||
output_stream = createOutputStream(input_streams.front(), std::move(result_header), getDataStreamTraits());
|
output_stream = createOutputStream(input_streams.at(0), std::move(result_header), getDataStreamTraits());
|
||||||
updateDistinctColumns(output_stream->header, output_stream->distinct_columns);
|
updateDistinctColumns(output_stream->header, output_stream->distinct_columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user