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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java:
##########
@@ -610,8 +610,8 @@ public Optional<ResultSet> handleQueryInFe(StatementBase 
parsedStmt) {
         }
 
         if (physicalPlan instanceof PhysicalResultSink
-                && physicalPlan.child(0) instanceof PhysicalHashAggregate && 
!getScanNodes().isEmpty()
-                && getScanNodes().get(0) instanceof IcebergScanNode) {
+                && !getScanNodes().isEmpty() && getScanNodes().get(0) 
instanceof IcebergScanNode
+                && 
getScanNodes().get(0).getPushDownAggNoGroupingOp().equals(TPushAggOp.COUNT)) {

Review Comment:
   This condition is trick because it can only process this shape:
   ```
        PhysicalResultSink
               |
       PhysicalHashAggregate
               |
   PhysicalFileScan(table=IcebergScan)
   ```
   
   If there has another PhysicalPlan between PhysicalHashAggregate and 
PhysicalFileScan, it maybe compute a wrong result
   
   ```
        PhysicalResultSink
               |
       PhysicalHashAggregate
               |
          PhysicalFilter
               |
       PhysicalHashAggregate
               |
   PhysicalFileScan(table=IcebergScan)
   ```
   
   for example:
   
   ```sql
   select max(cnt) from (select count(*) as cnt from iceberg_table having cnt = 
10)a
   ```
   
   
   I think you should remove this code in NereidsPlanner, the correct approach 
is
   1. add `PhysicalCountIcebergTable` plan
   2. add a rule in Rewrite to rewrite 
`LogicalAggregate(LogicalFileScan().when(scan -> scan.getTable instance 
IcebergTable)` to `PhysicalCountIcebergTable`
   3. translate `PhysicalCountIcebergTable` like `PhysicalOneRowRelation`
   5. finally the PhysicalCountIcebergTable can be compute by constant value
   



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