Preserve table expression counting

This commit is contained in:
Dmitry Novik 2024-12-02 10:58:26 +01:00
parent a528b51a97
commit ad5a571d7a
3 changed files with 15 additions and 7 deletions

View File

@ -59,6 +59,12 @@ public:
}
break;
}
case QueryTreeNodeType::ARRAY_JOIN:
{
/// Simulate previous behaviour and preserve table naming with previous versions
++next_id;
break;
}
default:
break;
}
@ -170,18 +176,20 @@ private:
{
if (result.empty())
{
String unique_array_join_name = fmt::format("__array_join_{}", ++next_id);
for (auto & array_join_expression : array_join->getJoinExpressions())
{
auto * array_join_column = array_join_expression->as<ColumnNode>();
chassert(array_join_column != nullptr);
String unique_name = fmt::format("__array_join_exp_{}", ++next_id);
result.emplace(array_join_column->getColumnName(), unique_name);
String unique_expression_name = fmt::format("{}.{}", unique_array_join_name, array_join_column->getColumnName());
result.emplace(array_join_column->getColumnName(), unique_expression_name);
auto replacement_column = array_join_column->getColumn();
replacement_column.name = unique_name;
replacement_column.name = unique_expression_name;
auto replacement_column_node = std::make_shared<ColumnNode>(replacement_column, array_join_column->getExpression(), array_join_column->getColumnSource());
replacement_column_node->setAlias(unique_name);
replacement_column_node->setAlias(unique_expression_name);
array_join_expression = std::move(replacement_column_node);
replaced_nodes_set.insert(array_join_expression);

View File

@ -121,8 +121,8 @@ Filter column: and(notEquals(y, 2), notEquals(x, 0))
ARRAY JOIN x
Filter column: notEquals(y, 2)
> (analyzer) filter is split, one part is filtered before ARRAY JOIN
Filter column: and(notEquals(__table2.y, 2_UInt8), notEquals(__table1.x, 0_UInt8))
ARRAY JOIN __table1.x
Filter column: and(notEquals(__table2.y, 2_UInt8), notEquals(__array_join_1.x, 0_UInt8))
ARRAY JOIN __array_join_1.x
Filter column: notEquals(__table2.y, 2_UInt8)
1 3
> filter is pushed down before Distinct

View File

@ -134,7 +134,7 @@ $CLICKHOUSE_CLIENT --enable_analyzer=1 -q "
explain actions = 1 select x, y from (
select range(number) as x, number + 1 as y from numbers(3)
) array join x where y != 2 and x != 0" |
grep -o "Filter column: and(notEquals(__table2.y, 2_UInt8), notEquals(__table1.x, 0_UInt8))\|ARRAY JOIN __table1.x\|Filter column: notEquals(__table2.y, 2_UInt8)"
grep -o "Filter column: and(notEquals(__table2.y, 2_UInt8), notEquals(__array_join_1.x, 0_UInt8))\|ARRAY JOIN __array_join_1.x\|Filter column: notEquals(__table2.y, 2_UInt8)"
$CLICKHOUSE_CLIENT -q "
select x, y from (
select range(number) as x, number + 1 as y from numbers(3)