Skip to content

fix: evaluate timestamp-dependent virtual columns in reader time zone - #31268

Merged
XuPeng-SH merged 37 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/issue-28140-virtual-timestamp-tz
Nov 2, 2026
Merged

XuPeng-SH merged 37 commits into
matrixorigin:mainfrom
jiangxinmeng1:fix/issue-28140-virtual-timestamp-tz

Conversation

@jiangxinmeng1

@jiangxinmeng1 jiangxinmeng1 commented Oct 26, 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 #28140

What this PR does / why we need it:

A VIRTUAL DATE(ts) column was materialized at write time. Reading it in another session time zone returned the writer's date, and its persisted secondary-index key could make WHERE d = ... miss the row.

For SELECT, the planner evaluates TIMESTAMP-dependent VIRTUAL columns from the base row in the reader's session and excludes their persisted index keys from read access paths, including forced and covering indexes. UPDATE and DELETE retain physical old values for index maintenance. Generated-column dependency classification is memoized.

Read-expression expansion has a 65,536-node bound for new schemas. CREATE and ALTER reject final schemas whose affected generated-column graph exceeds that bound. Older catalogs above the bound use dependency-ordered projection stages so SELECT can evaluate each virtual column once per row without exponential inlining. The read-only, all-tenant preflight in test/manual/issue28140 reports affected catalogs before rollout; freeze generated-column DDL and rerun it before the all-CN cutover.

Original remote validation at [email protected] against upstream/main (83c1e23526):

  • Planner tests passed for dependency classification, index eligibility, expansion bounds, and DDL admission.
  • Embedded SQL integration passed for cross-zone SELECT/WHERE, default/FORCE/IGNORE index hints, prepared statements, view, CTAS, grouping, join, correlated query, cross-zone UPDATE/DELETE, and CREATE/ALTER admission.
  • Warm full-scan comparison at 16,384 and 131,072 rows: generated-column query took 1.03x and 0.99x the explicit DATE(ts) control; reported maximum operator memory matched at 144 KiB and 256 KiB.
  • Read-only preflight passed on the remote release catalog (1 account, 167 tables, 1,736 columns); an isolated legacy oversized graph was detected and cleaned up. This checks the preflight against the release catalog, not the new DDL runtime.
  • A distributed BVT fixture is included; standalone mo-tester execution remains for CI.

CI follow-up on 2026-10-27: merged upstream/main (2465dae7a4) into this branch, including its fix for the temporary-table/ISCP scheduling race seen in the earlier UT run. Scoped the preflight catalog result sets with deferred Close calls to satisfy sqlclosecheck, and added SQL-mock coverage of successful scans, malformed catalog rows, query errors, and result-set cleanup. On the remote host, make -j2 cgo, the targeted preflight tests (77.1% package coverage), the VIRTUAL TIMESTAMP planner tests, and the embedded SQL integration tests for VIRTUAL TIMESTAMP and temporary-table isolation all passed. CI run 40445486715 passed, including SCA, x86 UT, both enabled multi-CN BVT jobs, changed-code coverage (192/246 lines, 78.05% against the 75% threshold), and CI Required.

Existing UNIQUE indexes on VIRTUAL columns enforce writer-time stored values; SELECT now exposes those same values, including through dependent columns. Session-dependent uniqueness requires a separate versioned constraint policy. Sequential UPDATE keeps raw ENUM/SET storage values in its current-row projection, including empty-label ENUM definitions. Corrected SELECT behavior begins after all serving CNs are upgraded and old prepared plans are recreated. Affected nonunique queries may use a base scan instead of the old index lookup.

CI follow-up on 2026-10-30: merged upstream/main at d39d8a4034. The previous x86 UT failed only in TestPKCheckReconnectRollsBackAndFreshTxnSucceeds: its single logtail barrier could precede the parked transaction snapshot because no later commit was required. The fixture now commits on an independent table after the DELETE is parked, then acquires the barrier, making the asserted timestamp order a consequence of the commit order. Exact-head validation is in progress.

@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 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: d468ce05d6be876ceb588a5fe0fe2136d1c3f5ba

Assessment: request_changes

Earlier findings have fixes and regression coverage. One new sequential UPDATE regression remains for supported empty-label ENUM definitions.

Model: gpt-6-astra / xhigh

Session: 01a1869d-999c-7481-b340-ae4a63e8cee4 · slot 1 · generation 2

  • P2 pkg/sql/plan/virtual_timestamp_read.go:178: Define p ENUM('','a') and h VARCHAR(32) AS(CONCAT(p,':',DATE(ts))) VIRTUAL, where ts is TIMESTAMP. UPDATE t SET x=h succeeds, but UPDATE t SET x=h,y=1 fails, even without changing time zones.
    Impact: Adding an unrelated assignment makes a previously valid UPDATE fail with error 20105. Preserve lossless ENUM/SET storage values through the sequential current-row projection instead of rejecting supported definitions after display conversion, and add regression coverage.
    Evidence: empty-enum-head.log:1263-1272 reproduces the rejection; the reversible-ENUM control passes. The identical merge-base production-overlay probe passes both cases in empty-enum-base.log:1112-1114. Receipts: 1793267422437884744-2.json (exit 1) and 1793267498669401322-3.json (exit 0).

Validation:

  • Reviewed the complete 21-file delta, linked issue and all nine discussion items; saved discussion-assessment.json.

  • Isolation preflight and repository-owned native build passed. Verified 193 native inputs and retained artifact hashes.

  • Public SQL candidate/control probes confirmed the regression. Logs and receipts are mapped in attempt-1/review-audit.json.

  • Final source, overlay, discussion and evidence audit passed: checks/1793267659718697322-2.json. Source remains unchanged.

  • Supplied exact-head CI reports successful UT, SCA and enabled BVT checks.

Limitations:

  • No full-suite rerun, live catalog preflight or independent throughput benchmark; raw author benchmark and CI logs were not supplied.

  • Writer-time UNIQUE enforcement and affected-index scan fallback remain accepted scope limits.

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

Request changes. The SELECT correction is useful, but the current approach breaks supported persisted-schema compatibility and makes an existing UNIQUE constraint inconsistent with the values visible to SQL. These findings follow from the changed planner/DML paths and documented contract; I did not run a separate local server reproduction. CI is passing on this head.

Comment thread pkg/sql/plan/virtual_timestamp_read.go Resolved
@XuPeng-SH

XuPeng-SH commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: d468ce05d6be876ceb588a5fe0fe2136d1c3f5ba

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

Assessment: request_changes

Three concerns remain: persisted-expression compatibility, UNIQUE/read consistency, and the previously reproduced empty-label ENUM regression. Earlier binding defects have targeted fixes. The later concrete counterexample warrants revisiting the previously accepted UNIQUE scope exclusion.

Model: gpt-6-astra / xhigh

Session: 01a1869d-999c-7481-b340-ae4a63e8cee4 · slot 1 · generation 2

  • P2 pkg/sql/plan/virtual_timestamp_read.go:67: An existing catalog contains a valid TIMESTAMP-dependent generated-column DAG whose expanded tree exceeds 65,536 nodes; repeated references can reach this limit with fewer than 20 columns.
    Impact: SELECT now rejects the persisted expression. Mandatory manual schema rewriting or deferring upgrade does not satisfy the repository's persisted-state compatibility contract. Preserve bounded DAG evaluation or provide a compatible representation/migration, with predecessor-catalog regression coverage.
    Evidence: upgrade-compatibility.md:49-55 requires older persisted expressions to remain readable. The design explicitly acknowledges historical oversized catalogs at lines 17-19. Current expansion returns NotSupported; preflight only detects the incompatibility. This is a structural compatibility finding, not an observed released-cluster outage.

  • P2 docs/design/issue-28140-virtual-timestamp-timezone.md:7: With UNIQUE(d) on virtual DATE(ts), insert February 29 23:30 at +00:00, then March 1 09:00 at +08:00.
    Impact: Distinct writer-time keys permit both rows, but the new SELECT semantics expose March 1 for both at +08:00. Preserve coherent enforced/read values for affected UNIQUE columns or introduce a compatible constraint policy before activating their new read semantics. Cover the cross-zone case through public SQL.
    Evidence: bind_insert.go:5571 evaluates generated write values; its unique-key path compares persisted keys. base_binder.go:749 recomputes reads regardless of UNIQUE membership. The supplied two-row counterexample establishes a new constraint/read mismatch despite the documented scope exclusion; see source-assessment.md.

  • P2 pkg/sql/plan/virtual_timestamp_read.go:178: Define p ENUM('','a') and h AS CONCAT(p,':',DATE(ts)) VIRTUAL, then compare UPDATE SET x=h with UPDATE SET x=h,y=1.
    Impact: Adding an unrelated assignment makes a valid UPDATE fail with error 20105, even without changing time zones. Carry lossless ENUM/SET storage values through the sequential projection instead of rejecting supported definitions after display conversion.
    Evidence: Reconciled exact-head public SQL evidence: reused/empty-enum-head.log fails the empty-label case while its reversible control passes; reused/empty-enum-base.log passes both. Receipts 1793267422437884744-2.json and 1793267498669401322-3.json record exits 1 and 0 respectively.

Validation:

  • Read the complete 21-file delta and all 14 discussion entries; saved review-plan.md, source-assessment.md and discussion-assessment.json.

  • Verified cited exact-head execution provenance, overlays, 193 native inputs, artifact hashes, receipts and retained logs; reused completed evidence without rerunning tests.

  • Current evidence audit passed: review-audit.log and checks/1793289153762095149-2.json, exit 0. Source remains unchanged.

  • Frozen exact-head CI reports successful UT, SCA and enabled BVT checks.

Limitations:

  • Compatibility and UNIQUE findings use source/contract reasoning; no new released-binary upgrade or UNIQUE SQL reproduction was executed.

  • Further dependent validation stopped at the design blockers. No full-suite rerun, live catalog sweep or independent throughput benchmark was performed.

@XuPeng-SH

XuPeng-SH commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 60bfe782ab4b14adb038b94d350d97ad0d1af969

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: 60bfe782ab4b14adb038b94d350d97ad0d1af969

Assessment: request_changes

Earlier join, UNIQUE, ENUM and allocation findings have fixes. Legacy compatibility remains incomplete for sequential UPDATE, and preflight still imposes the obsolete schema-rewrite requirement.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

  • P2 pkg/sql/plan/bind_update.go:389: Read an oversized historical virtual-column DAG in a sequential UPDATE, such as SET val=g17,updated_at=now(), where g0=YEAR(ts) and each subsequent column doubles its predecessor.
    Impact: The new current-row binding re-enters bounded expression inlining and rejects the statement, although SELECT and single-assignment UPDATE succeed. Integrate bounded DAG evaluation with sequential current-row projections, preserving physical OLD values and earlier assignment effects.
    Evidence: planner-probe-v3.log:22 reproduces NotSupported at the 65,536-node limit. SELECT, single-assignment UPDATE and a smaller-DAG sequential control pass. Receipt checks/1793350187036883069-4.json exits 1. virtual_timestamp_read.go:46-72 explains why the fresh binding bypasses staging.

  • P2 test/manual/issue28140/preflight.go:201: The required preflight encounters a valid oversized legacy DAG supported by the new staged-evaluation path.
    Impact: It still fails and instructs operators to defer upgrading until the schema is rewritten. Align the tool and README with staged evaluation: distinguish capacity advisories from invalid metadata instead of requiring migration of every oversized schema.
    Evidence: preflight.go:200-201 and README.md:13-15 explicitly block cutover pending rewriting. The updated design document:17-19 supports these catalogs through staged projections and performance review; the historical SELECT planner regression passes.

Validation:

  • Reviewed all 24 changed files, linked issue #28140 and all 16 discussion records; saved review-plan.md and discussion-assessment.json.

  • Isolation preflight and fresh repository-owned native build passed; verified 191 native inputs and seven artifact hashes.

  • Five maintained planner test roots and three diagnostic controls passed. The corrected legacy UPDATE probe reproduced the finding; earlier invalid diagnostic fixtures are excluded in validation-results.json.

  • Frozen exact-head CI reports successful UT, SCA and enabled multi-CN BVT checks.

  • Final audit passed with unchanged source: checks/1793350265986877242-4.json. Receipts and logs are retained under the assigned attempt-1 directory.

Limitations:

  • The reproduction exercises SQL parsing, binding and optimization against a legacy-catalog fixture, not a live predecessor-binary upgrade.

  • No full-suite rerun, live catalog sweep or independent performance benchmark was performed; raw author benchmark and CI logs were not supplied.

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: cfb626eba715ed76e84ee354046952ee0f0853d4

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

Assessment: request_changes

Prior reported defects are addressed, but staged sequential UPDATE introduces an OLD-index-key regression for supported historical oversized generated-column graphs.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

  • P2 pkg/sql/plan/bind_update.go:293: A historical oversized virtual DAG—g0=YEAR(ts), followed by doubling dependencies through g17—with a nonunique index on g0 receives UPDATE SET val=g0, updated_at=NOW() in a timezone where g0 differs from its stored value.
    Impact: Staging overwrites the generated slots still referenced by oldColName2Idx. The subsequent old-index INNER JOIN uses the recomputed key and can silently discard rows that should be updated. For example, a timestamp written as 2023-12-31 23:30 at +00:00 has stored g0=2023 but recomputes to 2024 at +08:00.
    Evidence: The complete bindUpdate probe confirms physical g0 provenance for the depth-3 control, but recomputed YEAR(ts) provenance for depth 17 (full-binder-probe.log). Lines 1119–1127 save the staged value as OLD; lines 2095–2147 consume it in the index lookup. Preserve physical generated OLD values independently of current write destinations, and add an indexed legacy multi-assignment regression covering affected rows and index maintenance.

Validation:

  • Isolation preflight and native build passed; receipts 1793589607014416392-3 and 1793589688070291294-5 match retained logs.

  • Five maintained planner tests and four preflight/audit tests passed. The added OLD-provenance diagnostic failed at depth 17 and passed at depth 3; focused-probe.log, receipt 1793590006872606955-3, overall exit 1.

  • Complete UPDATE binder/index-lookup diagnostic confirmed the same failure and passing control; full-binder-probe.log, receipt 1793590217732817092-3, exit 1.

  • Evidence audit passed: frozen patch identity, unchanged source, 193 native inputs, receipt/log correspondence and coverage of all 18 discussion keys; audit-evidence.log, receipt 1793590376902776191-4.

Limitations:

  • The new diagnostic verifies bound-plan provenance using mocked catalog metadata; the missed-update consequence follows from the INNER JOIN and was not executed against a database service.

  • No fresh live SQL integration, BVT, predecessor-binary upgrade, live catalog audit or performance benchmark was run.

  • Frozen CI metadata reports 13 successful, 14 skipped and 2 neutral checks; raw CI logs were unavailable.

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 045dfc754edff084e5bde6a6278b1adb88bbc7ad

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: 045dfc754edff084e5bde6a6278b1adb88bbc7ad

Assessment: request_changes

Previous planner findings are resolved. One P2 defect remains: the rollout preflight rejects healthy catalogs containing another session’s temporary table.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

  • P2 test/manual/issue28140/preflight.go:158: Run the system-account preflight while another session owns a valid temporary table.
    Impact: The table inventory hides that temporary table, but the column inventory includes its columns. This check incorrectly reports incomplete metadata and blocks the documented rollout procedure. Align the inventory visibility domains, preserve genuine missing-metadata detection, and add a two-session regression test.
    Evidence: The actual run() passed the baseline embedded catalog, then failed after another session created a temporary table: zero visible table rows versus three column rows. See focused-tests-retry.log:1058 and :1079–1090, with receipt checks/1793612307932605935-3.json. The session filter is applied to mo_tables in pkg/sql/plan/query_builder.go:14308.

Validation:

  • Reviewed the complete 23-file delta, linked issue, and all 20 discussion entries; saved review-plan.md and discussion-assessment.json.

  • Isolation preflight passed. Verified 193 native inputs and six retained library hashes before reuse.

  • Fourteen focused test roots passed, including public SQL integration and physical OLD-key provenance at DAG depths 3 and 17. Only the new temporary-table preflight diagnostic failed; the combined command correctly exited 1.

  • Initial dependency-download failures were recovered using the assigned cache. Final source, discussion coverage, receipts, and logs passed the audit recorded in evidence-audit.log and validation-evidence.json; source remained unchanged.

Limitations:

  • No fresh full-suite, multi-CN, released-binary upgrade, or performance run; supplied CI statuses were reviewed without raw CI logs.

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

Reviewed the planner changes, bounded expansion/staged legacy path, DML OLD/current-row separation, index admission and hint fallbacks, preflight, and SQL/unit regressions at this head. The repair consistently evaluates affected nonunique virtual columns in the reader session while retaining physical OLD values for maintenance; UNIQUE/STORED leaves and the all-serving-CNs/reprepare rollout boundary are explicit. Checked correlated references, JOIN USING and null extension, sequential UPDATE including ENUM storage, dependency-cost admission, and the legacy-DAG pushdown barrier. No actionable correctness finding. Reused the recorded remote SQL/performance evidence and current successful CI; no new local test run.

@XuPeng-SH

XuPeng-SH commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

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

Commit: 226c3623eab43755bd170980ab891417b6bac935

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: 226c3623eab43755bd170980ab891417b6bac935

Assessment: approve

The preflight now handles other sessions’ temporary tables while preserving visible-catalog integrity checks. The previous finding is resolved, and qualified evidence closes the unchanged planner scope. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a1869d-820c-7212-9788-aecfb86a4141 · slot 0 · generation 2

Validation:

  • Four preflight unit test roots and both maintained live tests passed through a test-owned embedded server. Two-session reproduction and owner/foreign visibility controls passed.

  • Reused ten passing planner and SQL test roots after verifying unchanged inputs and matching receipts and logs.

  • Verified isolation, 193 native inputs, six library hashes, all 23 changed paths and all 23 discussion entries. Source remained unchanged.

  • Retained commands, receipts and logs are indexed in the diagnostic directory’s validation-evidence.json.

Limitations:

  • No fresh full-suite, multi-CN, released-binary upgrade, production-catalog or performance run.

  • Supplied CI statuses were reviewed; raw CI logs were unavailable.

@mergify

mergify Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

🚫 Left the queue · pull request branch update failed

1 min in the queue, with no time running CI.

So far

  • ✅ Entered the queue Mon 2 Nov, 11:11 · rule main · triggered by rule Automatic queue on approval for main
  • 🚫 Left the queue 11:12 · 226c362

Reason

The pull request can't be updated

GitHub response: refusing to allow a GitHub App to create or update workflow .github/workflows/ci-scope-check.yml without workflows permission
GitHub only lets Mergify write to .github/workflows/ with the workflows permission. An organization owner can accept Mergify's pending permissions at https://dashboard.mergify.com/orgs/matrixorigin/repositories.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

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

  • Requeue this pull request

Times in UTC · dashboard · how the merge queue works

This branch was successfully deployed

No deployments
ci — 0bea6b08 Deployed Nov 2, 2026 by XuPeng-SH
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]: VIRTUAL generated DATE(TIMESTAMP) column ignores session time zone

5 participants