Skip to content

[RFC] functional indexes on deterministic expressions - #28156

Merged
XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-28053-functional-index-rfc
Sep 7, 2026
Merged

XuPeng-SH merged 4 commits into
matrixorigin:mainfrom
VioletQwQ-0:codex/issue-28053-functional-index-rfc

Conversation

@VioletQwQ-0

@VioletQwQ-0 VioletQwQ-0 commented Sep 4, 2026 •

Copy link
Copy Markdown
Collaborator

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #28053

What this PR does / why we need it:

This RFC defines the first functional-index contract for MatrixOne: deterministic scalar expressions lowered to owned hidden generated columns and maintained by the existing regular-index path.

It records the supported and rejected SQL surface, atomic DDL and rollback ownership, catalog/SHOW/checkpoint/clone behavior, optimizer matching, mixed-version gating, and the dependency on #28052 and #28090.

Validation:

  • Documentation-only change; git diff --check passes.
  • QA required: no for this RFC itself. The implementation PR remains QA-gated.

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

Design review of exact RFC head 86b6a1f62bb6e6a82fabe054c6d5c15b132ef51f: REQUEST_CHANGES before implementation.

[P1] Define session-invariant expression eligibility; the existing generated-column volatility check is insufficient

The supported-contract section at docs/rfcs/20260904_functional_indexes.md:43-55 relies on the generated-column binder and rejects volatile functions. The optimizer section at lines 102-110 then selects the index using structural expression identity plus a residual predicate. A persisted functional key requires a stronger invariant: the same base row must produce the same key during backfill, all future DML and every eligible query, regardless of session/CN evaluation settings.

A concrete counterexample under the proposed rules is an index on CAST(ts AS CHAR(19)) for a TIMESTAMP column. Current buildGeneratedColumnDef calls checkExprForVolatileFunc (pkg/sql/plan/build_util.go:767-770,843-855), which only tests CannotFold/IsRealTimeRelated. Ordinary CAST has neither flag (function/list_operator.go:2838), but timestampToOthers reads proc.GetSessionInfo().TimeZone and passes it to timestamp-to-string conversion (function/func_cast.go:2189-2222). Thus this expression is row-local and passes the cited binder's check while still being session-dependent.

Example failure path for the future implementation: backfill/write a row representing 2024-01-01 00:00:00 UTC under +00:00, storing key 2024-01-01 00:00:00; query under +08:00 with CAST(ts AS CHAR(19)) = '2024-01-01 08:00:00'. A table scan evaluates true, while the structurally identical expression-index lookup searches a key that was never stored and loses the row. The residual predicate cannot recover rows excluded by the index. Writes from sessions with different settings can also populate inconsistent keys within one index.

Please close this in the RFC rather than leaving “deterministic” undefined: specify a conservative accepted-expression rule that excludes session-dependent casts/functions (including transitive generated-column dependencies), or a persisted evaluation-context and query-eligibility contract that provably preserves SQL semantics. Merely evaluating the index in a fixed timezone is not sufficient if the query expression still uses its session timezone. Audit SQL-mode/collation-dependent evaluation under the same invariant and state how backfill, DML, restore and optimizer matching share it. Add a planned index-vs-table-scan oracle across different writer/query timezones and relevant session modes. The initial release may reject such expressions; broad support is not required.

The hidden generated-column lowering, exclusive column ownership, atomic copy-DDL direction, bounded first-release SQL surface and non-covering residual strategy are otherwise reasonable. This is a design-level counterexample based on the current reusable binder/kernel, not a claim that unimplemented functional-index SQL was executed. No production code changes are present in this PR; git diff --check passes. Resolve this semantic eligibility gap before treating the RFC as accepted, then validate the implementation separately. CI was not awaited.

@VioletQwQ-0

Copy link
Copy Markdown
Collaborator Author

Follow-up to XuPeng-SH's exact-head design review.

Exact head: d108491c6aa6a3ecec471011c469888f73ed9fc7
Base: 149219181f416e0fc8913c84b773c1034a69438b
Preflight diff hash: 033f297b17762d1299933a644687a0d8f71065661608a5a0105bec380efd4ad7

The RFC now defines a deny-by-default session-invariant eligibility contract:

  • The existing volatility check is no longer treated as sufficient; scalar functions and operators must come from an explicit session-independent allowlist.
  • Generated-column references are checked through their complete transitive dependency closure.
  • Session-dependent casts and functions are rejected, including CAST(ts AS CHAR(19)) when timestamp-to-text conversion reads the session timezone; SQL mode, connection charset/collation, locale, implicit coercion, and unknown-function dependencies are also fail-closed.
  • Backfill, DML, restore, and optimizer matching share the same resolved semantic attributes. Query-side eligibility is required, and a residual predicate cannot recover rows omitted by an incompatible key lookup.
  • The implementation validation plan now includes cross-timezone writer/query, SQL-mode/collation, restore, DML, and index-vs-table-scan oracle coverage.

Validation:

  • PASS semantic=PASS from the schema-v7 exact-content preflight validator.
  • Final worktree clean; git diff --check and RFC/Markdown structure checks pass.
  • BVT: N/A — documentation-only RFC. The implementation PR must add production-entry BVT cases and result assertions for the planned oracle matrix.

No runtime implementation or issue lifecycle change is included in this PR. Please re-review the exact head above.

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

Design re-review of exact head d108491c6aa6a3ecec471011c469888f73ed9fc7: approved. This is an RFC-only approval, not approval of an implementation that does not yet exist.

The previous session-dependent-key blocker is addressed at the right boundary. Eligibility is now deny-by-default and transitive through generated-column dependencies; both persisted-key evaluation and query matching must have fixed type/cast/charset/collation/error semantics. In particular, a foldable function is no longer treated as proof of session invariance, timezone-sensitive TIMESTAMP-to-text casts are rejected, and a residual predicate is explicitly not claimed to recover rows omitted by an incompatible lookup.

I reviewed the complete revised design: hidden generated-column ownership and namespace checks, atomic COPY/backfill and cleanup, DML reuse, exact-expression matching with a base-table join, restore validation, unsupported first-release cases, and cluster-capability gating. The bounded first release avoids introducing another expression evaluator and correctly leaves covering access, unique/composite indexes and wider equivalence rules out of scope. The copy rewrite, generated value and index storage costs are disclosed.

The planned validation compares index results with a forced-scan oracle across writers/query sessions, timezones, modes, DML paths and restore, and verifies rejection publishes no metadata. Those are appropriate implementation acceptance requirements rather than reasons to demand nonexistent runtime tests in this documentation PR. Implementation must reserve the then-next available MORPC capability; the historical v46 parenthetical is not an allocation to reuse.

Current head CI checks are all terminal, with successful applicable checks and skipped/neutral orchestration entries; no pending/failing check found. git diff --check passes. No production code changes or fresh native/race execution are part of this review. No confirmed design blocker remains.

@mergify mergify Bot added the queued label Sep 7, 2026
@mergify

mergify Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-07 11:52 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-07 12:07 UTC · at a77fd415e52a06d90328d91ba7e191020c56c235

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

Waiting for
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of: [🛡 GitHub branch protection]
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
All conditions
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / UT Test on Ubuntu/x86
    • check-skipped = Matrixone CI / UT Test on Ubuntu/x86
    • check-success = Matrixone CI / UT Test on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone CI / SCA Test on Linux/arm64
    • check-skipped = Matrixone CI / SCA Test on Linux/arm64
    • check-success = Matrixone CI / SCA Test on Linux/arm64
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-skipped = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
    • check-success = Matrixone Compose CI / multi cn e2e bvt test docker compose(PROXY)
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Utils CI / Coverage
    • check-skipped = Matrixone Utils CI / Coverage
    • check-success = Matrixone Utils CI / Coverage
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-skipped = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
    • check-success = Matrixone UT Coverage / UT Coverage on Ubuntu/x86
  • any of [🛡 GitHub branch protection]:
    • check-neutral = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-skipped = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
    • check-success = Matrixone Standlone CI / multi CN e2e BVT Test on Linux/x64(COMPOSE, PESSIMISTIC)
  • #review-threads-unresolved = 0 [🛡 GitHub branch protection]
  • github-review-approved [🛡 GitHub branch protection]

Reason

Pull request #28156 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.

Failing checks:

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.

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

  • Requeue this pull request

@XuPeng-SH
XuPeng-SH merged commit 665a17d into matrixorigin:main Sep 7, 2026
24 of 25 checks passed
@mergify mergify Bot added dequeued and removed queued labels Sep 7, 2026
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…8156)

## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [x] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#28053

## What this PR does / why we need it:

This RFC defines the first functional-index contract for MatrixOne:
deterministic scalar expressions lowered to owned hidden generated
columns and maintained by the existing regular-index path.

It records the supported and rejected SQL surface, atomic DDL and
rollback ownership, catalog/SHOW/checkpoint/clone behavior, optimizer
matching, mixed-version gating, and the dependency on matrixorigin#28052 and matrixorigin#28090.

Validation:
- Documentation-only change; `git diff --check` passes.
- QA required: no for this RFC itself. The implementation PR remains
QA-gated.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…8156)

## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [x] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#28053

## What this PR does / why we need it:

This RFC defines the first functional-index contract for MatrixOne:
deterministic scalar expressions lowered to owned hidden generated
columns and maintained by the existing regular-index path.

It records the supported and rejected SQL surface, atomic DDL and
rollback ownership, catalog/SHOW/checkpoint/clone behavior, optimizer
matching, mixed-version gating, and the dependency on matrixorigin#28052 and matrixorigin#28090.

Validation:
- Documentation-only change; `git diff --check` passes.
- QA required: no for this RFC itself. The implementation PR remains
QA-gated.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
VioletQwQ-0 added a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
…8156)

## What type of PR is this?

- [ ] API-change
- [ ] BUG
- [ ] Improvement
- [x] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

issue matrixorigin#28053

## What this PR does / why we need it:

This RFC defines the first functional-index contract for MatrixOne:
deterministic scalar expressions lowered to owned hidden generated
columns and maintained by the existing regular-index path.

It records the supported and rejected SQL surface, atomic DDL and
rollback ownership, catalog/SHOW/checkpoint/clone behavior, optimizer
matching, mixed-version gating, and the dependency on matrixorigin#28052 and matrixorigin#28090.

Validation:
- Documentation-only change; `git diff --check` passes.
- QA required: no for this RFC itself. The implementation PR remains
QA-gated.

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@VioletQwQ-0
VioletQwQ-0 deleted the codex/issue-28053-functional-index-rfc branch December 1, 2026 03:47

This branch was previously deployed

1 inactive deployment
ci — a77fd415 Deployed Sep 7, 2026 by mergify[bot] via Matrixone Utils CI / Coverage #51311
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/documentation Improvements or additions to documentation size/XS Denotes a PR that changes [1, 9] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants