Repository navigation
fix: maintain indexes for REPLACE foreign key actions - #27062
Conversation
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? |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed at 0f7194d. The recursive FK paths now retain a stable source layout through hidden-index delete and pre-insert maintenance, with coordinator wait-cycle closure where required. Focused planner tests and all four new multi-CN issue regressions pass.
XuPeng-SH
left a comment
There was a problem hiding this comment.
P1: close the indexed mixed-action row-domain/projection path before merging.
At exact head 0f7194dc3bc2f74723a2e37e12ab3c7734ada29a, a child table with both indexed ON DELETE SET NULL and indexed ON DELETE CASCADE still makes REPLACE fail with an internal runtime panic. This reproduces with only ordinary secondary indexes (no UNIQUE index is required):
create table p(id int primary key);
create table c(
id int primary key, set_id int, cascade_id int, marker int,
key sk_set(set_id), key sk_cascade(cascade_id),
foreign key(set_id) references p(id) on delete set null,
foreign key(cascade_id) references p(id) on delete cascade
);
insert into p values(1),(2);
insert into c values
(10,1,2,10), -- SET NULL only
(20,2,1,20), -- CASCADE only
(30,1,1,30), -- both actions; CASCADE owns it
(40,2,2,40); -- unaffected
replace into p values(1);The final statement deterministically returns error 20101 with a nil dereference in hashjoin.(*container).appendOneNotMatch -> Vector.UnionNull. The hash join's outer-row path has an output/result slot without a valid vector, showing that the mixed SET NULL/CASCADE action graph still reaches execution with an incomplete relation/projection layout.
Expected: row 10 remains with set_id IS NULL; rows 20 and 30 are deleted; row 40 and both secondary indexes remain valid. Actual: the statement aborts with an internal panic.
The full pkg/sql/plan suite, build, vet, and current CI pass, so this action-composition edge is not covered. Please make the SET NULL and CASCADE branches share an explicit, fully remapped ownership/output contract, and add a regression covering SET-only, CASCADE-only, overlap, and unaffected rows (including index-forced validation; prepared execution should use the same matrix).
aptend
left a comment
There was a problem hiding this comment.
Deep review of exact head 0f7194d. I inspected the full diff and all existing review history, then ran the full pkg/sql/plan suite, the four checked-in issue_26875 cluster regressions, focused planner tests, build, vet, and diff-check. Those pass, but an independently reproduced mixed-action path still panics at runtime, so this head is not safe to merge.
XuPeng-SH
left a comment
There was a problem hiding this comment.
P1: close the combined SET NULL + CASCADE stream-isolation path before merging.
At exact head 9e59df41b569cbaabd4b16eb67106e5f1f8b2651, the new single-SET-NULL regression passes, but the adjacent supported case with two indexed ON DELETE SET NULL FKs plus one indexed ON DELETE CASCADE FK still aborts REPLACE with an internal panic.
Minimal shape:
create table p(id int primary key);
create table c(
id int primary key, set_a int, set_b int, cascade_id int,
key sk_a(set_a), key sk_b(set_b), key sk_c(cascade_id),
foreign key(set_a) references p(id) on delete set null,
foreign key(set_b) references p(id) on delete set null,
foreign key(cascade_id) references p(id) on delete cascade
);
insert into p values(1),(2);
insert into c values
(10,1,2,2),(11,2,1,2),(20,2,2,1),(30,1,1,1),(40,2,2,2);
replace into p values(1);Actual: error 20101, index out of range [4] with length 4 in colexec.(*ColumnExpressionExecutor).Eval, reached from projection/hashjoin. Expected: rows 10/11 survive with the matching SET NULL applied, rows 20/30 are deleted by CASCADE, and row 40 plus all secondary indexes remain valid.
The combined-SET-NULL branch builds its anti-joined update stream but does not mark it pending for the later CASCADE branch, so builder.deleteNode can still merge the disjoint action sources and narrow the projection ABI. Please establish the same isolation invariant for every SET NULL producer, including the combined branch, and add a regression covering this multi-SET-NULL + CASCADE state, preferably with FK-order/prepared controls.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Reviewed exact head 04ea25e. The combined SET NULL producer now owns an isolated TableDef and marks its delete stream pending before sibling CASCADE planning, closing the previously reproduced projection/row-domain failure. The new literal and prepared regression covers reversed FK order, SET-only rows, CASCADE-owned rows, overlap, unaffected rows, and forced-index validation. The focused regression, all TestIssue26875 cases, and the full pkg/sql/plan suite pass locally; required CI is green.
What type of PR is this?
Which issue(s) this PR fixes:
issue #26875
What this PR does / why we need it:
Fixes REPLACE foreign-key actions when child tables have explicit unique or secondary indexes.
Validation:
go test ./pkg/sql/planTestIssue26875ReplaceMaintainsIndexedForeignKeyChildrenTestIssue25526PreparedUpdateJoinSecondExecutegolangci-lint run -v -c .golangci.yml ./...