Skip to content

fix(sql): refresh automatic timestamps on stored text changes - #33682

Open
aptend wants to merge 3 commits into
matrixorigin:mainfrom
aptend:fix/astra-meow-33660
Open

aptend wants to merge 3 commits into
matrixorigin:mainfrom
aptend:fix/astra-meow-33660

Conversation

@aptend

@aptend aptend commented Dec 2, 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:

Fixes #33660

What this PR does / why we need it:

An UPDATE can persist different text bytes under a Unicode collation without refreshing an unassigned ON UPDATE CURRENT_TIMESTAMP column. Use the stored row image for the automatic update decision, including when multiple aliases update the same physical row. Keep explicit assignments per row. In UPDATE IGNORE, evaluate constraints against the candidate row that would be written and preserve the previously accepted row image when a later contribution is rejected. Preserve CHAR padding and NULL handling, affected-row accounting, and ODKU behavior.

Validation

  • Native SQL covered stale automatic timestamps, rejected CHECK contributions after partial reversion, unsigned DECIMAL assignment, explicit precedence, byte-identical no-ops, prepared execution, and rollback. Both selected UPDATE BVT cases passed mo-tester's -n -g comparison (574/574 statements), with fixture teardown verified.
  • 157 focused native CGO planner tests passed, including assertions that candidate CHECK filters depend on guarded timestamp projections. The official changed-code coverage parser measured 243/303 (80.20%) from the native set-mode profile, above the 75% threshold.
  • make static-check-selected STATIC_CHECK_PACKAGES="$(SCA_LOCAL_BASE=origin/main node .github/ci/static-analysis.cjs)" passed for 110 affected packages using both pinned analyzers.
  • Rebased onto 6f47e8540cc3 with the same four-file feature patch. Focused Linux x86 race planner controls and the native UPDATE IGNORE regression passed. The selected UPDATE BVT passed 574/574 statements. make static-check-selected STATIC_CHECK_PACKAGES="$(SCA_LOCAL_BASE=6f47e8540cc348849c1065f574cde38e37fd7741 node .github/ci/static-analysis.cjs)" passed for 89 affected packages with the pinned analyzers.

@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 added the kind/bug Something isn't working label Dec 2, 2026
@matrix-meow matrix-meow added the size/L Denotes a PR that changes [500,999] lines label Dec 2, 2026
@mergify

mergify Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 45608ad2d8db2eea5b956e65a773adbf3c13d146

Review completed. Read the assessment.

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

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

Commit: 45608ad2d8db2eea5b956e65a773adbf3c13d146

Assessment: request_changes

The planner change reuses the existing changed-row predicate and lossless binary serialization for Unicode text. The new regression case does not actually verify several required timestamp-preservation controls because it compares against a timestamp that was already replaced.

Model: gpt-6.1-terra / max

Session: 01a23504-137d-7f93-9b91-fd29f7f60fa2 · slot 1 · generation 42

  • P2 test/distributed/cases/dml/update/dml_on_update_collation_bytes.sql:77: A NULL-to-NULL update, an identical ODKU, or an explicit ts=ts assignment refreshes the timestamp unexpectedly.
    Impact: The new BVT can still pass, leaving the requested no-op and explicit-assignment behavior without an effective public-path regression oracle. This is a validation defect, not a demonstrated production failure.
    Evidence: The preceding value-to-NULL update already refreshes ts, and the result at dml_on_update_collation_bytes.result:72 expects ts_kept_fixed=0. Another refresh also satisfies that assertion. The ODKU and ts=ts controls likewise accept any timestamp after the original 2000 sentinel. Seed a fixed timestamp or capture the immediately preceding value before each no-op, assert equality afterward, update the result, and rerun the existing BVT.

Validation:

  • Reviewed the complete diff, linked issue, indexed discussion, relevant repository policy, and the planner, serialization, comparison, and update consumers.

  • Private /tmp and loopback preflight passed: checks/1796222639383126951-3.json and preflight.log.

  • A static fixture check confirmed the ineffective no-op assertions: checks/1796223044082763365-4.json and oracle-check.log. It did not execute SQL.

  • git diff --check passed for the assigned merge-base and head: checks/1796223057528545104-3.json and diff-check.log.

  • The supplied CI snapshot reports successful Ubuntu unit and multi-CN BVT jobs, without individual case results.

Limitations:

  • No local Go or SQL tests ran. The installed Go 1.26.6 is below the checkout's Go 1.27.1 requirement, and the bounded toolchain download timed out before package loading.

  • The author reports focused planner and BVT runs, but local_validation contains no matching command and log receipts.

@XuPeng-SH

XuPeng-SH commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 5ec1de9946def30295f14cc8626e4fc6ece4d4d4

Review completed. Read the assessment.

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

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

Commit: 5ec1de9946def30295f14cc8626e4fc6ece4d4d4

