Repository navigation
fix: the cursor Material's plan node id sits above the subplans' ids (#1306 follow-up) - #1312
Conversation
…ommandprompt#1306 follow-up) set_plan_references numbers the main tree and then the subplans from one counter, so the main tree's largest id is not the largest: a cursor whose query had a subplan got a Material whose id repeated the subplan's first node. Found by @jdatcmd reviewing commandprompt#1306. An assert build now checks every id in the final plan is unique; the arm 'a SCROLL cursor whose query has a subplan fetches backward as the filter's plan does' was red (XX000) on PG16 in both twins before the fix, and is green on PG15-19 after. Ledger 1943 -> 1945, census 1694. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jdatcmd
left a comment
There was a problem hiding this comment.
Approved at 622a749. I reproduced it here, without relying on the PR text:
| build | the fold of stmt->subplans removed |
as pushed |
|---|---|---|
PG18 assert (/usr/local/pg18_assert) |
35 passed, 1 failed: ERROR: XX000 on the subquery cursor |
36/36 + 1 SKIP |
PG17 (/usr/local/pg17) |
35 passed, 1 failed, the same |
The server log says the failure is the new check: pgcolumnar: duplicate plan_node_id after adding a Material above a cursor's plan.
One correction to my own expectation. I ran the PG17 mutant to show that a release build stays green. It doesn't, because /usr/local/pg17 here is configured with --enable-cassert too. So on our dev builds, this check catches the regression on every major. On CI's PGDG release packages, the uniqueness check is compiled out and the check guards only the backward fetches, as your TESTS.md note says. The ledger date is a true observation either way. If a future reader wonders why CI can't redden it, the mutation description could say "(assert builds)", but that's optional.
Checked:
- Both walkers return on a NULL plan, and
PlannedStmt->subplanscan hold NULL entries. - The subplans resolve against the one flattened
stmt->rtable. - The assert-only walk costs nothing in release builds.
I'll merge once CI is green.
|
Merging now: approved at 622a749, 15/15 green. |
…ith the commandprompt#1308 review's arms 27 rows from a five-major run, 21 dated by eleven mutations merged one log at a time with --mutation and --target; the six 'never' rows are premises. Census 1694 -> 1700. TESTS.md section 93; cluster_tests 501 by collection. Docs and CHANGELOG name the MAXVALUE and 1000-partition refusals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The cursor Material's node id sits above the subplans' ids (#1306 follow-up)
@jdatcmd's non-blocking note on #1306.
set_plan_referencesnumbers the main tree first and the subplans after it, from one counter. My hook tookmax(main tree) + 1for the Material, so a cursor whose query had a SubPlan or InitPlan got a Material that repeated the subplan's first node id.plannodes.hsays the ids are unique across the final plan.Fix: the maximum is now taken over
stmt->subplansas well, about a dozen lines inpgcolumnar_planner.Proof, as you suggested, but kept rather than one-off. Under
USE_ASSERT_CHECKING, the hook walks the final plan (the main tree plus every subplan) and raises an ERROR if any id repeats. With that check in place and without the fix, the new arm is red on PG16 assert, in both twins:It's your example shape:
SELECT id, (SELECT max(id) FROM tr) ...underDECLARE c SCROLL CURSOR. A premise requires that the plan holds both a Tid Range Scan and an InitPlan. On a release build (CI's PGDG packages) the uniqueness check is compiled out, so there the arm checks the backward fetches only. The PR says so in TESTS.md.Evidence:
tid_range_scan.sh: 36/36 plus the parallel SKIP on PG15–18, and 38/38 on PG19, after amake cleanbuild for each major.never. Census 1694.🤖 Generated with Claude Code