Skip to content

fix(sql): validate offered rows before ODKU arbitration - #33687

Merged
XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/33536-33537-odku-input-constraints
Dec 2, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/33536-33537-odku-input-constraints

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

Fixes #33536
Fixes #33537

What this PR does / why we need it:

A duplicate-key UPDATE can discard invalid values from the offered INSERT row. Validate the assigned row before duplicate arbitration. A CHECK violation returns 3819 and a NULL in a required column returns 1048. A failed statement leaves existing rows unchanged and rolls back writes from valid siblings.

Use the existing duplicate-action replay to check the changed UPDATE image before the next action. Remove the final-only CHECK path and its synthetic FK eligibility column. The input NOT NULL assertion reads the vector's NULL metadata. CHECK accepts SQL UNKNOWN directly and looks up statement mode only on a violation.

  • Verified 39 SQL assertions covering diagnostics, statement rollback, prepared reuse, key shapes, generated values, AUTO_INCREMENT, IGNORE, and FK behavior. Six BVT suites passed all 982 checks. A second CN read the expected rows after both rejections and a valid commit.
  • Alternated the candidate production code and main at 6302cd4e33 over 13 runs per workload with 24,000 input rows per run. Median latency in ms was 45.6 to 45.4 for new rows, 88.0 to 84.2 for duplicates without CHECK, 91.6 to 85.2 for duplicates with an unrelated CHECK, and 98.2 to 94.8 for duplicates modifying a checked column. Final row counts and sums matched. Both binaries had outliers on the test host.
  • Incremental vet and lint passed. Race tests passed for moerr, sql/compile, sql/plan/function, and dedupjoin, plus the targeted planner suite on the PR head.

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

@mergify

mergify Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 7f422c1be6b12d67b4d4567c19636276d4e7326c

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 7f422c1be6b12d67b4d4567c19636276d4e7326c

Assessment: approve

The change validates offered rows before duplicate arbitration and reuses ordered duplicate-action replay for resulting CHECK constraints. It removes the superseded final-only CHECK path without introducing a separate action stream. No actionable defects remain in the reviewed scope.

Model: gpt-6.1-terra / max

Session: 01a2350e-851d-7031-94fc-615272373c71 · slot 2 · generation 20

Validation:

  • Isolated preflight passed. Focused CHECK-function, planner and compile-operator tests passed; logs and matching receipts are retained in the diagnostic directory.

  • A MySQL-protocol probe passed against fresh one- and two-CN embedded clusters. It covered CHECK and NOT NULL diagnostics, rollback, IGNORE warnings, ordered actions, prepared parameters, INSERT SELECT, nullable LIMIT, composite-unique conflicts and committed readback from the second CN. The two-CN receipt is checks/1796225681344777671-3.json, with odku-sql-probe-v4.log and its retained test source.

  • The first focused test attempt timed out while fetching dependencies; the subsequent run passed.

Limitations:

  • The full BVT and race suites and the reported performance comparisons were not independently repeated; the author reports passes, but their raw logs were not supplied.

  • The two-CN probe verified peer readback, not a forced remote execution pipeline. CI was still in progress or queued in the frozen evidence.

@XuPeng-SH
XuPeng-SH merged commit f0c32a6 into matrixorigin:main Dec 2, 2026
18 of 23 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/33536-33537-odku-input-constraints branch December 2, 2026 16:00
XuPeng-SH added a commit that referenced this pull request Dec 2, 2026
## What type of PR is this?

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

## Which issue(s) this PR fixes:

Related to #33536. Follow-up to #33687.

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

The CHECK BVT still expected an invalid incoming row to update an
existing row when the duplicate-key assignment had a valid value. #33687
validates the incoming row before duplicate-key arbitration.

Keep that input in the script and assert the CHECK violation and the
unchanged stored value. Use a valid incoming row with an invalid
assignment to cover CHECK on the UPDATE image independently. A valid
input and assignment still update the row to 30.

Ran both versions of `check_constraint.test` against a local MatrixOne
cluster at `d96cdf0c26` with the [failing
job](https://github.com/matrixorigin/matrixone/actions/runs/46924549921/job/143622456616?pr=33073)'s
mo-tester revision `309a0ca650`. The old script reproduced all 3
failures. The updated script passed 71/71 statements. The full Compose
BVT suite was not run locally.

Signed-off-by: XuPeng-SH <[email protected]>

This branch was successfully deployed

No deployments
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/M Denotes a PR that changes [100,499] lines

Projects

None yet

2 participants