Repository navigation
fix(plan): validate child keys in modern update - #26407
Conversation
XuPeng-SH
left a comment
There was a problem hiding this comment.
[P1] Mark modern FK-sensitive UPDATE plans for rebuild/cache invalidation across foreign_key_checks changes.
appendUpdateForeignKeyChecks makes the plan shape depend on the session value at lines 32-38: with checks off it returns before adding the child MARK joins/asserts, while with checks on it adds them (and parent-key routing depends on the same value). Neither branch sets Query.HasForeignKeyAction.
The prepared-statement contract in pkg/frontend/computation_wrapper.go only rebuilds such a plan on EXECUTE when HasForeignKeyAction is true, and both prepared compile caching and generic plan caching use that flag as well. Consequently, PREPARE with foreign_key_checks=0, then switch to 1 and EXECUTE, can reuse the cached no-check plan and write an invalid child key. The inverse transition can retain enforcement after checks are disabled. The new ordinary child update keeps prepare cacheable test currently codifies the unsafe false flag.
Please mark the query FK-sensitive before the disabled early return whenever the UPDATE can depend on FK metadata, and add prepared-statement regressions for both 0→1 and 1→0 transitions. Please also make the AUTO_INCREMENT child-key routing decision observe the disabled setting if consistent foreign_key_checks=0 routing is intended.
Deep re-review of exact head 9f2fa1182cee2392c7f279cbe02b9b1e7e7adf21: the prior AUTO_INCREMENT final-value validation and typed 1452/23000 error blockers are resolved. Focused planner tests passed under race (-count=5); go build, go vet, and git diff --check also passed. CI is still running.
XuPeng-SH
left a comment
There was a problem hiding this comment.
Re-reviewed exact head 25d7f042acb4a66e5d664b12e524633880ed7af5. The prior blockers are resolved: FK-sensitive UPDATE plans are marked independently of the current foreign_key_checks value, both prepared/generic cache paths invalidate correctly across 0↔1, and disabled checks retain the intended modern AUTO_INCREMENT route. Child-key row-image validation, MATCH SIMPLE NULL handling, unchanged-orphan behavior, self-reference, parent-key fallback, and typed 1452/23000 errors remain sound. Focused planner/frontend tests passed under race; the full pkg/sql/plan package and exact-head CI pass.
Merge Queue Status
This pull request spent 37 minutes 9 seconds in the queue, including 36 minutes 17 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #26338
What this PR does / why we need it:
The modern UPDATE planner previously rejected every FK-bearing target based only
on table metadata, even when the updated columns were unrelated to any foreign
key. This forced those statements onto the legacy planner and did not apply
foreign_key_checksconsistently during route selection.This PR:
MULTI_UPDATEpath;
work tracked by [Subtask]: Move parent-side FK referential actions to MULTI_UPDATE #26339;
foreign_key_checks=0/1consistently to routing and validation;generated columns, UPDATE FROM deduplication, composite keys, and
self-referencing foreign keys.
Validation:
-race -count=100;pkg/sql/planpackage passed with-race -count=1;go build,go vet,make build, formatting, and diff checks passed;update_modern_fk.sqlpassed 46/46 cases;cases.