Skip to content

fix(plan): preserve join pushdown for independent CTE consumers - #29793

Merged
mergify[bot] merged 2 commits into
matrixorigin:mainfrom
ck89119:issue-29783-main
Oct 9, 2026
Merged

mergify[bot] merged 2 commits into
matrixorigin:mainfrom
ck89119:issue-29783-main

Conversation

@ck89119

@ck89119 ck89119 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #29783

What this PR does / why we need it:

Root cause

bindWhere treated any subquery containing a CTE as requiring an outer demand domain. For independent CTE consumers such as TPC-H Q15, this installed a FilterIsBarrier above the supplier/revenue join and prevented the supplier equality from becoming a join condition. The shared CTE producer was still reused, but the join produced a Cartesian product before filtering.

Changes

  • Share the existing parameterization dependency proof between demand-barrier admission and parameterizeLocalCTEs.
  • Preserve ordinary predicate pushdown for independent CTEs and predicate-only correlations, while retaining the existing protection for parameterized projections and recursive SourceStep dependencies.
  • Extend the existing Q15 plan test and add eight focused barrier-admission scenarios.
  • Add a small SQL regression covering comma/explicit joins, tied maxima, predicate-only correlation, all-NULL aggregates, and empty input.

Local reproduction

Using the repository's Q15 SQL on macOS arm64, with 10,000 suppliers and 20,000 lineitems:

Observation Before After
Supplier INNER JOIN output rows 100,000,000 10,000
Mean elapsed time, three measured runs after warmup 14.237 s 0.033 s

The query results were identical. These measurements were collected before the latest-main merge, against d7621ea017 and this fix. They include local client/connection overhead and are reduced-data local observations, not a reproduction of the original TKE Family 10G/100G benchmark.

The final regression assertions also fail against the unfixed production sources: Q15 loses its supplier join predicate, and independent CTE scenarios incorrectly acquire a barrier.

Validation

Re-run at 21151a902b, after merging mo/main (d2a0055ebe), using Go 1.27.1 and repository CGo tooling:

  • Focused Q15 and local/correlated CTE unit tests.
  • Full pkg/sql/plan tests: 84.1% package statement coverage; 16/16 changed statements covered (100%).
  • TestTPCHNumericEligibilityInventory in pkg/sql/plan/substrait (Q1–Q22).
  • Fresh service build, Q15 execution/EXPLAIN ANALYZE, and repeated result checks.
  • New BVT twice on the same instance, with explicit teardown checks; entire CTE directory: 296/296 statements passed, including 268 existing correlated-CTE statements.
  • gofmt, incremental go vet, and CI-version golangci-lint 2.14.0.

The .result was generated with mo-tester on the unfixed service, manually checked against the expected rows, and then verified in comparison mode on the fixed service.

Remaining external validation: the original TKE Family concurrent topology and full TPCH 10G/100G workloads have not been re-run locally.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deep review of 21151a9 against d2a0055: APPROVE. All six changed files reviewed; no blocking findings.

Design/ownership: this is a focused planner regression fix. Barrier admission now consumes the same existing CTE parameterization predicate as the lowering path. This removes the inconsistent second decision without adding state or another execution path. The Q15 producer remains shared; independent consumers regain the supplier join predicate instead of filtering a Cartesian join. Predicate-only decorrelation remains owned by the existing decorrelator.

Adversarial closure: traced independent/nested and predicate-only CTEs against projected outer references and recursive SourceStep dependencies, including reversed WHERE conjuncts, conditional/throwing expressions, and unsafe-domain rejection. bindWhere binds the complete predicate set before selecting the domain, so protection does not depend on conjunct order. Parameterization admission, atomic rejection, and guarded-expression checks remain intact. Followed FilterIsBarrier through predicate pushdown to the actual join condition.

Validation: reviewer ran the Q15 reuse/join test, eight barrier-admission cases, existing executable correlated-CTE cases (including reversed predicates), and unsafe-domain rejection cases on this exact head: PASS, 3.132s, Go 1.27.1/macOS arm64 with repository-built native libraries. Reused the explicitly revisioned author evidence for full planner tests, Q1-Q22 inventory, real SQL/EXPLAIN ANALYZE, same-instance BVT rerun/teardown and 296/296 CTE statements. Latest ALL CI run37939091647 is completed/success on this exact SHA; superseded cancelled checks were not treated as current failures.

Incremental quality: implementation +28/-15 across two files; tests +165 across four files; no documentation delta. Existing Q15 fixture is extended rather than duplicated. The SQL regression independently checks tied maxima, NULL/empty input and both join forms; the existing negative correlated suite supplies the adjacent unhappy-path controls.

Performance: extra graph inspection/allocation is confined to planning CTE subqueries; ordinary non-CTE and already executing TP paths gain no per-row work. Avoiding the demonstrated Q15 Cartesian join is a concrete benefit. The reduced local 14.237s -> 0.033s result is not a production/TKE or general TP throughput claim; the original full TKE workload remains external validation.

Comment audit: there were no earlier substantive inline/review findings on this PR. Issue #29783's causal boundary is addressed; original-topology performance validation is still explicitly distinguished from the local regression proof.

@mergify mergify Bot added the queued label Oct 9, 2026
@mergify

mergify Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-09 15:29 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks skipped · PR is already up-to-date
  • ✅ Merged — 2026-10-09 15:29 UTC · at dfd77560340d5c46b0c8c2cdc50d0a13133daa32 · squash

This pull request spent 13 seconds in the queue, including 1 second running CI.

Required conditions to merge

@mergify
mergify Bot merged commit dfd7756 into matrixorigin:main Oct 9, 2026
@mergify mergify Bot removed the queued label Oct 9, 2026

This branch was previously deployed

1 inactive deployment
ci — 21151a90 Deployed Oct 9, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: TKE Weekly AP TPCH 10G step jumps from 3m11s to 2h55m on main 83d82b8

3 participants