Repository navigation
fix(plan): handle empty indexed FK cascades and cover self-FK ALTER - #29994
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? |
|
mo-bot review · Commit: Assessment: request_changes Reviewed the complete six-file delta. The direct DELETE fix introduces a planning regression for indexed self-referencing CASCADE under REPLACE. Model: Session:
Validation:
Limitations:
|
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 4a19f94b73c0913a9208622a624da8ecf8234ffd
Assessment: request_changes
Reviewed the complete six-file delta. The direct DELETE fix introduces a planning regression for indexed self-referencing CASCADE under REPLACE.
Model: gpt-6-astra / xhigh
Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0
- P2
pkg/sql/plan/build_dml_util.go:6561: REPLACE on a table with an ON DELETE CASCADE self-reference and a regular secondary or unique index. Example: create table sr(id int primary key, parent_id int, key idx_parent(parent_id), foreign key(parent_id) references sr(id) on delete cascade); insert into sr values (1,null),(2,1); replace into sr values (1,null);
Impact: The new predicate incorrectly selects the positional DELETE path before createQuery, producing an untagged hidden-index scan that causes planning to fail.
Evidence: Modern REPLACE builds its cascade graph before createQuery (build.go:250–270). The self-cascade context at build_dml_util.go:1821–1827 leaves sourceTag and updateColLength zero, making localCascadeDelete true. Lines 6609–6611 disable projection preservation, so appendDeleteIndexTablePlan omits scan BindingTags at 4492–4494. Subsequent TABLE_SCAN remapping unconditionally reads BindingTags[0] (query_builder.go:1314). Previously this branch retained a binding tag. Distinguish the actual construction phase or propagate the self-cascade tag, and add an indexed self-referencing REPLACE regression.
Validation:
-
Traced direct DELETE, ordinary tagged cascades, self-referencing REPLACE, index lookup, deletion and optimizer consumers.
-
Reviewed all added planner tests and SQL/result regressions; none covers indexed self-referencing REPLACE.
-
Frozen exact-head CI reports successful UT, SCA, coverage, proxy BVT, pessimistic multi-CN BVT and required checks.
-
gofmt and git diff --check passed; assigned HEAD and unchanged source verified.
-
Saved the source-trace audit and diagnostic SQL under the current attempt directory.
Limitations:
-
Finding established by source tracing; the SQL trigger was not executed locally. Available native artifacts failed the repository owner's input-equivalence requirement.
-
Author-reported pre-rebase runtime checks were treated as supplementary evidence.
-
Full linked-issue bodies were absent. No independent performance measurements were made.
|
mo-bot review · Commit: Review completed. Read the assessment. |
XuPeng-SH
left a comment
There was a problem hiding this comment.
mo-bot review · mo-bot-local · review
Commit: 4268bd4c66980482adb46038aaad67ae9e27b130
Assessment: approve
Reviewed the complete six-file delta and frozen discussion. The fix coherently reuses existing index maintenance, preserves positional DELETE and tagged REPLACE contracts, and addresses the prior self-cascade finding. No actionable defects remain.
Model: gpt-6-astra / xhigh
Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0
Validation:
-
Traced cascade sources through index joins, locks, DELETE, and planner remapping; reviewed all planner and SQL/result changes, including empty actions, rollback, NULL keys, RESTRICT, and self-referencing REPLACE.
-
Reused frozen exact-head CI results: successful build, Ubuntu UT, SCA, coverage, proxy BVT, and pessimistic multi-CN BVT.
-
HEAD/base, unchanged source, patch contents, diff whitespace, and Go formatting passed. Receipt: attempt-1/checks/1791950704935376966-4.json; log: attempt-1/review_static_check.log.
-
Detailed scope, evidence reconciliation, and performance analysis retained in attempt-1/review-record.json. Runtime-filter suppression was already present; ordinary SQL paths retain their previous behavior.
Limitations:
-
No local Go/SQL execution or performance benchmarks were repeated. Author-reported checks lack retained logs and were treated as supplementary evidence; raw CI logs were not supplied.
-
Full linked-issue bodies were absent; their behavioral contracts were assessed from the frozen PR description and regression cases.
Merge Queue Status
This pull request spent 36 minutes 28 seconds in the queue, with no time running CI. ReasonPull request #29994 has been dequeued Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.
HintYou should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it. Waiting for any of
All conditions
Tick the box to put this pull request back in the merge queue (same as
|
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29954
Related to #29910: the production fix is already on main in #27799; this PR adds regression coverage.
What this PR does / why we need it:
Deleting a parent with no matching children can panic when an indexed CASCADE child table contains unrelated rows. Direct DELETE appends these recursive branches after planner tag remapping. Use a matched-only index lookup and local input positions throughout untagged recursive deletes, and keep runtime filters disabled to avoid a feedback wait cycle. Carry the tagged self-referencing CASCADE source into its recursive context before createQuery, so indexed REPLACE keeps the planner tags needed by index scans, locks, and DELETE. Positional direct-DELETE actions still use the matched-only local layout.
Add planner assertions and SQL regressions for empty and matching cascades, single/composite/unique indexes, NULL keys, prepared deletes, rollback, unrelated-row preservation, and RESTRICT controls. Cover indexed self-referencing REPLACE with secondary/unique indexes, recursive descendants, empty actions, forced-index reads, key reuse, and subsequent direct DELETE. Extend the existing ALTER regression to cover populated self references during VARCHAR resizing, including dropping and re-adding the foreign key (#29910).
Validation:
pkg/sql/plantests pass (9.479s); package vet and configured incremental golangci-lint pass.7af631bdf7; fullpkg/sql/plantests pass with repository CGo setup, Go 1.27.1, GOAMD64=v3, GOEXPERIMENT=simd.This PR targets main; it does not include a v4.2.5 backport.