jiaqizho commented on PR #776:
URL: https://github.com/apache/cloudberry/pull/776#issuecomment-2539008062

   The context about this PR: ORCA can create the 3-stage agg in 
`agg(distinct)` path, but prohibit the distribution key in distinct. Because 
ORCA think 2-stage agg is enough.
   
   So u can see the 3-stage agg path but no cost generated in the memo. like 
   ```
   ROOT
   Group 9 (#GExprs: 8):
     0: CLogicalGbAgg( Global ) Grp Cols: [][Global], Minimal Grp Cols: [], 
Generates Duplicates :[ 0 ]  [ 0 8 ]
     1: CLogicalGbAgg( Global ) Grp Cols: [][Global], Minimal Grp Cols: [], 
Generates Duplicates :[ 0 ] , m_aggStage :[  Three Stage Scalar DQA  ]  [ 12 15 
]
     2: CLogicalGbAgg( Global ) Grp Cols: [][Global], Minimal Grp Cols: [], 
Generates Duplicates :[ 0 ] , m_aggStage :[  Two Stage Scalar DQA  ]  [ 16 15 ]
     3: CLogicalGbAgg( Global ) Grp Cols: [][Global], Minimal Grp Cols: [], 
Generates Duplicates :[ 0 ] , m_aggStage :[  Two Stage Scalar DQA  ]  [ 20 25 ]
     4: CPhysicalScalarAgg( Global, multi-stage ) Grp Cols: [], Minimal Grp 
Cols:[], Generates Duplicates :[ 0 ] , m_aggStage :[ Two Stage Scalar DQA ]  [ 
20 25 ]
       Cost Ctxts:
         main ctxt (stage 0)0.1, child ctxts:[0], rows:1.000000 (group), cost: 
484.101386
     5: CPhysicalScalarAgg( Global, multi-stage ) Grp Cols: [], Minimal Grp 
Cols:[], Generates Duplicates :[ 0 ] , m_aggStage :[ Two Stage Scalar DQA ]  [ 
16 15 ]
       Cost Ctxts:
         main ctxt (stage 0)0.1, child ctxts:[0], rows:1.000000 (group), cost: 
679.103561
     6: CPhysicalScalarAgg( Global, multi-stage ) Grp Cols: [], Minimal Grp 
Cols:[], Generates Duplicates :[ 0 ] , m_aggStage :[ Three Stage Scalar DQA ]  
[ 12 15 ]
       Cost Ctxts:
     7: CPhysicalScalarAgg( Global ) Grp Cols: [], Minimal Grp Cols:[], 
Generates Duplicates :[ 0 ]  [ 0 8 ]
       Cost Ctxts:
         main ctxt (stage 0)0.1, child ctxts:[0], rows:1.000000 (group), cost: 
527.493765
     Grp OptCtxts:
       0 (stage 0): (req CTEs: [], req order: [<empty> match: satisfy ], req 
dist: [SINGLETON (master) match: satisfy], req rewind: [], req rewind: [NONE 
NO-MOTION match: satisfy], req partition propagation: [<empty> match: satisfy 
]) => Best Expr:4
   ```
   
   The GroupExpression#6 is the **Three Stage Scalar DQA**.
   
   Details of why this path have no cost:
   1. ORCA will create a `CPhysicalMotionHashDistribute HASHED` 
GroupExpression(Redistribute Motion) below the GroupExpression#6. If current 
physical agg enforce the distribution.
   2. If current required distribution key(hashagg) is same as distribution 
key, then `Redistribute Motion` won't get the cost(in 
CPhysicalMotion::FValidContext)
   3. So the root group(GroupExpression#6) won't be selected.
   
   


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