Alena0704 opened a new pull request, #1719:
URL: https://github.com/apache/cloudberry/pull/1719

   ### What does this PR do?
   
   Fixes a query hang in ORCA when a CTE over a replicated table is referenced
   from a different executor slice than its Producer (e.g. from a scalar
   subquery, or via duplicate-hazard motion in a JOIN).
   
   Before Expr→DXL translation, the patch walks the physical tree and tracks
   which slice each CTE Producer and Consumer lives on (slices are delimited
   by Motion nodes). If any Consumer is on a different slice than its Producer
   *and* the Producer's distribution is replicated-like
   (StrictReplicated / TaintedReplicated / Universal), ORCA raises an
   unsupported-feature exception and falls back to the Postgres planner.
   
   The replicated filter is essential: ordinary cross-slice CTE plans
   (non-replicated Producer with Gather/Redistribute Consumer) are a normal
   ORCA pattern and must not trigger fallback.
   
   Inspired by greengage 51fe92e, but extends it: 51fe92e's single-point check
   doesn't trigger when a CTE over a replicated table is referenced from a
   scalar subquery, so the query hangs. This PR replaces it with a whole-tree
   walker that catches both cases.
   
   ### Type of Change
   - [x] Bug fix (non-breaking change)
   - [ ] New feature (non-breaking change)
   - [ ] Breaking change (fix or feature with breaking changes)
   - [ ] Documentation update
   
   ### Breaking Changes
   None.
   
   ### Test Plan
   - [x] Unit tests added/updated
   - [x] Integration tests added/updated
   - [ ] Passed `make installcheck`
   - [ ] Passed `make -C src/test installcheck-cbdb-parallel`
   
   Two regression cases added:
   - `qp_orca_fallback`: original 51fe92e reproducer — JOIN over a CTE
     referencing replicated tables with duplicate-hazard motion.
   - `shared_scan`: scalar-subquery reproducer where a CTE over a replicated
     table is referenced from multiple `(SELECT … FROM cte)` expressions.
     Guarded by `statement_timeout = '15s'` so the test fails fast if the
     hang regresses (40k rows in the driving table are needed to push ORCA
     to the cross-slice plan — fewer rows would make the test silently pass
     without the fix).
   
   ### Impact
   **Performance:** Negligible. The added walker runs once per query, only
   over the physical tree, and only when CTE Producers/Consumers are present.
   The set of queries that newly fall back to the Postgres planner is narrow
   (replicated CTE Producer with a cross-slice Consumer) — these queries
   previously hung, so any plan is an improvement.
   
   **User-facing changes:** Queries matching the pattern above now complete
   instead of hanging. Users will see
   `INFO: GPORCA failed to produce a plan, falling back to planner` /
   `DETAIL: Feature not supported: CTE Consumer placed on a different slice
   than its replicated Producer` in those cases.
   
   **Dependencies:** None.
   
   ### Checklist
   - [x] Followed [contribution 
guide](https://cloudberry.apache.org/contribute/code)
   - [ ] Added/updated documentation
   - [x] Reviewed code for security implications
   - [ ] Requested review from cloudberry committers
   
   ### Additional Context
   Cherry-picked from open-gpdb/gpdb#375 (commit
   `3a9aebfe3afb27dd060c16b5cfa7932e7a2ed43f`).
   
   Files changed:
   - `src/backend/gporca/libgpopt/include/gpopt/base/CUtils.h`
   - `src/backend/gporca/libgpopt/src/base/CUtils.cpp`
   - `src/backend/gporca/libgpopt/src/translate/CTranslatorExprToDXL.cpp`
   - `src/test/regress/{sql,expected}/qp_orca_fallback{,.out,_optimizer.out}`
   - `src/test/regress/{sql,expected}/shared_scan{,.out,_optimizer.out}`
   


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