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


##########
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:
   [P2] Bind projected score references independently of TopN and scan adjacency
   
   A minimum-score query with a window in the same SELECT appears to be 
rejected even though its scoring context is unambiguous:
   ```sql
   SELECT id, score() AS s, row_number() OVER (ORDER BY id) AS rn
   FROM test_score_filter_usage
   WHERE c1 MATCH 'apple' AND score() > 0.00001;
   ```
   `ExtractAndNormalizeWindowExpression.collectExpressionsToBePushedDown` 
collects only input slots for an ordinary alias. Since `score()` has none, 
`score() AS s` remains in a Project above Window, while the score filter stays 
below Window. These new patterns bind projected score calls only in 
`Project(Filter(OlapScan))`; the upper Project still contains raw Score, so 
`CheckScoreUsage` rejects it because its child is Window. This is a 
source-level trace, not a runtime reproduction. Unlike the existing 
outer-window-filter threads, the WHERE predicate here correctly runs before 
window evaluation; the issue is propagating the already-defined score value to 
the output.
   
   Could we separate mandatory score binding from optional TopN optimization? 
Once the MATCH/SEARCH scan context is established, bind its score references to 
one hidden scan slot and carry that slot through the plan. Then keep threshold 
pushdown and TopN eligibility as separate decisions. This would also reduce the 
need for Score-specific exceptions in generic join/window/set-operation rules. 
Please add this same-SELECT window case as a positive test while retaining 
rejection of unsupported raw score calls above windowed results.



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