Skip to content

fix(plan): enforce CHECK constraints on final update rows - #26912

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aptend:fix/26820-update-check-constraints
Aug 10, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
aptend:fix/26820-update-check-constraints

Conversation

@aptend

@aptend aptend commented Aug 10, 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 #26820

What this PR does / why we need it:

Enforces persisted CHECK constraints on the final row image for UPDATE and the UPDATE arm of INSERT ... ON DUPLICATE KEY UPDATE.

  • introduces a row-preserving ASSERT plan boundary for strict CHECK validation;
  • keeps UPDATE/INSERT IGNORE row-filter semantics behind an explicit pushdown barrier;
  • validates modern UPDATE, fallback joined UPDATE, and ODKU after final-row materialization but before writes;
  • preserves ASSERT semantics through parallel operator duplication and remote pipeline serialization;
  • adds planner, operator, protobuf, EXPLAIN, and multi-CN BVT coverage.

Validation:

  • make generate-pb
  • CGo-enabled unit tests for the six owning packages
  • make build
  • multi-CN check_constraint.test: 55/55 passed

@aptend
aptend requested a review from a user August 10, 2026 07:39
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@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.

Deep-reviewed exact head b519b9f.

CHECK constraints are evaluated over the final row image on the modern UPDATE path, the joined-update fallback, and ON DUPLICATE KEY UPDATE. Strict assertions remain row-preserving; UPDATE IGNORE uses a non-reorderable cardinality barrier; and DEDUP UPDATE, remapping, statistics, explain, operator duplication, and remote pipeline serialization preserve the new semantics.

Focused CGo tests passed for the assertion fast path and error cleanup, runtime-filter coexistence, remote round-trip, identity projection, UPDATE/UPDATE IGNORE/joined UPDATE/ODKU plan shapes, absent outer-join targets, pushdown boundaries, deep copy, and stats. git diff --check passed. No merge-blocking issue found.

VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#26912)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26820

## What this PR does / why we need it:

Enforces persisted CHECK constraints on the final row image for UPDATE
and the UPDATE arm of INSERT ... ON DUPLICATE KEY UPDATE.

- introduces a row-preserving ASSERT plan boundary for strict CHECK
validation;
- keeps UPDATE/INSERT IGNORE row-filter semantics behind an explicit
pushdown barrier;
- validates modern UPDATE, fallback joined UPDATE, and ODKU after
final-row materialization but before writes;
- preserves ASSERT semantics through parallel operator duplication and
remote pipeline serialization;
- adds planner, operator, protobuf, EXPLAIN, and multi-CN BVT coverage.

Validation:

- `make generate-pb`
- CGo-enabled unit tests for the six owning packages
- `make build`
- multi-CN `check_constraint.test`: 55/55 passed

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#26912)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26820

## What this PR does / why we need it:

Enforces persisted CHECK constraints on the final row image for UPDATE
and the UPDATE arm of INSERT ... ON DUPLICATE KEY UPDATE.

- introduces a row-preserving ASSERT plan boundary for strict CHECK
validation;
- keeps UPDATE/INSERT IGNORE row-filter semantics behind an explicit
pushdown barrier;
- validates modern UPDATE, fallback joined UPDATE, and ODKU after
final-row materialization but before writes;
- preserves ASSERT semantics through parallel operator duplication and
remote pipeline serialization;
- adds planner, operator, protobuf, EXPLAIN, and multi-CN BVT coverage.

Validation:

- `make generate-pb`
- CGo-enabled unit tests for the six owning packages
- `make build`
- multi-CN `check_constraint.test`: 55/55 passed

Co-authored-by: XuPeng-SH <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…in#26912)

## What type of PR is this?

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#26820

## What this PR does / why we need it:

Enforces persisted CHECK constraints on the final row image for UPDATE
and the UPDATE arm of INSERT ... ON DUPLICATE KEY UPDATE.

- introduces a row-preserving ASSERT plan boundary for strict CHECK
validation;
- keeps UPDATE/INSERT IGNORE row-filter semantics behind an explicit
pushdown barrier;
- validates modern UPDATE, fallback joined UPDATE, and ODKU after
final-row materialization but before writes;
- preserves ASSERT semantics through parallel operator duplication and
remote pipeline serialization;
- adds planner, operator, protobuf, EXPLAIN, and multi-CN BVT coverage.

Validation:

- `make generate-pb`
- CGo-enabled unit tests for the six owning packages
- `make build`
- multi-CN `check_constraint.test`: 55/55 passed

Co-authored-by: XuPeng-SH <[email protected]>
XuPeng-SH added a commit that referenced this pull request Nov 30, 2026
## What type of PR is this?

- [x] BUG

## Which issue(s) this PR fixes:

Related to #26820. Applies the final-row CHECK behavior from #26912 to
`4.2-dev`.

## What this PR does / why we need it:

Enforce CHECK on the rows that ordinary and joined UPDATE, UPDATE
IGNORE, upserts, and foreign-key actions actually write. Evaluate
explicit assignments once, select a complete source row per update
target, and derive generated values in dependency order. CHECK,
generated keys, and the write use the same row values.

- DedupJoin validates each image that another conflict will overwrite.
The existing vectorized CHECK validates the emitted image before no-op
write suppression, including a single conflicting row. A subsequent
valid assignment cannot hide a rejected intermediate value.
- SQL-equal explicit assignments retain observable representations.
Implicit `ON UPDATE` values and dependent generated columns are
finalized before CHECK. A generated column is evaluated once, including
in a no-op where a provisional timestamp would have caused a cast error.
Final write suppression compares the materialized values, including a
timestamp changed by an earlier conflict.
- Validate unsupported generated primary and unique key movement during
each repeat fold. Pre-resolved conflict targets require stable encoded
keys throughout folding, independently of CHECK and implicit `ON
UPDATE`. Both fold and final-row validation use the same key encoding
and return 20313 for unsupported movement.
- Eligible single-row generated primary key updates reuse UPDATE's
new-key duplicate check and lock. Delete by the old key and maintain
regular secondary-index entries by their original owner.
- Foreign-key actions validate the generated child row, preserve the
NULL-component exemption, and compare outgoing keys with SQL equality.
Changed non-NULL references use the existing parent lookup and lock when
the parent is outside the write closure. REPLACE child Datalink
admission stays bound to the final child values. Its existing guards
cover generated changes that would require unsupported index maintenance
or an unstable referenced parent.

The rebase uses the shared CDC task-store readiness check from #33451
and removes the temporary local task-service setup. Intermediate
generated-key checks reuse one encoded key snapshot per repeated group
that needs it. The final plan checks the emitted key. The change reuses
the existing plan fields, per-worker scratch and write path.

### Validation

- Go 1.26.4, darwin/arm64. Fresh race runs passed in 10 Go packages
covering planner, executor, compile, hash-build, multi-update, protocol
types and consumers. The mandatory-role-rule integration test passed.
Scoped golangci-lint reported zero issues. The pinned molint tool
reported 11 existing diagnostics in eight files identical to the release
base. Formatting, err-check and generated-plan binding verification
passed.
- At the previous PR head, direct UPDATE rejected negative zero with
3819. Matched and fresh duplicate groups and a singleton upsert accepted
the same invalid representation. The fixed MySQL TCP probe passed all
nine cases, including statement rollback inside an explicit transaction,
reuse of a prepared statement after an error, a secondary UNIQUE
conflict, an encoded generated key, and generated-cast boundaries.
- Five BVT fixtures passed 704/704 statements on an isolated cluster.
CHECK 245, generated columns 174, modern duplicate-key DML 203, VARCHAR
casts 47, prepared projections 35.
- Local timing for a prepared 4,096-conflict statement, five measured
executions after warm-up, median before → after: plain 5.19 → 5.25 ms,
check only 6.21 → 6.06 ms, implicit generated 7.09 → 7.14 ms. This is a
single-CN comparison of these workloads.

[Hosted
checks](https://github.com/matrixorigin/matrixone/pull/33324/checks)

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/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants