airborne12 commented on code in PR #69292:
URL: https://github.com/apache/doris/pull/69292#discussion_r4333847737


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushDownScoreTopNIntoOlapScan.java:
##########
@@ -98,7 +76,69 @@ public List<Rule> buildRules() {
                             LogicalFilter<LogicalOlapScan> filter = 
project.child();
                             LogicalOlapScan scan = filter.child();
                             return pushDown(topN, project, filter, scan);
-                        
}).toRule(RuleType.PUSH_DOWN_SCORE_TOPN_INTO_OLAP_SCAN));
+                        
}).toRule(RuleType.PUSH_DOWN_SCORE_TOPN_INTO_OLAP_SCAN),
+                
logicalProject(logicalFilter(logicalOlapScan()).when(this::hasScorePredicate))

Review Comment:
   Thanks, this is done in c0036a2fd7 as suggested:
   
   - **Binding is separate from the optimizations.** `CheckScoreUsage` now runs 
first in rewrite, while subqueries, views and CTEs still have their own plan 
nodes. It gives every SELECT that calls `score()` an id and marks with it the 
`score()` calls and the MATCH/SEARCH predicates in the WHERE clause of that 
SELECT. `BindScoreToOlapScan` then adds one hidden score column to the scan 
those predicates filter, replaces the `score()` calls with that slot and 
carries it through the projections in between. `PushDownScoreRangeIntoOlapScan` 
(`score > x` / `score >= x`) and `PushDownScoreTopNIntoOlapScan` are separate, 
optional optimizations; without them the scan scores every row it returns.
   - **No Score-specific exceptions in the generic rules.** They are removed 
from `PushDownFilterThroughJoin`, `PushFilterInsideJoin`, 
`PushDownFilterThroughWindow`, `PushDownFilterThroughSetOperation` and 
`PushDownVirtualColumnsIntoOlapScan`; for them the score is an ordinary column 
now.
   - **Tests.** Your same-SELECT window query is a positive case 
(`window_same_select` in `test_score_filter_usage`, 
`testScoreNextToWindowFunctions` in `CheckScoreUsageTest`). A raw `score()` 
above a windowed subquery is still rejected, now with `score() requires a MATCH 
or SEARCH predicate in the WHERE clause of the same SELECT`.
   



-- 
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]

Reply via email to