-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix](nereids) fix NormalizeRepeat, change the outputExpression rewrite logic #34196
Conversation
Thank you for your contribution to Apache Doris. Since 2024-03-18, the Document has been moved to doris-website. |
run buildall |
TPC-H: Total hot run time: 41172 ms
|
run buildall |
TPC-H: Total hot run time: 41828 ms
|
TPC-DS: Total hot run time: 186321 ms
|
9cef386
to
ffabae2
Compare
run buildall |
TPC-H: Total hot run time: 41947 ms
|
TPC-DS: Total hot run time: 188715 ms
|
run buildall |
TPC-H: Total hot run time: 40778 ms
|
TPC-DS: Total hot run time: 187086 ms
|
run external |
run cloud_p1 |
run buildall |
TPC-H: Total hot run time: 40729 ms
|
TPC-DS: Total hot run time: 185318 ms
|
PR approved by at least one committer and no changes requested. |
PR approved by anyone and no changes requested. |
// rewrite the arguments of grouping scalar function to slots | ||
// rewrite grouping scalar function to virtual slots | ||
// rewrite the arguments of agg function to slots | ||
List<NamedExpression> normalizedAggOutput = repeat.getOutputExpressions().stream() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we replace all stream api by for loop?
run buildall |
TPC-H: Total hot run time: 40878 ms
|
TPC-DS: Total hot run time: 185654 ms
|
run p0 |
run cloud_p1 |
…calar function with bottom projects
…with needToSlots in repeat outputExpressions
… the agg arguments and grouping scalar function
4f81946
to
9ae14b1
Compare
run buildall |
PR approved by at least one committer and no changes requested. |
…te logic (#34196) In NormalizeRepeat, three parts of the outputExpression of LogicalRepeat need to be pushed down and outputted by bottom project: flattenGroupingSetExpr, argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction. In the original code, use these three parts to rewrite the outputExpressions of LogicalRepeat to slots.This can cause problems in some cases, for example: ```sql SELECT ROUND( SUM(pk + 1) - 3) col_alias1, pk + 1 AS col_alias3 FROM table_20_undef_partitions2_keys3_properties4_distributed_by53 GROUP BY GROUPING SETS ((pk), ()) ; ``` The three parts expression needed to be pushed down are: pk, pk+1. The original code use pk+1 to rewrite the pk + 1 AS col_alias3 to slot. But the pk+1 is not in the list of grouping outputs, and then report error. This pr change the rewrite process, divide the expression needed to be pushed down into 2 parts: one is (flattenGroupingSetExpr) and the other one is (argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction). and use the flattenGroupingSetExpr rewrite all LogicalRepeat outputExpressions, and use the argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction to rewrite only the agg function arguments and the grouping scalar function. So, in the above sql, the pk + 1 AS col_alias3 will not be rewritten to slot, and can be computed.
…te logic (apache#34196) In NormalizeRepeat, three parts of the outputExpression of LogicalRepeat need to be pushed down and outputted by bottom project: flattenGroupingSetExpr, argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction. In the original code, use these three parts to rewrite the outputExpressions of LogicalRepeat to slots.This can cause problems in some cases, for example: ```sql SELECT ROUND( SUM(pk + 1) - 3) col_alias1, pk + 1 AS col_alias3 FROM table_20_undef_partitions2_keys3_properties4_distributed_by53 GROUP BY GROUPING SETS ((pk), ()) ; ``` The three parts expression needed to be pushed down are: pk, pk+1. The original code use pk+1 to rewrite the pk + 1 AS col_alias3 to slot. But the pk+1 is not in the list of grouping outputs, and then report error. This pr change the rewrite process, divide the expression needed to be pushed down into 2 parts: one is (flattenGroupingSetExpr) and the other one is (argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction). and use the flattenGroupingSetExpr rewrite all LogicalRepeat outputExpressions, and use the argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction to rewrite only the agg function arguments and the grouping scalar function. So, in the above sql, the pk + 1 AS col_alias3 will not be rewritten to slot, and can be computed.
Induced by #34196. In NormalizeRepeat, when NormalizeToSlot is called, aggregate function parameters, grouping scalar function parameters, and all expressions in grouping sets (including columns and column aliases) are pushed down to the lower-level project output. In the previous PR #34196, the context was split into two, but the two contexts were not consistent. It is possible that the triplets in one context save (id, c1, id as c1), and the triplets in the other context save (id, id, id). This causes id as c1 to be pushed down, but there is a reference to id in the upper-level LogicalRepeat, which causes the slot to be not found. This pr has been modified. If the same slot in the projection column has different aliases, for example, select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id)); then id as c1 (using the first alias) will be pushed down to the project. In both the LogicalRepeat operator and the LogicalAggregate operator, c1 is referenced as the input slot, and id and c3 will not be used as input slots. before NormalizeRepeat: LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] ) +--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`#3, id#0, id#0 AS `c3`#4, Grouping(id#0) AS `Grouping(id)`#5] ) +--LogicalOlapScan (qualified=table1) After NormalizeRepeat: LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5]) +--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`#5], hasRepeat=true ) +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] ) +--LogicalProject[28] (projects=[id#0 AS `c1`#3, value2#2]) +--LogicalOlapScan (qualified=table1)
Induced by apache#34196. In NormalizeRepeat, when NormalizeToSlot is called, aggregate function parameters, grouping scalar function parameters, and all expressions in grouping sets (including columns and column aliases) are pushed down to the lower-level project output. In the previous PR apache#34196, the context was split into two, but the two contexts were not consistent. It is possible that the triplets in one context save (id, c1, id as c1), and the triplets in the other context save (id, id, id). This causes id as c1 to be pushed down, but there is a reference to id in the upper-level LogicalRepeat, which causes the slot to be not found. This pr has been modified. If the same slot in the projection column has different aliases, for example, select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id)); then id as c1 (using the first alias) will be pushed down to the project. In both the LogicalRepeat operator and the LogicalAggregate operator, c1 is referenced as the input slot, and id and c3 will not be used as input slots. before NormalizeRepeat: LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] ) +--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`apache#3, id#0, id#0 AS `c3`apache#4, Grouping(id#0) AS `Grouping(id)`apache#5] ) +--LogicalOlapScan (qualified=table1) After NormalizeRepeat: LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5]) +--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`apache#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`apache#5], hasRepeat=true ) +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] ) +--LogicalProject[28] (projects=[id#0 AS `c1`apache#3, value2#2]) +--LogicalOlapScan (qualified=table1)
Induced by apache#34196. In NormalizeRepeat, when NormalizeToSlot is called, aggregate function parameters, grouping scalar function parameters, and all expressions in grouping sets (including columns and column aliases) are pushed down to the lower-level project output. In the previous PR apache#34196, the context was split into two, but the two contexts were not consistent. It is possible that the triplets in one context save (id, c1, id as c1), and the triplets in the other context save (id, id, id). This causes id as c1 to be pushed down, but there is a reference to id in the upper-level LogicalRepeat, which causes the slot to be not found. This pr has been modified. If the same slot in the projection column has different aliases, for example, select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id)); then id as c1 (using the first alias) will be pushed down to the project. In both the LogicalRepeat operator and the LogicalAggregate operator, c1 is referenced as the input slot, and id and c3 will not be used as input slots. before NormalizeRepeat: LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] ) +--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`apache#3, id#0, id#0 AS `c3`apache#4, Grouping(id#0) AS `Grouping(id)`apache#5] ) +--LogicalOlapScan (qualified=table1) After NormalizeRepeat: LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5]) +--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`apache#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`apache#5], hasRepeat=true ) +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] ) +--LogicalProject[28] (projects=[id#0 AS `c1`apache#3, value2#2]) +--LogicalOlapScan (qualified=table1)
Induced by #34196. In NormalizeRepeat, when NormalizeToSlot is called, aggregate function parameters, grouping scalar function parameters, and all expressions in grouping sets (including columns and column aliases) are pushed down to the lower-level project output. In the previous PR #34196, the context was split into two, but the two contexts were not consistent. It is possible that the triplets in one context save (id, c1, id as c1), and the triplets in the other context save (id, id, id). This causes id as c1 to be pushed down, but there is a reference to id in the upper-level LogicalRepeat, which causes the slot to be not found. This pr has been modified. If the same slot in the projection column has different aliases, for example, select id as c1, id, id as c3, grouping(id) from table1 group by grouping sets((id, value2),(id)); then id as c1 (using the first alias) will be pushed down to the project. In both the LogicalRepeat operator and the LogicalAggregate operator, c1 is referenced as the input slot, and id and c3 will not be used as input slots. before NormalizeRepeat: LogicalResultSink[32] ( outputExprs=[c1#3, id#0, c3#4, __grouping_3#5] ) +--LogicalRepeat ( groupingSets=[[id#0, value2#2], [id#0]], outputExpressions=[id#0 AS `c1`#3, id#0, id#0 AS `c3`#4, Grouping(id#0) AS `Grouping(id)`#5] ) +--LogicalOlapScan (qualified=table1) After NormalizeRepeat: LogicalResultSink[33] (outputExprs=[c1#3, id#0, c3#4, __grouping_3#5]) +--LogicalAggregate[30] (groupByExpr=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)], outputExpr=[c1#3, c1#3 AS `id`#0, c1#3 AS `c3`#4, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3) AS `GROUPING_PREFIX_c1`#5], hasRepeat=true ) +--LogicalRepeat (groupingSets=[[c1#3, value2#2], [c1#3]], outputExpressions=[c1#3, value2#2, GROUPING_ID#7, GROUPING_PREFIX_c1#6 originExpression=Grouping(c1#3)] ) +--LogicalProject[28] (projects=[id#0 AS `c1`#3, value2#2]) +--LogicalOlapScan (qualified=table1)
In NormalizeRepeat, three parts of the outputExpression of LogicalRepeat need to be pushed down and outputted by bottom project: flattenGroupingSetExpr, argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction.
In the original code, use these three parts to rewrite the outputExpressions of LogicalRepeat to slots.This can cause problems in some cases, for example:
The three parts expression needed to be pushed down are: pk, pk+1. The original code use pk+1 to rewrite the pk + 1 AS col_alias3 to slot. But the pk+1 is not in the list of grouping outputs, and then report error.
This pr change the rewrite process, divide the expression needed to be pushed down into 2 parts: one is (flattenGroupingSetExpr) and the other one is (argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction).
and use the flattenGroupingSetExpr rewrite all LogicalRepeat outputExpressions, and use the argumentsOfGroupingScalarFunction, argumentsOfAggregateFunction to rewrite only the agg function arguments and the grouping scalar function.
So, in the above sql, the pk + 1 AS col_alias3 will not be rewritten to slot, and can be computed.