Repository navigation
Description
[Bug] Single-table UPDATE evaluates later assignments against pre-update values
Environment
- Repository:
matrixorigin/matrixone - Local reproduction commit from
main:621782d4634a36865bdb18c9fe3853bf70f43f1c - Runtime build: local MatrixOne build on macOS arm64
- Client: Go MySQL driver over the MatrixOne MySQL protocol
- SQL endpoint: embedded standalone MatrixOne test cluster
- Test date: 2026-08-19
Describe the bug
For a single-table UPDATE, MatrixOne evaluates every right-hand-side expression against the original row. MySQL generally evaluates single-table assignments from left to right, so a later assignment can read the value produced by an earlier one.
This causes incorrect stored data for ordinary multi-column updates, including prepared statements and explicit transactions.
Steps to reproduce
CREATE DATABASE issue_update_assignment_order;
CREATE TABLE issue_update_assignment_order.t (
id INT PRIMARY KEY,
a INT,
b INT,
c INT
);
INSERT INTO issue_update_assignment_order.t VALUES (1, 1, 10, 100);
UPDATE issue_update_assignment_order.t
SET a = a + 1, b = a, c = b
WHERE id = 1;
SELECT a, b, c FROM issue_update_assignment_order.t WHERE id = 1;Actual behavior
MatrixOne returns:
a | b | c
2 | 1 | 10
It evaluates both b = a and c = b using the row values before the UPDATE.
The same result was reproduced three times for the direct statement, a server-side prepared statement, and an explicit transaction. ROLLBACK restores the original row, so this is not transaction visibility or commit handling.
A swap assignment shows the same behavior:
CREATE TABLE t(a INT, b INT);
INSERT INTO t VALUES (1, 2);
UPDATE t SET a = b, b = a;
SELECT a, b FROM t;MatrixOne returns (2,1).
Expected behavior
For a single-table UPDATE, later assignments should observe prior assignments in the same SET clause. The first reproduction should return:
a | b | c
2 | 2 | 2
The swap assignment should return (2,2).
MySQL documents this left-to-right behavior for single-table updates, including the equivalent example UPDATE t1 SET col1 = col1 + 1, col2 = col1: MySQL UPDATE documentation.
Source-level evidence
pkg/sql/plan/dml_context.go records update targets in updateCol2Expr, a map that does not retain the SQL SET order. In pkg/sql/plan/bind_update.go, assignments are planned from a projection of the original table row, so later right-hand-side expressions bind to pre-update column values.
Suggested fix
Preserve the source SET order for each target table. For a single-table update, plan assignments as sequential projections: each right-hand side reads the current result of preceding assignments, while a distinct original-row projection is retained for indexes, constraints, foreign keys, partitions, and row identifiers.
Multi-table UPDATE should remain a separate path because MySQL does not guarantee assignment order there.
Duplicate check
I searched MatrixOne issues and pull requests for UPDATE left to right, UPDATE assignment order, single-table UPDATE, a = a + 1, and b = a. No issue describing this table-row assignment-evaluation behavior was found. The superficially related closed issue #26685 concerns prepared session-variable assignments, not table-row update semantics.
Activity
fix: evaluate single-table UPDATE assignments left to right (#27337)
Lundomn commentedon Sep 7, 2026
QA 转测(2026-09-07)
请在本 Issue 记录实际测试版本/环境、通过或失败结论、未覆盖项及补测要求。按流程,QA 明确通过后再关闭 Issue;如发现失败或回归请保持 open 并反馈复现信息。
slyunnn commentedon Sep 8, 2026
Regression and extended verification for #27336 (2026-09-08)
Verification Environment
origin/mainatb2f0f3fe69b23cde495c59d226c647aba555cfdc—refactor: define canonical compute-group execution and harden ingress-owned scheduling (#26109).fix: evaluate single-table UPDATE assignments left to right, merge commit71c9eb37d3cbc5025c227460a0b1223462ac6734; it is an ancestor of the verifiedorigin/main.1 LogService + 1 TN + 1 CNdeployment, with no Proxy and one CN frontend at127.0.0.1:26001.mysqlclient at127.0.0.1:26001; focused embedded Go MySQL-driver test; MOTR record/replay client at127.0.0.1:26001. The direct and MOTR paths intentionally target the same physical CN in this single-CN topology.mysqlCLI and MOTR/PyMySQL); the focused upstream regression also exercises the MySQL driver against an embedded MatrixOne cluster.What Was Covered
SET a = a + 1, b = a, c = breturned(2,2,2).(2,2)and repeated assignmentSET a = a + 1, a = a + 1, b = areturned(3,3).PREPARE/EXECUTEpreserved left-to-right assignment semantics.ROLLBACKrestoration, andCOMMITpersistence.SET a = RAND(), b = apreserved the evaluated value (a = b).UPDATEandUPDATE ... FROM.20301and left the target row unchanged.SETordering, and server-side prepared execution plus MySQL-protocol SQL coverage reached the same planner path.Findings
The original regression is not reproducible on the current mainline. The single-table
UPDATEnow preserves sourceSETorder while the explicitly excluded multi-target andUPDATE ... FROMforms retain their simultaneous-assignment behavior.Focused current-main validation passed:
TestUpdateAssignmentEvaluationIsLeftToRightin./pkg/tests/issuescompleted successfully via the MatrixOne CGo test wrapper (13.290s).MOTR / BVT Coverage
Added and recorded:
suites/14_issue_regression/t/issue_27336_update_assignment_order.testsuites/14_issue_regression/r/issue_27336_update_assignment_order.resultThe case was recorded once and replayed twice successfully:
47statements per replay,47passed,0failed. The regression commit isf36a7548413a28c3f6b6a9f7793139896c4eeb0c(test: add MOTR regression for #27336) ontest/issue-27336-update-assignment-order, pushed tomatrixorigin/motrvia SSH.Large-data regression: not required. The defect is deterministic planner binding order within one target row and is independent of row count, block/batch boundaries, memory/spill, concurrency, data skew, network transport, or resource scale; larger data would not add relevant coverage.
Final Conclusion
Fixed. The mainline fix restores MySQL-compatible left-to-right
SETevaluation for single-tableUPDATE, while preserving the intended simultaneous semantics for multi-targetUPDATEandUPDATE ... FROM. The single-CN result is fully verified; multi-CN/Proxy routing remains explicitly not covered.fix: evaluate single-table UPDATE assignments left to right (matrixor…
fix: evaluate single-table UPDATE assignments left to right (matrixor…
fix: evaluate single-table UPDATE assignments left to right (matrixor…