Skip to content

fix(explain): resolve JSON UPDATE assignment expressions - #30139

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/explain-json-update-assignments-30130
Oct 14, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
iamlinjunhong:fix/explain-json-update-assignments-30130

Conversation

@iamlinjunhong

@iamlinjunhong iamlinjunhong commented Oct 14, 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:

Please leave the issue open for the reporter to verify after merge.

What this PR does / why we need it:

EXPLAIN FORMAT=JSON UPDATE t SET v = 2 currently exposes #[0,1] as the assignment value because the row image passes through a Lock Operator. Resolve anonymous row-image references in each producing node's context until the assigned expression is reached. Constant and expression assignments now display 2 and t.v + 1, while unchanged columns retain their source names.

Multi-target UPDATE plans also resolve materialized source steps, aggregate slots, and window outputs. UNION outputs show explicit branch lineage so both aliases' expressions remain visible. Generated MARK-join outputs used by EXISTS and IN subquery assignments now render their join predicates as display-only lineage, retaining three-valued semantics and the outer IS TRUE/NOT wrappers. The resolver selects the correct input for joins and preserves column reordering, logical binding references, and nested function/list expressions. It copies expression containers before substitution and rejects cyclic or unresolved references. This only changes UPDATE assignment rendering; the JSON schema and execution plan are unchanged. Work and allocations are limited to EXPLAIN expression expansion.

Regression coverage includes real planner output, passthrough/reordered projections, join inputs, named terminals, repeated references, invalid/cyclic references, and plan immutability. The existing SQL regression now checks constant, arithmetic, NULL, and prepared UPDATE assignment values together with the existing no-write controls.

Validation on macOS arm64, Go 1.27.1:

  • Reproduced the exact-head MARK-output failure for EXISTS, IN, NOT EXISTS, and NOT IN assignment plans before repair.
  • mo-cgo-test -v -count=1 -timeout=120s ./pkg/sql/plan/explain passed. Final focused MARK tests also passed, including multiple predicates with NULL, malformed inputs, empty predicates, cycles, cancellation, and plan immutability.
  • Scoped go vet and golangci-lint passed (0 issues).
  • Built cmd/mo-service with the repository native libraries and ran optimizer/explain_format_json.sql in mo-tester normal comparison mode twice against a fresh isolated instance: 155/155 statements each, zero ignored/abnormal. Verified database teardown after each round.
  • Public SQL controls cover EXPLAIN's lack of writes, multi-target updates, nullable IN/NOT IN assignments, EXISTS/NOT EXISTS, and empty subquery results.
  • Documented display-only UNION and MARK lineage without changing the JSON schema or executable plan.

Rebased onto official main a33dcfb2e54196e17abe21de4346200a18009d83; package, static, build and both public SQL checks passed again after rebase. The starting head's required CI checks passed. CI for the repair commit will run after the update.

@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 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 93673814b48e7d205b9dc518c0812fbc9b068efb

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: 93673814b48e7d205b9dc518c0812fbc9b068efb

Assessment: request_changes

Reviewed the complete four-file delta and affected callers. Keeping expression expansion in the EXPLAIN renderer is appropriate, but the implementation rejects valid multi-target UPDATE plans.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

  • P2 pkg/sql/plan/explain/sql_json.go:951: EXPLAIN FORMAT=JSON UPDATE nation n JOIN region r ON n.n_regionkey = r.r_regionkey SET n.n_regionkey = 2, r.r_name = 'changed'; updating two aliases of the same table also reproduces the failure.
    Impact: Previously accepted JSON EXPLAIN statements now fail with "cannot resolve row-image expression for column n_nationkey". Handle producer-specific outputs before treating unnamed references as malformed, and add multi-target planner regressions.
    Evidence: The new recursion assumes every unnamed column references a child projection. The real multi-target plan reaches a SINK_SCAN output with SourceStep but no children; the self-join variant reaches an aggregate output at RelPos=-2. Neither resolves through the implemented lookup. Both queries optimize successfully, then fail rendering in TestReviewSharedDMLAndDistinctProducers. Identical tests pass with only the merge-base formatter substituted. Candidate receipt: checks/1791955864330931951-3.json (exit 1); baseline control: checks/1791955901730202330-5.json (exit 0). Logs: shared-probe.jsonl and base-shared-probe.jsonl.

Validation:

  • All changed unit regressions and eight additional UPDATE producer-shape probes passed. INSERT, REPLACE, ON DUPLICATE and DISTINCT controls also passed.

  • Isolation preflight passed. Verified compatibility of 192 native build inputs and 62 retained artifacts before testing.

  • Commands, source fingerprints, overlays, exit receipts and logs were reconciled in /home/xupeng/.local/state/mo-bot/jobs/9e973011225a06ca4c953c15/attempt-1/validation-summary.json. Source remained unchanged.

  • Reviewed exact-head green CI statuses and author validation claims. Added traversal/allocation affects JSON EXPLAIN, not normal SQL execution; no performance benchmark was run.

Limitations:

  • Local reproduction uses production parser, optimizer and renderer entry points, not a fresh network client. Baseline control substitutes only sql_json.go.

  • Raw CI/author logs and the linked issue's full body were not supplied; local_validation was empty.

  • Source review is complete. Corrected multi-target rendering and corresponding SQL regressions require validation before approval.

@aptend aptend 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 re-review of exact head 9e5084e35bda23d1ef8eef719d6cf8a528de8947, base/merge-base fcad62a8ff06000e682824802f1155cbeea02a2f: APPROVE. No actionable blocker found.

Read the complete five-file delta, the prior REQUEST_CHANGES at 93673814b48e7d205b9dc518c0812fbc9b068efb, its incremental repair, all conversation comments and #30130. There are no inline comments or review threads. This is a focused repair to the existing accepted JSON EXPLAIN contract; the display-only UNION lineage clarification matches the implementation.

The prior multi-target blocker is closed: SINK_SCAN now follows its source step, AGG handles pruned grouping/aggregate slots, WINDOW resolves its output in producer context, and UNION preserves both branch alternatives instead of selecting one. I checked planner remapping conventions and the public EXPLAIN caller. Child-relative inputs, logical binding fallback, named terminals, function/list/window containers, cycles, malformed inputs and cancellation were inspected. Expansion clones expression containers and does not rewrite the execution plan or change the result schema. There is no new background work, shared cache, resource owner or wait protocol.

Independent exact-head validation in a detached worktree with CGO enabled:

  • Full explain package passed: 137 roots / 410 named results, no skips, 0.234s. Committed planner tests cover both prior failures (different tables and two aliases of one table).
  • Nine additional real parser/optimizer/renderer UPDATE shapes passed, including multi-target joins, arithmetic/COALESCE/CASE, grouped and window-derived inputs, UNION ALL, CTEs and a scalar aggregate subquery. The plan was byte-identical before/after rendering.
  • The unchanged canonical mo-tester normal comparison path ran the complete optimizer/explain_format_json.sql twice against an owned native single-CN LOG/TN/CN fixture: 134/134 successful statements each, zero failed/ignored/abnormal. This includes constant/arithmetic/NULL/prepared assignments, both multi-target cases, no-write observations and actual UPDATE result controls. Database teardown was independently checked after each round.
  • A bounded real-planner CTE-chain probe at depths 4/8/12/16 did not reproduce the suspected expansion-growth issue; depth 16 was 873 SQL bytes, 25 plan nodes and 6,925 JSON bytes. This is a scoped control, not a general performance guarantee.
  • Initial local harness-only password/default-database/result-path errors were corrected before the qualifying BVT run. The pinned active runner JAR SHA256 is f60ecd676ba52b8ea6b2d4f79130257929bab6057378141c90ce25aa30166a8c. Final BVT log SHA256: 9fdf5467ca774064c93ab15b51baff1e5175ea0631c68575bc85ef30519e527d.
  • Canonical wrapper verified matching primary native artifacts read-only; both temporary probe files were removed, gofmt/diff checks pass, and tracked source is unchanged.

At final check, exact-head shared build, ARM64 SCA, coverage, PROXY and PESSIMISTIC BVT were successful; Ubuntu UT was still in progress. Pending/skipped checks are not counted as passes. No general EXPLAIN performance benchmark or new mixed-version qualification is claimed.

@XuPeng-SH

XuPeng-SH commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 9e5084e35bda23d1ef8eef719d6cf8a528de8947

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: 9e5084e35bda23d1ef8eef719d6cf8a528de8947

Assessment: request_changes

Reviewed the complete five-file delta and affected callers. Keeping expansion in the EXPLAIN renderer is appropriate, and the prior multi-target failures are addressed. However, the new recursion rejects valid UPDATE assignments that consume MARK-join outputs.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-8e48-7622-ad17-b605f08450ce · slot 1 · generation 0

  • P2 pkg/sql/plan/explain/sql_json.go:1025: EXPLAIN FORMAT=JSON UPDATE nation n SET n_regionkey = CASE WHEN EXISTS (SELECT 1 FROM region r WHERE r.r_regionkey = n.n_regionkey) THEN 1 ELSE 0 END; CASE WHEN n.n_regionkey IN (SELECT r_regionkey FROM region) reproduces the same failure.
    Impact: Previously accepted JSON EXPLAIN statements now fail with "cannot resolve row-image expression for column n_regionkey". Resolve the MARK join's generated output in its producer context and add planner/public SQL regressions.
    Evidence: Both queries optimize successfully, but recursive expansion reaches an unnamed MARK output at RelPos=-1, ColPos=0, which resolveUpdateRef cannot handle. Candidate receipt checks/1791971002967599070-2.json records exit 1 with both failures; constant and composite-primary-key controls pass. Identical probes pass with the merge-base formatter: checks/1791971036055385934-2.json, exit 0. Retained logs: special-slots.jsonl and base-special-slots.jsonl.

Validation:

  • Committed explain package passed all 410 named results, with no skips; receipt checks/1791971074513477717-2.json. Its coverage misses the reproduced MARK-output cases.

  • Isolation preflight passed. Verified 192 native inputs and 62 retained artifacts against build-owner receipts and logs before testing.

  • Verified frozen source identity, clean checkout, diff formatting and correspondence of all 134 SQL/result statements. Fixture correspondence is a static check.

  • Reviewed current-head successful UT, SCA, coverage and complementary BVT statuses. Author and independent-review reports describe two successful public SQL regression runs.

  • Commands, source fingerprints, overlays, receipts and retained logs are reconciled in /home/xupeng/.local/state/mo-bot/jobs/2615c30f2ad9b8fa6da5346a/attempt-1/validation-summary.json.

Limitations:

  • Local reproduction uses production parser, optimizer and renderer with a mock catalog, not a fresh network SQL client. The baseline control substitutes the formatter and matching original test file.

  • Raw author/CI logs and the linked issue's full text were not supplied.

  • Added traversal and allocation are confined to JSON EXPLAIN rendering. No general performance benchmark was run.

@XuPeng-SH

XuPeng-SH commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: d0187a3ae3273f14da30de5013348ba94714aaca

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: d0187a3ae3273f14da30de5013348ba94714aaca

Assessment: approve

Reviewed the complete five-file delta and affected callers. Producer-aware resolution appropriately belongs in the existing EXPLAIN renderer. It closes the prior multi-target and MARK-output failures while preserving plan immutability, JSON schema compatibility and three-valued marker semantics. No actionable findings remain. Additional traversal and allocation are confined to JSON EXPLAIN.

Model: gpt-6-astra / xhigh

Session: 01a12d8f-7dea-77c2-a565-38d45b5564e4 · slot 0 · generation 0

Validation:

  • Full explain package plus 13 supplemental planner cases passed: 140 test roots, 438 named passes, no skips. Coverage includes combined multi-target MARK joins, recursive/sample/window sources and INSERT/REPLACE/upsert controls. Receipt: checks/1791998458852950131-2.json; log: explain-v2-check.log.

  • The initial diagnostic run rejected two exploratory queries during optimization, before the changed renderer. Corrected non-target-table inputs passed; the unsuccessful run remains recorded separately.

  • Isolation preflight passed. Verified 192 native inputs and 62 retained artifacts against build-owner evidence. Source remained unchanged.

  • Verified all 155 SQL statement lines correspond to result entries. Frozen exact-head CI reports successful UT, SCA, coverage and complementary BVT checks; the author reports two successful public SQL comparison runs.

  • Commands, source fingerprints, receipts, logs and artifact hashes are reconciled in /home/xupeng/.local/state/mo-bot/jobs/3265dfc8647d4d5a940bc4fa/attempt-1/review-evidence.json. Final audit receipt: checks/1791998566405836675-2.json.

Limitations:

  • Supplemental checks use the production parser, optimizer and renderer with a mock catalog. No fresh local mo-tester run was performed; raw author/CI execution logs were not supplied.

  • The linked issue’s full body was unavailable. No general performance benchmark was run; rendering cost can grow with expanded lineage.

@mergify mergify Bot added the queued label Oct 14, 2026
@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-14 17:25 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-10-14 17:37 UTC · at ef2d08d2a066f67439a5a313623186ded257fbd0

This pull request spent 12 minutes 22 seconds in the queue, with no time running CI.

Reason

Pull request #30139 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — ef2d08d2 Deployed Oct 14, 2026 by mergify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

4 participants