github-actions[bot] commented on code in PR #68503:
URL: https://github.com/apache/doris/pull/68503#discussion_r4269784939
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/ReplaceExpressionByChildOutput.java:
##########
@@ -72,7 +72,13 @@ private Map<Expression, Slot>
buildOutputAliasMap(List<NamedExpression> output)
for (NamedExpression expr : output) {
if (expr instanceof Alias) {
Alias alias = (Alias) expr;
- sMap.put(alias.child(), alias.toSlot());
+ // replacing a constant sub-expression anywhere it
structurally recurs, e.g. inside
+ // a function argument that must fold to a literal (NTILE's
bucket, LAG/LEAD's offset),
+ // gives no benefit since a constant is folded once anyway,
and can only break such a
+ // position wherever the constant happens to also be an
unrelated output value.
+ if (!alias.child().isConstant()) {
Review Comment:
[P2] Preserve alias reuse for constants that remain runtime expressions
`isConstant()` does not guarantee the expression is folded. On a nonempty
ordinary table `t(k INT)`, consider `SELECT sleep(1) AS s, k, rand() AS r FROM
t ORDER BY CAST(sleep(1) AS INT) + k, r + r`. Previously
`replaceSortExpression` reused `s#` for the nested `sleep(1)`. This filter
removes that entry, and `NormalizeSort` produces this reduced subtree inferred
from the rewrite:
```text
Project(s#, k#, r#, CAST(sleep(1) AS INT) + k# AS key#, r# + r# AS rr#)
Project(sleep(1) AS s#, k#, rand() AS r#)
Scan(t)
```
FE has no SLEEP evaluator and `FoldConstantRuleOnBE` explicitly skips it.
The repeated `r#` prevents project merging, and `CommonSubExpressionOpt` only
shares expressions within each project; translation preserves the separate
projections. `FunctionSleep` disables constant caching and sleeps for every
input row, so this adds another one-second sleep per input row, doubling the
SLEEP work and potentially causing previously successful queries to time out.
Please retain reuse for runtime constants in ordinary sort keys while
preserving constant-required window arguments, and add coverage for this case.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]