Skip to content

fix(plan): validate child keys in modern update - #26407

Merged
mergify[bot] merged 17 commits into
matrixorigin:mainfrom
ck89119:issue-26338-main
Jul 31, 2026
Merged

mergify[bot] merged 17 commits into
matrixorigin:mainfrom
ck89119:issue-26338-main

Conversation

@ck89119

@ck89119 ck89119 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

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_checks consistently during route selection.

This PR:

  • defers foreign-key route selection until the final updated columns are known;
  • keeps unrelated updates on FK-bearing tables on the modern MULTI_UPDATE
    path;
  • validates affected child keys with per-constraint parent MARK joins;
  • preserves single and composite MATCH SIMPLE NULL semantics;
  • allows unchanged orphan keys while rejecting newly invalid keys;
  • routes referenced-parent-key updates to the legacy planner for the parent-side
    work tracked by [Subtask]: Move parent-side FK referential actions to MULTI_UPDATE #26339;
  • applies foreign_key_checks=0/1 consistently to routing and validation;
  • adds planner and real-server regression coverage for regular indexes,
    generated columns, UPDATE FROM deduplication, composite keys, and
    self-referencing foreign keys.

Validation:

  • seven focused planner tests passed with -race -count=100;
  • the complete pkg/sql/plan package passed with -race -count=1;
  • go build, go vet, make build, formatting, and diff checks passed;
  • update_modern_fk.sql passed 46/46 cases;
  • the affected self-referencing FK suites passed 60/60, 101/101, and 81/81
    cases.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mergify

mergify Bot commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-07-31 06:12 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-07-31 06:49 UTC · at 3c9c90b151fb6b3172e64f497548c9ecac0e688d · squash

This pull request spent 37 minutes 9 seconds in the queue, including 36 minutes 17 seconds running CI.

Required conditions to merge
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-neutral = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / e2e BVT Test on Linux/x64(LAUNCH, PESSIMISTIC)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone CI / SCA Test on Linux/arm64
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone Utils CI / Coverage
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants