my-ship-it commented on code in PR #1398:
URL: https://github.com/apache/cloudberry/pull/1398#discussion_r2447332155
##########
src/backend/gpopt/translate/CTranslatorDXLToPlStmt.cpp:
##########
@@ -7282,4 +7425,75 @@ CTranslatorDXLToPlStmt::IsIndexForOrderBy(
}
return false;
}
+
+//---------------------------------------------------------------------------
+// @function:
+// CTranslatorDXLToPlStmt::ExtractParallelWorkersFromDXL
+//
+// @doc:
+// Extract parallel workers count from DXL node tree recursively.
+// Since parallel degree is uniform across all parallel scans in a
query,
+// returns the first parallel degree found from any
CDXLPhysicalParallelTableScan,
+// or 1 if no parallel scan exists.
+//
+//---------------------------------------------------------------------------
+ULONG
+CTranslatorDXLToPlStmt::ExtractParallelWorkersFromDXL(const CDXLNode *dxlnode)
+{
+ if (nullptr == dxlnode)
+ {
+ return 1;
+ }
+
+ CDXLOperator *dxlop = dxlnode->GetOperator();
+ if (EdxlopPhysicalParallelTableScan == dxlop->GetDXLOperator())
+ {
+ // Return parallel workers from the parallel table scan operator
+ // All parallel scans in the query share the same parallel
degree
+ CDXLPhysicalParallelTableScan *parallel_scan_dxlop =
+ CDXLPhysicalParallelTableScan::Cast(dxlop);
+ return parallel_scan_dxlop->UlParallelWorkers();
+ }
+ else if (EdxlopPhysicalTableScan == dxlop->GetDXLOperator() ||
+ EdxlopPhysicalDynamicTableScan ==
dxlop->GetDXLOperator() ||
+ EdxlopPhysicalIndexScan == dxlop->GetDXLOperator() ||
+ EdxlopPhysicalIndexOnlyScan == dxlop->GetDXLOperator()
||
+ EdxlopPhysicalBitmapTableScan ==
dxlop->GetDXLOperator() ||
+ EdxlopPhysicalDynamicBitmapTableScan ==
dxlop->GetDXLOperator() ||
+ EdxlopPhysicalForeignScan == dxlop->GetDXLOperator() ||
+ EdxlopPhysicalDynamicForeignScan ==
dxlop->GetDXLOperator() ||
+ EdxlopPhysicalDynamicIndexScan ==
dxlop->GetDXLOperator() ||
+ EdxlopPhysicalDynamicIndexOnlyScan ==
dxlop->GetDXLOperator() ||
+ EdxlopPhysicalValuesScan == dxlop->GetDXLOperator())
+ {
+ // Non-parallel scans (table, index, bitmap, foreign, values)
+ // These are leaf nodes in terms of parallel worker extraction
+ // Return 1 to indicate no parallel workers
+ return 1;
+ }
+ else if (EdxlopPhysicalMotionGather == dxlop->GetDXLOperator() ||
+ EdxlopPhysicalMotionBroadcast ==
dxlop->GetDXLOperator() ||
+ EdxlopPhysicalMotionRedistribute ==
dxlop->GetDXLOperator() ||
+ EdxlopPhysicalMotionRandom == dxlop->GetDXLOperator()
||
+ EdxlopPhysicalMotionRoutedDistribute ==
dxlop->GetDXLOperator())
+ {
+ // Motion node creates a slice boundary - do not recurse into
child
+ // The child's parallel workers belong to the sending slice,
not receiving slice
+ // Return 0 to indicate the receiving slice (current slice) has
no parallel workers
+ return 1;
+ }
+
+ // Recursively check child nodes, return early when first parallel scan
is found
+ for (ULONG ul = 0; ul < dxlnode->Arity(); ul++)
+ {
+ ULONG child_parallel_workers =
ExtractParallelWorkersFromDXL((*dxlnode)[ul]);
Review Comment:
For HashJoin, should we return 3 or 6?
```
HashJoin
|─ Motion
|─ Parallel Scan on A (parallel_workers = 3)
|─ Motion
|─ Parallel Scan on B (parallel_workers = 6)
```
--
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]