Fix constant result for prewhere optimization.

This commit is contained in:
Nikolai Kochetov 2024-10-16 19:33:23 +00:00
parent 2b73641837
commit ca237ee3c4
2 changed files with 17 additions and 4 deletions

View File

@ -152,10 +152,7 @@ addNewFilterStepOrThrow(QueryPlan::Node * parent_node, QueryPlan::Nodes & nodes,
node.step = std::make_unique<FilterStep>(
node.children.at(0)->step->getOutputHeader(), std::move(split_filter), std::move(split_filter_column_name), can_remove_filter);
if (auto * join = typeid_cast<JoinStep *>(child.get()))
join->updateInputHeader(node.step->getOutputHeader(), child_idx);
else
child->updateInputHeader(node.step->getOutputHeader());
child->updateInputHeader(node.step->getOutputHeader(), child_idx);
if (update_parent_filter)
{

View File

@ -194,6 +194,22 @@ void optimizePrewhere(Stack & stack, QueryPlan::Nodes &)
}
else
{
if (!filter_step->removesFilterColumn())
{
const auto * node = split_result.second.tryFindInOutputs(filter_step->getFilterColumnName());
if (node && !node->column)
{
ColumnWithTypeAndName column;
column.type = node->result_type;
column.name = node->result_name;
column.column = column.type->createColumnConst(0, 1u);
const auto * replaced_const = &split_result.second.addColumn(column);
for (auto & output : split_result.second.getOutputs())
if (output == node)
output = replaced_const;
}
}
/// Have to keep this expression to change column names to column identifiers
filter_node->step = std::make_unique<ExpressionStep>(
source_step_with_filter->getOutputHeader(),