Repository navigation
perf(plan): reuse eligible multi-reference CTEs - #26295
VioletQwQ-0 wants to merge 4 commits into
Conversation
4c64347 to
aa815b6
Compare
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep-reviewed exact head aa815b6. The materialized Source producer/reader ownership, cancellation, prepared-reuse generation, and spill cleanup paths are otherwise coherent. One P1 semantic blocker remains.
[P1] SAMPLE is treated as deterministic and can be shared (pkg/sql/plan/cte_reuse.go, cteSubtreeIsDeterministic).
The node-type denylist excludes volatile functions but not plan.Node_SAMPLE, whose executor uses random selection. I reproduced this on the exact head with an expensive fixed-width producer:
with c as (
select sample(total, 2 rows) as n from (
select l_suppkey, sum(l_extendedprice) as total
from lineitem group by l_suppkey
) grouped
) select a.n from c a join c b on a.n = b.n;
Before this optimization the plan has two independent SAMPLE nodes. On this head the cost guard wins and rewrites it to one materialized SINK plus two SINK_SCAN consumers. The two independent random samples therefore become the same sample; joins, intersections, aggregates, and returned rows can change.
Please classify Node_SAMPLE as nondeterministic and add this profitable shape to TestCTEMultiReferenceReuseGuards (asserting zero reachable SINK_SCAN). Focused CTE race tests and the materialized/dispatch/merge/compile race packages passed; the full plan race package was killed by the local resource limit, while its focused CTE race suite passed.
|
Superseded by #26331, which is now the canonical PR for #26131. The successor removes the disk-spill experiment, keeps bounded query-MPool materialization, and includes the reviewer-reported profitable SAMPLE SQL as a production planner guard. The guard fails on this reviewed head with two reachable SINK_SCAN nodes and passes on #26331 with zero, preserving independent sampling semantics. Closing this duplicate; the branch is retained. |
What type of PR is this?
Which issue(s) this PR fixes:
issue #26131
What this PR does / why we need it:
Reuse only deterministic, profitable, fixed-width, bounded multi-reference CTEs through one local materialized producer and independent full-drain readers. Unsupported or uncertain shapes remain inline.
The materialized source keeps the first 64 MiB in the query MPool and spills later batches to an anonymous query-scoped local file, so underestimated planner statistics cannot turn a formerly successful inline query into a runtime-limit error. Each reader owns its decoded spill batch until it advances or releases; the final producer/reader release reclaims the shared batches, per-reader batches, and spill file.
The branch is composed onto current
main. Its superseded pipeline-terminal commit was dropped because #26250 now provides the durable terminal-state implementation; only the materialized Dispatch reset branch is composed onto that upstream behavior.Validation on exact head
aa815b68971e29daff1ea86587ec4cac1e7b4eef:MAXconsumer, twoSink Scannodes, expected result, EOF,rows.Err()andClose()checksgit diff --checkPASS review=PASS validation=PENDING, diff hash8cc8631ac675171d883041af41d62493a9a0b52bfbec949dfd3bf99990f1c75cPrior-head CI classification:
copyloopvarwas PR-caused and is fixed on this head.TestCkpLeakwithpanic: ExpectedEOB; this PR's planner tests passed in that run.Performance status: