iwanttobepowerful commented on code in PR #30459:
URL: https://github.com/apache/doris/pull/30459#discussion_r1469044186


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/SubqueryToApply.java:
##########
@@ -140,6 +140,13 @@ public List<Rule> buildRules() {
                                 .filter(s -> !(s instanceof 
MarkJoinSlotReference))
                                 .collect(ImmutableList.toImmutableList()), 
newFilter);
                     } else {
+                        if (applyPlan instanceof LogicalProject) {

Review Comment:
   ```
   mysql> explain parsed plan with cte1 as(select * from t123) select tm  from 
cte1 group by tm having tm > (select  'Apple');
   
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   | Explain String(Nereids Planner)                                            
                                                                                
                                                           |
   
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   | UnboundResultSink[11] (  )                                                 
                                                                                
                                                           |
   | +--LogicalCTE ( aliasQueries=[LogicalSubQueryAlias ( qualifier=[cte1] )] ) 
                                                                                
                                                           |
   |    |-*LogicalSubQueryAlias ( qualifier=[cte1] )                            
                                                                                
                                                           |
   |    |  +--LogicalProject[8] ( distinct=false, projects=[*], excepts=[] )    
                                                                                
                                                           |
   |    |     +--LogicalCheckPolicy (  )                                        
                                                                                
                                                           |
   |    |        +--UnboundRelation ( id=RelationId#2, nameParts=t123 )         
                                                                                
                                                           |
   |    +--LogicalHaving ( predicates=('tm >  (SCALARSUBQUERY) SubqueryExpr ( 
QueryPlan=LogicalProject[4] ( distinct=false, projects=[UnboundAlias('Apple')], 
excepts=[] ), CorrelatedSlots=[], typeCoercionExpr=null )) ) |
   |       +--LogicalAggregate[2] ( groupByExpr=['tm], outputExpr=['tm], 
hasRepeat=false )                                                               
                                                                  |
   |          +--LogicalCheckPolicy (  )                                        
                                                                                
                                                           |
   |             +--UnboundRelation ( id=RelationId#0, nameParts=cte1 )         
                                                                                
                                                           |
   
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   10 rows in set (0.00 sec)
   
   mysql> explain analyzed plan with cte1 as(select * from t123) select tm  
from cte1 group by tm having tm > (select  'Apple');
   
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   | Explain String(Nereids Planner)                                            
                                                                                
      |
   
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   | LogicalResultSink[43] ( outputExprs=[tm#1] )                               
                                                                                
      |
   | +--LogicalCteAnchor[41] ( cteId=CTEId#0 )                                  
                                                                                
      |
   |    |--LogicalCteProducer[18] ( cteId=CTEId#0 )                             
                                                                                
      |
   |    |  +--LogicalSubQueryAlias ( qualifier=[cte1] )                         
                                                                                
      |
   |    |     +--LogicalProject[16] ( distinct=false, projects=[tm#0], 
excepts=[] )                                                                    
               |
   |    |        +--LogicalOlapScan ( qualified=demo.t123, 
indexName=<index_not_selected>, selectedIndexId=10097, preAgg=ON )              
                           |
   |    +--LogicalProject[40] ( distinct=false, projects=[tm#1], excepts=[] )   
                                                                                
      |
   |       +--LogicalFilter[39] ( predicates=(tm#1 > 'Apple'#3) )               
                                                                                
      |
   |          +--LogicalProject[38] ( distinct=false, projects=[tm#1, 
'Apple'#3], excepts=[] )                                                        
                |
   |             +--LogicalApply ( correlationSlot=[], 
correlationFilter=Optional.empty, isMarkJoin=false, 
isMarkJoinSlotNotNull=false, MarkJoinSlotReference=empty ) |
   |                |--LogicalProject[34] ( distinct=false, projects=[tm#1], 
excepts=[] )                                                                    
         |
   |                |  +--LogicalAggregate[33] ( groupByExpr=[tm#1], 
outputExpr=[tm#1], hasRepeat=false )                                            
                 |
   |                |     +--LogicalProject[32] ( distinct=false, 
projects=[tm#1], excepts=[] )                                                   
                    |
   |                |        +--LogicalCteConsumer[19] ( cteId=CTEId#0, 
relationId=RelationId#0, name=cte1 )                                            
              |
   |                +--LogicalProject[27] ( distinct=false, projects=['Apple' 
AS `'Apple'`#3], excepts=[] )                                                   
        |
   |                   +--LogicalOneRowRelation ( projects=['Apple' AS 
`'Apple'`#2] )                                                                  
               |
   
+------------------------------------------------------------------------------------------------------------------------------------------------------------------+
   16 rows in set (0.00 sec)
   ```



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