Skip to content

[Bug]: EXPLAIN FORMAT=JSON UPDATE assignments show raw #[rel,col] refs instead of the assigned values #30130

Closed

Description

@iamlinjunhong

Environment

Actual Behavior

EXPLAIN FORMAT=JSON for an UPDATE renders the assignments value fields as opaque internal column references (#[0,0], #[0,1]) instead of the assigned expressions, even though the documented contract requires the actual value (docs/design/explain_format_json.md: "a plan for SET v = 2 includes a value of 2").

For update t set v = 2 where id = 1 the Multi Update node is:

{"id":"4","operator":"Multi Update","inputs":["3"],"table_names":["ub.t"],
 "assignments":[{"target":"ub.t.id","value":"#[0,0]"},{"target":"ub.t.v","value":"#[0,1]"}]}

The real assigned value 2 is present only one node lower, on the reachable Project (node 2):

{"id":"2","operator":"Project","inputs":["1"],"projection":["t.id","2","t.__mo_rowid","(not (t.v <=> 2))"]}

The same happens for expression sets and for unchanged columns: update t set v = v + 1 where id = 1 also yields value":"#[0,1]" (and target":"ub.t.id" yields #[0,0] instead of t.id), although node 1/2 carry cast((cast(t.v AS BIGINT) + 1) AS INT) and t.v + 1.

Expected Behavior

node.assignments[*].value must be the resolved row-image expression, exactly as the design document states. Concretely:

  • update t set v = 2 where id = 1 -> {"target":"ub.t.id","value":"t.id"}, {"target":"ub.t.v","value":"2"}.
  • update t set v = v + 1 where id = 1 -> {"target":"ub.t.v","value":"t.v + 1"} (or the equivalent typed expression actually projected).

MySQL 8.0 reports "set": {"t.v": "2"} for the same statements; MatrixOne must not emit #[rel,col] placeholder refs it has already resolved elsewhere in the same document.

Steps to Reproduce

drop database if exists ub; create database ub; use ub;
create table t(id int primary key, v int);
insert into t values (1,10);
explain format=json update t set v = 2 where id = 1;

Inspect the Multi Update node's assignments: both values are #[0,0] / #[0,1] rather than t.id / 2. Repeated three times and via a prepared statement (prepare s from 'explain format=json update t set v = 2 where id = 1') with identical output.

Additional information

Root cause is sqlJSONPlanBuilder.resolveUpdateColumnExpr in pkg/sql/plan/explain/sql_json.go. For a MULTI_UPDATE the row image is read from UpdateCtxList.InsertCols and resolved through only the immediate child: when ref.RelPos == 0 it returns child.ProjectList[ref.ColPos] verbatim (no further resolution). A real UPDATE plan places a Lock Operator between the MULTI_UPDATE and the producing Project; the Lock Operator's ProjectList is a passthrough of column refs (["#[0,0]","#[0,1]","#[0,2]","#[0,3]"]), so the resolver returns a column-ref expression and sqlJSONExpr serializes it as the literal #[0,1] string. The genuine value in the underlying Project is never consulted.

This gap is not caught by the newly added tests because TestBuildSQLJSONPlanResolvesPrunedUpdateAssignments (pkg/sql/plan/explain/sql_json_test.go:346) builds a LOCK_OP child whose ProjectList holds literal values (sqlJSONTestInt32(...)) rather than the passthrough column refs a real plan uses, so the single-level lookup happens to resolve to a real value there.

Impact: EXPLAIN FORMAT=JSON is the only way to inspect UPDATE assignments, and it is unusable/misleading for every real UPDATE (constant, expression, and unchanged columns alike). No data is corrupted; ordinary text EXPLAIN is unaffected, so the workaround is to avoid/ignore the assignments field. Severity is therefore major (incorrect documented EXPLAIN output with a workaround) rather than critical.

Note: #28301 tracks the feature being unavailable before #28435; that is not this issue. #30108 tracks the retired vector-scan protobuf build break, also unrelated.

Found by Loom bug hunt (module: sql-plan; tests: end-to-end)

Activity

  1. added
    kind/bug
    on Oct 13, 2026
  2. added
    ai-easy
    on Oct 15, 2026
  3. slyunnn commented on Oct 16, 2026

    @slyunnn

    Regression and extended verification for #30130 (2026-10-16)

    Verification Environment

    • MatrixOne latest origin/main: b24d1b311555e0b6f3d56eb37f9a2e9617e9a5b7 — fix(window): support temporal interval frame parameters and string parsing (#30310). The running mo-service -version reported this exact commit, and the Log, TN, both CNs, and Proxy process executables had the same SHA-256 checksum.
    • Associated fix: PR #30139, merge commit 66e7a4cf0ba25747e2071faef5d971654fca20e9 — fix(explain): resolve JSON UPDATE assignment expressions. This commit is an ancestor of the tested main.
    • Isolated topology: 2 CN / 1 TN / 1 Log service / 1 Proxy. Direct test endpoints inside the isolated network were Proxy mo-proxy:6001, CN1 mo-cn1:16001, and CN2 mo-cn2:16002; all were reachable. The isolated Proxy was also mapped to a nondefault host port because the shared host port 6001 belongs to another cluster.
    • Client: MySQL 8.4 CLI over the native MySQL text protocol with utf8mb4; SQL PREPARE / EXECUTE was used for the prepared case. Additional host-mapped checks used MySQL CLI 9.7.1.

    What Was Covered

    • OK — Original EXPLAIN FORMAT=JSON UPDATE t SET v=2 WHERE id=1 scenario, using an isolated schema: assignments rendered unchanged id as t.id and assigned v as 2, rather than raw #[rel,col] references, through Proxy, CN1, and CN2.
    • OK — Happy and boundary cases: v=v+1, v=NULL, v=id*10, and a WHERE predicate matching no rows rendered their intended expressions. The literal, arithmetic, and NULL cases were also rerun through all three exact service ports.
    • OK — SQL PREPARE / EXECUTE of JSON EXPLAIN rendered assigned value 7 through all three exact service ports.
    • OK — Multi-target UPDATE displayed lineage for both targets and the assigned 99 / 88 values through all three exact service ports. Additional EXISTS and nullable IN subquery assignment checks rendered readable source expressions on the same exact-main cluster.
    • OK — Invalid assignment column returned 1054 / 42S22 on all three exact service ports; subsequent queries succeeded.
    • OK — EXPLAIN did not modify either table. A real UPDATE changed v from 10 to 2 as a control and was then restored to 10; ordinary text EXPLAIN remained usable.
    • Not covered — Binary COM_STMT_PREPARE / COM_STMT_EXECUTE and a full BVT-suite replay. This issue concerns JSON plan rendering, not the binary prepared protocol; its focused SQL-prepared and direct-protocol cases passed.

    Findings

    The merged fix resolves UPDATE row-image references through the producing plan nodes before rendering assignments. No unresolved #[rel,col] value appeared in the checked assignment paths. The defect affected explanation output, not UPDATE data correctness.

    MOTR / BVT Coverage

    • Existing main-branch BVT coverage for this issue is in test/distributed/cases/optimizer/explain_format_json.sql and its .result; focused resolver tests are in pkg/sql/plan/explain/sql_json_test.go.
    • The focused pkg/sql/plan/explain Go tests covering planner UPDATE assignments, multi-target assignments, MARK/subquery outputs, and resolver boundaries passed on the tested main commit.
    • No new MOTR case, issue branch, commit, or daily-PR entry was added: the merged fix already supplies dedicated SQL BVT and unit coverage, and this verification found no uncovered regression path requiring duplicate MOTR coverage.

    Final Conclusion

    Fixed on latest origin/main b24d1b311555e0b6f3d56eb37f9a2e9617e9a5b7 for the original scenario and the tested extensions across the 2 CN / 1 TN / 1 Log service / 1 Proxy topology.

    Large-data regression: not needed. The bug is in deterministic JSON plan-expression resolution during EXPLAIN, not a row-count, block/batch, memory/spill, concurrency, network-transfer, or resource-scale boundary. Small isolated tables exercise the affected plan shapes without unrelated CI cost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions