Skip to content

[Subtask]: Move child-side foreign-key UPDATE validation to MULTI_UPDATE #26338

Closed

Description

@XuPeng-SH

Parent issue

#26336

Problem

The modern UPDATE resolver currently rejects a target as soon as its table definition contains any Fkeys or RefChildTbls. Because ResolveUpdateTables calls ResolveTables(..., respectFKCheck=false), this routing also ignores the session's foreign_key_checks value.

Planner selection should instead depend on the columns actually updated:

A table can be both child and parent, so these decisions must be made per constraint, not per table.

Required work

  • Keep unrelated-column updates on FK-bearing tables in the modern MULTI_UPDATE path.
  • Detect which child FK constraints are affected by the final updated row image.
  • Validate changed child keys against the corresponding parent key.
  • Preserve single/composite FK NULL semantics, including partial-NULL keys.
  • Apply the defined foreign_key_checks=0/1 semantics consistently to routing and validation; do not preserve the current metadata-only routing accident.
  • Reuse modern base-table, regular-index, lock, retry, and rollback behavior.
  • Leave referenced-parent-key actions to [Subtask]: Move parent-side FK referential actions to MULTI_UPDATE #26339.

Acceptance criteria

  • An unrelated-column UPDATE produces MULTI_UPDATE even when the target has child FKs, referenced children, or both.
  • Changing a child FK to an existing parent succeeds; changing it to a missing parent fails before mutation.
  • Unchanged child FK columns do not cause redundant parent probes.
  • Single and composite FKs cover all-non-NULL, all-NULL, partial-NULL, nullable, and NOT NULL cases.
  • foreign_key_checks=0 and =1 have explicit plan and behavior tests matching the intended SQL contract.
  • The real-server shape from [Bug]: nullable index UPDATE keeps Rowid from filtered NULL row #26334 (nullable UNIQUE plus unrelated FK metadata) uses MULTI_UPDATE, contains no PreInsert UniqueKey, and leaves correct hidden-index contents.
  • [Bug]: nullable index UPDATE keeps Rowid from filtered NULL row #26334 remains independently fixed so the legacy path is safe during rollout.
  • Optimistic/pessimistic conflict, retry, cancellation, and rollback cases remain atomic.
  • INSERT/ODKU FK behavior is unchanged.

Test matrix

  • Target with only Fkeys, only RefChildTbls, and both.
  • Unrelated column; unchanged FK columns; changed child FK to present/missing parent.
  • Single/composite FK with NULL combinations.
  • Nullable single/composite UNIQUE and secondary indexes on the target.
  • Multi-row batches where filtered NULL index keys precede and follow surviving rows.
  • foreign_key_checks=0/1 in optimistic and pessimistic modes.

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions