github-actions[bot] commented on code in PR #66973:
URL: https://github.com/apache/doris/pull/66973#discussion_r4281128219
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckScoreUsage.java:
##########
@@ -98,18 +115,9 @@ private boolean containsScoreFunction(Expression expr) {
}
private boolean isScoreAlreadyOptimized(LogicalProject<?> project) {
- Plan child = project.child();
- if (child instanceof LogicalOlapScan) {
- LogicalOlapScan scan = (LogicalOlapScan) child;
- return scan.getVirtualColumns().stream()
- .anyMatch(virtualCol -> {
- if (virtualCol instanceof Alias) {
- Expression childExpr = ((Alias)
virtualCol).child();
- return containsScoreFunction(childExpr);
- }
- return false;
- });
- }
- return false;
+ return
project.<LogicalOlapScan>collectToList(LogicalOlapScan.class::isInstance).stream()
+ .anyMatch(scan -> scan.getVirtualColumns().stream()
+ .anyMatch(virtualCol -> virtualCol instanceof Alias
+ && containsScoreFunction(((Alias)
virtualCol).child())));
Review Comment:
[P2] Distinguish CSE expressions from materialized score columns
With `experimental_enable_virtual_slot_for_cse=true`, a DUP table query such
as `SELECT score() AS s, abs(score()) AS magnitude FROM dup WHERE content MATCH
'doris' AND abs(score()) > -1` reaches this check without ORDER BY or LIMIT.
The earlier `PushDownVirtualColumnsIntoOlapScan` job extracts the repeated
wrapper, producing this reduced plan inferred from the rules:
```text
Project(score() AS s, v AS magnitude)
Filter(MATCH AND v > -1)
Scan(DUP, virtual=[abs(score()) AS v])
```
There is no TopN, so `PushDownScoreTopNIntoOlapScan` never runs. This helper
nevertheless finds the wrapped Score below the filter and exempts the remaining
raw `score()` from the usage error. The previous direct-child check rejected
this shape. The surviving scalar reaches `function_score.cpp`, which returns
`0.0`, so an invalid scoring query silently returns zero scores. Require actual
score materialization, or reject surviving raw Score expressions, and cover
this CSE-enabled case.
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/CheckScoreUsage.java:
##########
@@ -98,18 +115,9 @@ private boolean containsScoreFunction(Expression expr) {
}
private boolean isScoreAlreadyOptimized(LogicalProject<?> project) {
- Plan child = project.child();
- if (child instanceof LogicalOlapScan) {
- LogicalOlapScan scan = (LogicalOlapScan) child;
- return scan.getVirtualColumns().stream()
- .anyMatch(virtualCol -> {
- if (virtualCol instanceof Alias) {
- Expression childExpr = ((Alias)
virtualCol).child();
- return containsScoreFunction(childExpr);
- }
- return false;
- });
- }
- return false;
+ return
project.<LogicalOlapScan>collectToList(LogicalOlapScan.class::isInstance).stream()
Review Comment:
[P2] Avoid rescanning every project subtree for score-free queries
Both project predicates call this helper even when the projection has no
`score()`. `collectToList` eagerly walks the entire subtree and allocates its
scan list before `anyMatch`, so ordinary queries now perform two full
descendant walks per Project instead of the previous direct-child check. For
example, nested dependent window queries retain this reduced shape:
```text
Window(row_number ORDER BY k2)
Project(k2 := rn2 % 100)
Window(rn2 := row_number ORDER BY k1)
Project(k1 := rn1 % 100)
Window(rn1 := row_number ORDER BY id)
Scan(t)
```
The computed order-key aliases prevent project elimination, and the windows
prevent project merging. Extending this to d layers therefore adds O(d^2)
score-validation work under default settings, despite having no score
expression. Check score-bearing scans once or propagate/cache the relevant
subtree fact instead of collecting descendants twice at every Project.
--
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]