Assessment: request_changes

The revised fixture resolves the previous review’s timestamp-oracle concern. The byte-comparison fix remains incomplete for multi-target updates in which two aliases refer to the same physical row.

Model: gpt-6.1-terra / max

Session: 01a23642-a5da-74a3-9479-4bd000540084 · slot 0 · generation 54

  • P2 pkg/sql/plan/bind_update.go:933: A self-join updates the same row through two aliases, with a collation-equal byte change through the first alias and a no-op assignment through the later alias, for example: UPDATE t a JOIN t b ON a.id=b.id SET a.v='A', b.n=b.n.
    Impact: The stored value can change from 'a' to 'A' while the unassigned ON UPDATE timestamp remains unchanged. This is a preexisting same-row merge issue that leaves the stated timestamp fix incomplete for this supported UPDATE form.
    Evidence: The new predicate computes the automatic timestamp separately for each alias. Both automatic values become contributions in collectPhysicalTargetAssignedCols; mergeSamePhysicalTargetAssignmentsAcrossTuples then constructs the final value in target order, so the later alias’s unchanged timestamp overrides the earlier alias’s refreshed value. Derive the automatic decision from the merged physical row, or otherwise prevent a no-op alias from overriding a refresh, while preserving explicit timestamp assignments. The source-derived SQL scenario is retained in repeated-target-on-update.sql.

Validation:

  • Private /tmp and loopback preflight passed.

  • A static fixture check confirmed that the three previously disputed controls seed a fixed timestamp and expect it to remain equal.

  • git diff --check passed for the assigned merge-base and head.

  • The supplied CI snapshot reports successful Ubuntu unit and multi-CN BVT jobs, without individual case logs.

Limitations:

  • The self-join counterexample was traced through source and was not executed.

  • The local Go installation is 1.26.6, below the checkout’s 1.27.1 requirement; the toolchain download attempt timed out before the focused test compiled.

  • The author reports selected BVT and planner runs, but the supplied local_validation contains no matching retained logs.

@XuPeng-SH

XuPeng-SH commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 95bf777a976e4adeebc720c071202045d70f5085

Review completed. Read the assessment.

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

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

Commit: 95bf777a976e4adeebc720c071202045d70f5085

Assessment: request_changes

The fix reuses the existing byte comparison and repeated-target admission machinery, but its unsigned-DECIMAL exception leaves the merged-row behavior incomplete and can cause UPDATE IGNORE to discard a valid assignment.

Model: gpt-6.1-terra / max

Session: 01a237df-a073-7910-ac2c-836d2d273b8a · slot 1 · generation 43

  • P2 pkg/sql/plan/bind_update.go:3947: A table has v VARCHAR COLLATE utf8mb4_unicode_ci, n INT, d DECIMAL(20,0) UNSIGNED DEFAULT 0 ON UPDATE CURRENT_TIMESTAMP, and CHECK (HEX(v) = '61' OR d > 0). Starting from (v, n, d) = ('a', 0, 0), run UPDATE IGNORE t a JOIN t b ON a.id = b.id SET a.v = 'A', a.n = 1, b.n = 0.
    Impact: The later alias is incorrectly rejected and n remains 1, although the merged row with v = 'A', n = 0 and a refreshed d satisfies the CHECK. Without the CHECK, ordinary and IGNORE updates can instead leave d at 0 after the stored text bytes change.
    Evidence: The candidate path retains the per-alias automatic decimal value here, and the final paths also skip merged-image resolution at lines 4453 and 5558. A real SQL probe observed n = 1; the otherwise identical signed-DECIMAL control observed n = 0. Resolve the candidate and final decimal values from the merged image while preserving unsigned admission and explicit-assignment precedence, and add a regression case for both ordinary and CHECK-constrained IGNORE updates.

Validation:

  • The complete pkg/sql/plan package passed with -count=1 using the assigned test executor; receipt checks/1796303669029737344-4.json and planner-package.log.

  • A real-SQL CHAR probe passed for single and repeated targets, IGNORE, padding, reversion and explicit timestamp assignment; receipt checks/1796303380762943447-6.json.

  • Real-SQL unsigned-DECIMAL probes reproduced the stale value and rejected assignment; receipts checks/1796303532962421826-5.json and checks/1796303731125162512-6.json. The signed-DECIMAL admission control passed under checks/1796303767309826416-5.json.

  • Private execution preflight and git diff --check passed. The native build succeeded after retrying with the checkout-verified ONNX prebuilt input; receipts and logs are retained in the diagnostic directory.

Limitations:

  • The PR reports a 574/574 mo-tester BVT run, but its terminal logs were not supplied in the assigned evidence and the full BVT was not independently rerun.

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/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Ordinary UPDATE preserves ON UPDATE timestamp for collation-equal byte changes

3 participants