Skip to content

fix(plan): always consider usable indexes - #26972

Merged
XuPeng-SH merged 1 commit into
mainfrom
fix/always-consider-usable-indexes
Aug 11, 2026
Merged

XuPeng-SH merged 1 commit into
mainfrom
fix/always-consider-usable-indexes

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What changed

Index visibility no longer participates in optimizer candidate eligibility. Every physically present, semantically applicable index is considered; the cost model and explicit index hints decide whether it is used.

This removes the visibility gating introduced by #26881 across:

  • regular, master, and spatial index discovery
  • fulltext index matching
  • vector direct-scan and logical multi-table index discovery
  • join and index-hint paths

It also removes the visibility initialization helper, propagation, and per-tenant reconciliation migration added by that PR.

Compatibility boundary

The historical IndexDef.visible field, mo_indexes.is_visible column, and accepted DDL syntax remain compatibility metadata only. They are not optimizer switches.

  • protobuf field 14 / visibility_set is removed and reserved, so its published wire identity cannot be reused
  • old field-14 data is accepted and preserved as unknown wire data
  • the consumed v4.0.6 upgrade offset remains reserved; persisted upgrade identity never moves backward
  • no catalog-wide normalization scan or ALTER replay is added

Nil IndexDef entries remain safely skipped after removing the old nil-tolerant visibility helper.

Performance

The planner hot paths remove visibility helper calls, vector visibility tracking maps, and candidate-filter slice allocation. There is no new scan, I/O, logging, cache, or background maintenance.

Validation

  • focused visibility, hint, regular-index, fulltext, vector, protobuf compatibility, catalog metadata, and upgrade-offset regressions
  • full owning-package tests:
    • ./pkg/bootstrap/versions/v4_0_6
    • ./pkg/publication
    • ./pkg/sql/colexec
    • ./pkg/sql/compile
    • ./pkg/sql/plan
  • go vet on the same owning packages
  • protobuf regenerated; git diff --check

Remove index visibility from optimizer candidate eligibility across regular, fulltext, vector, join, and hint paths. Retain legacy catalog and DDL metadata for compatibility, reserve the removed protobuf wire identity, and keep the consumed upgrade offset stable.
@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 merged commit c8c21ca into main Aug 11, 2026
32 checks passed
@XuPeng-SH
XuPeng-SH deleted the fix/always-consider-usable-indexes branch August 11, 2026 20:56
XuPeng-SH added a commit that referenced this pull request Aug 12, 2026
Follow-up to #26972. Removing the nil-tolerant optimizer visibility
filter exposed unchecked nil IndexDef dereferences, but blindly skipping
nil metadata on every path is not correct.

## Invariant and failure policy

Persisted engine metadata is dense: protobuf and constraint decoders
allocate an IndexDef for every stored entry. A nil entry therefore
represents incomplete in-memory metadata, not an optional physical
index.

- read-only discovery and display paths skip nil entries and keep
processing later valid indexes; the base table remains the authoritative
correctness fallback
- mutation, locking, clone, and index-lifecycle paths fail closed before
an unknown index can be omitted from maintenance, locking, copy,
truncate, rename, or drop work
- no metadata is compacted, guessed, repaired in the background, or
silently normalized

## What changed

Read-only closure:
- master, regular join, vector single-row, SHOW CREATE, SHOW COLUMNS,
PREPARE dependency, and index-size traversals tolerate nil entries
- later valid indexes and plugin hidden-table dependencies remain
eligible

Mutation closure:
- one dense-metadata validator is applied at the common DML target
boundary
- ALTER, RENAME, TRUNCATE, DROP TABLE, CREATE/DROP INDEX, CREATE TABLE
LIKE/CLONE, and foreign-key creation validate before lifecycle work
- SELECT FOR UPDATE/SHARE validates before hidden-index lock planning
- foreign-key unique-parent locking and cascaded child mutations
validate related table metadata before building their mutation work

## Compatibility

The 4.1-dev and 4.2-dev visibility compatibility surface remains
unchanged: protobuf field 8, mo_indexes.is_visible, accepted
VISIBLE/INVISIBLE syntax, ALTER behavior, and SHOW behavior are
preserved. Field 14 remains reserved as established by #26972. No wire,
catalog, migration, or persisted metadata changes are introduced.

## Performance and unhappy paths

Read-only traversals add one constant-time nil branch per visited index.
Mutation validation is a bounded O(number of indexes) planner-time scan
per resolved table boundary, with no allocations on the healthy path.
There is no row-level or batch-level work, catalog I/O, logging, retry
loop, background task, cache, or new resource ownership.

Invalid metadata returns one deterministic internal error. It is not
logged repeatedly and cannot proceed far enough to create index
divergence or orphan hidden tables.

## Validation

- deterministic RED reproductions for SHOW COLUMNS, SELECT FOR UPDATE,
DML/DDL mutation paths, foreign-key unique-parent locking, and
cascade-child mutation
- regressions for nil-before-valid filter, join, vector, SHOW
CREATE/COLUMNS, PREPARE, and plugin dependency paths
- INSERT, LOAD, REPLACE, UPDATE, DELETE, ALTER, RENAME, TRUNCATE, DROP,
CREATE/DROP INDEX, CREATE LIKE, and CLONE fail-closed matrix
- full pkg/sql/plan tests
- go list, go build, and go vet for pkg/sql/plan
- git diff --check
- rebased onto current main at 3f2ed9b
cpegeric added a commit to cpegeric/matrixone that referenced this pull request Aug 12, 2026
Conflicts in pkg/sql/plan/apply_indices_fulltext.go and build_ddl.go: main's
matrixorigin#26972 removes optimizer index-visibility gating (catalog.IsIndexOptimizerEligible,
setIndexDefsVisibility, and pkg/catalog/index_visibility.go are deleted), while
this branch had restructured the same lines for fulltext2. Resolved by keeping
the branch's fulltext2 storage-def selection and BuildSessionVars capture, and
taking main's removal of both visibility calls.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What changed

Index visibility no longer participates in optimizer candidate
eligibility. Every physically present, semantically applicable index is
considered; the cost model and explicit index hints decide whether it is
used.

This removes the visibility gating introduced by matrixorigin#26881 across:

- regular, master, and spatial index discovery
- fulltext index matching
- vector direct-scan and logical multi-table index discovery
- join and index-hint paths

It also removes the visibility initialization helper, propagation, and
per-tenant reconciliation migration added by that PR.

## Compatibility boundary

The historical `IndexDef.visible` field, `mo_indexes.is_visible` column,
and accepted DDL syntax remain compatibility metadata only. They are not
optimizer switches.

- protobuf field 14 / `visibility_set` is removed and reserved, so its
published wire identity cannot be reused
- old field-14 data is accepted and preserved as unknown wire data
- the consumed v4.0.6 upgrade offset remains reserved; persisted upgrade
identity never moves backward
- no catalog-wide normalization scan or ALTER replay is added

Nil `IndexDef` entries remain safely skipped after removing the old
nil-tolerant visibility helper.

## Performance

The planner hot paths remove visibility helper calls, vector visibility
tracking maps, and candidate-filter slice allocation. There is no new
scan, I/O, logging, cache, or background maintenance.

## Validation

- focused visibility, hint, regular-index, fulltext, vector, protobuf
compatibility, catalog metadata, and upgrade-offset regressions
- full owning-package tests:
  - `./pkg/bootstrap/versions/v4_0_6`
  - `./pkg/publication`
  - `./pkg/sql/colexec`
  - `./pkg/sql/compile`
  - `./pkg/sql/plan`
- `go vet` on the same owning packages
- protobuf regenerated; `git diff --check`
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Follow-up to matrixorigin#26972. Removing the nil-tolerant optimizer visibility
filter exposed unchecked nil IndexDef dereferences, but blindly skipping
nil metadata on every path is not correct.

## Invariant and failure policy

Persisted engine metadata is dense: protobuf and constraint decoders
allocate an IndexDef for every stored entry. A nil entry therefore
represents incomplete in-memory metadata, not an optional physical
index.

- read-only discovery and display paths skip nil entries and keep
processing later valid indexes; the base table remains the authoritative
correctness fallback
- mutation, locking, clone, and index-lifecycle paths fail closed before
an unknown index can be omitted from maintenance, locking, copy,
truncate, rename, or drop work
- no metadata is compacted, guessed, repaired in the background, or
silently normalized

## What changed

Read-only closure:
- master, regular join, vector single-row, SHOW CREATE, SHOW COLUMNS,
PREPARE dependency, and index-size traversals tolerate nil entries
- later valid indexes and plugin hidden-table dependencies remain
eligible

Mutation closure:
- one dense-metadata validator is applied at the common DML target
boundary
- ALTER, RENAME, TRUNCATE, DROP TABLE, CREATE/DROP INDEX, CREATE TABLE
LIKE/CLONE, and foreign-key creation validate before lifecycle work
- SELECT FOR UPDATE/SHARE validates before hidden-index lock planning
- foreign-key unique-parent locking and cascaded child mutations
validate related table metadata before building their mutation work

## Compatibility

The 4.1-dev and 4.2-dev visibility compatibility surface remains
unchanged: protobuf field 8, mo_indexes.is_visible, accepted
VISIBLE/INVISIBLE syntax, ALTER behavior, and SHOW behavior are
preserved. Field 14 remains reserved as established by matrixorigin#26972. No wire,
catalog, migration, or persisted metadata changes are introduced.

## Performance and unhappy paths

Read-only traversals add one constant-time nil branch per visited index.
Mutation validation is a bounded O(number of indexes) planner-time scan
per resolved table boundary, with no allocations on the healthy path.
There is no row-level or batch-level work, catalog I/O, logging, retry
loop, background task, cache, or new resource ownership.

Invalid metadata returns one deterministic internal error. It is not
logged repeatedly and cannot proceed far enough to create index
divergence or orphan hidden tables.

## Validation

- deterministic RED reproductions for SHOW COLUMNS, SELECT FOR UPDATE,
DML/DDL mutation paths, foreign-key unique-parent locking, and
cascade-child mutation
- regressions for nil-before-valid filter, join, vector, SHOW
CREATE/COLUMNS, PREPARE, and plugin dependency paths
- INSERT, LOAD, REPLACE, UPDATE, DELETE, ALTER, RENAME, TRUNCATE, DROP,
CREATE/DROP INDEX, CREATE LIKE, and CLONE fail-closed matrix
- full pkg/sql/plan tests
- go list, go build, and go vet for pkg/sql/plan
- git diff --check
- rebased onto current main at 3f2ed9b
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What changed

Index visibility no longer participates in optimizer candidate
eligibility. Every physically present, semantically applicable index is
considered; the cost model and explicit index hints decide whether it is
used.

This removes the visibility gating introduced by matrixorigin#26881 across:

- regular, master, and spatial index discovery
- fulltext index matching
- vector direct-scan and logical multi-table index discovery
- join and index-hint paths

It also removes the visibility initialization helper, propagation, and
per-tenant reconciliation migration added by that PR.

## Compatibility boundary

The historical `IndexDef.visible` field, `mo_indexes.is_visible` column,
and accepted DDL syntax remain compatibility metadata only. They are not
optimizer switches.

- protobuf field 14 / `visibility_set` is removed and reserved, so its
published wire identity cannot be reused
- old field-14 data is accepted and preserved as unknown wire data
- the consumed v4.0.6 upgrade offset remains reserved; persisted upgrade
identity never moves backward
- no catalog-wide normalization scan or ALTER replay is added

Nil `IndexDef` entries remain safely skipped after removing the old
nil-tolerant visibility helper.

## Performance

The planner hot paths remove visibility helper calls, vector visibility
tracking maps, and candidate-filter slice allocation. There is no new
scan, I/O, logging, cache, or background maintenance.

## Validation

- focused visibility, hint, regular-index, fulltext, vector, protobuf
compatibility, catalog metadata, and upgrade-offset regressions
- full owning-package tests:
  - `./pkg/bootstrap/versions/v4_0_6`
  - `./pkg/publication`
  - `./pkg/sql/colexec`
  - `./pkg/sql/compile`
  - `./pkg/sql/plan`
- `go vet` on the same owning packages
- protobuf regenerated; `git diff --check`
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Follow-up to matrixorigin#26972. Removing the nil-tolerant optimizer visibility
filter exposed unchecked nil IndexDef dereferences, but blindly skipping
nil metadata on every path is not correct.

## Invariant and failure policy

Persisted engine metadata is dense: protobuf and constraint decoders
allocate an IndexDef for every stored entry. A nil entry therefore
represents incomplete in-memory metadata, not an optional physical
index.

- read-only discovery and display paths skip nil entries and keep
processing later valid indexes; the base table remains the authoritative
correctness fallback
- mutation, locking, clone, and index-lifecycle paths fail closed before
an unknown index can be omitted from maintenance, locking, copy,
truncate, rename, or drop work
- no metadata is compacted, guessed, repaired in the background, or
silently normalized

## What changed

Read-only closure:
- master, regular join, vector single-row, SHOW CREATE, SHOW COLUMNS,
PREPARE dependency, and index-size traversals tolerate nil entries
- later valid indexes and plugin hidden-table dependencies remain
eligible

Mutation closure:
- one dense-metadata validator is applied at the common DML target
boundary
- ALTER, RENAME, TRUNCATE, DROP TABLE, CREATE/DROP INDEX, CREATE TABLE
LIKE/CLONE, and foreign-key creation validate before lifecycle work
- SELECT FOR UPDATE/SHARE validates before hidden-index lock planning
- foreign-key unique-parent locking and cascaded child mutations
validate related table metadata before building their mutation work

## Compatibility

The 4.1-dev and 4.2-dev visibility compatibility surface remains
unchanged: protobuf field 8, mo_indexes.is_visible, accepted
VISIBLE/INVISIBLE syntax, ALTER behavior, and SHOW behavior are
preserved. Field 14 remains reserved as established by matrixorigin#26972. No wire,
catalog, migration, or persisted metadata changes are introduced.

## Performance and unhappy paths

Read-only traversals add one constant-time nil branch per visited index.
Mutation validation is a bounded O(number of indexes) planner-time scan
per resolved table boundary, with no allocations on the healthy path.
There is no row-level or batch-level work, catalog I/O, logging, retry
loop, background task, cache, or new resource ownership.

Invalid metadata returns one deterministic internal error. It is not
logged repeatedly and cannot proceed far enough to create index
divergence or orphan hidden tables.

## Validation

- deterministic RED reproductions for SHOW COLUMNS, SELECT FOR UPDATE,
DML/DDL mutation paths, foreign-key unique-parent locking, and
cascade-child mutation
- regressions for nil-before-valid filter, join, vector, SHOW
CREATE/COLUMNS, PREPARE, and plugin dependency paths
- INSERT, LOAD, REPLACE, UPDATE, DELETE, ALTER, RENAME, TRUNCATE, DROP,
CREATE/DROP INDEX, CREATE LIKE, and CLONE fail-closed matrix
- full pkg/sql/plan tests
- go list, go build, and go vet for pkg/sql/plan
- git diff --check
- rebased onto current main at 3f2ed9b
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
## What changed

Index visibility no longer participates in optimizer candidate
eligibility. Every physically present, semantically applicable index is
considered; the cost model and explicit index hints decide whether it is
used.

This removes the visibility gating introduced by matrixorigin#26881 across:

- regular, master, and spatial index discovery
- fulltext index matching
- vector direct-scan and logical multi-table index discovery
- join and index-hint paths

It also removes the visibility initialization helper, propagation, and
per-tenant reconciliation migration added by that PR.

## Compatibility boundary

The historical `IndexDef.visible` field, `mo_indexes.is_visible` column,
and accepted DDL syntax remain compatibility metadata only. They are not
optimizer switches.

- protobuf field 14 / `visibility_set` is removed and reserved, so its
published wire identity cannot be reused
- old field-14 data is accepted and preserved as unknown wire data
- the consumed v4.0.6 upgrade offset remains reserved; persisted upgrade
identity never moves backward
- no catalog-wide normalization scan or ALTER replay is added

Nil `IndexDef` entries remain safely skipped after removing the old
nil-tolerant visibility helper.

## Performance

The planner hot paths remove visibility helper calls, vector visibility
tracking maps, and candidate-filter slice allocation. There is no new
scan, I/O, logging, cache, or background maintenance.

## Validation

- focused visibility, hint, regular-index, fulltext, vector, protobuf
compatibility, catalog metadata, and upgrade-offset regressions
- full owning-package tests:
  - `./pkg/bootstrap/versions/v4_0_6`
  - `./pkg/publication`
  - `./pkg/sql/colexec`
  - `./pkg/sql/compile`
  - `./pkg/sql/plan`
- `go vet` on the same owning packages
- protobuf regenerated; `git diff --check`
VioletQwQ-0 pushed a commit to VioletQwQ-0/matrixone that referenced this pull request Sep 17, 2026
Follow-up to matrixorigin#26972. Removing the nil-tolerant optimizer visibility
filter exposed unchecked nil IndexDef dereferences, but blindly skipping
nil metadata on every path is not correct.

## Invariant and failure policy

Persisted engine metadata is dense: protobuf and constraint decoders
allocate an IndexDef for every stored entry. A nil entry therefore
represents incomplete in-memory metadata, not an optional physical
index.

- read-only discovery and display paths skip nil entries and keep
processing later valid indexes; the base table remains the authoritative
correctness fallback
- mutation, locking, clone, and index-lifecycle paths fail closed before
an unknown index can be omitted from maintenance, locking, copy,
truncate, rename, or drop work
- no metadata is compacted, guessed, repaired in the background, or
silently normalized

## What changed

Read-only closure:
- master, regular join, vector single-row, SHOW CREATE, SHOW COLUMNS,
PREPARE dependency, and index-size traversals tolerate nil entries
- later valid indexes and plugin hidden-table dependencies remain
eligible

Mutation closure:
- one dense-metadata validator is applied at the common DML target
boundary
- ALTER, RENAME, TRUNCATE, DROP TABLE, CREATE/DROP INDEX, CREATE TABLE
LIKE/CLONE, and foreign-key creation validate before lifecycle work
- SELECT FOR UPDATE/SHARE validates before hidden-index lock planning
- foreign-key unique-parent locking and cascaded child mutations
validate related table metadata before building their mutation work

## Compatibility

The 4.1-dev and 4.2-dev visibility compatibility surface remains
unchanged: protobuf field 8, mo_indexes.is_visible, accepted
VISIBLE/INVISIBLE syntax, ALTER behavior, and SHOW behavior are
preserved. Field 14 remains reserved as established by matrixorigin#26972. No wire,
catalog, migration, or persisted metadata changes are introduced.

## Performance and unhappy paths

Read-only traversals add one constant-time nil branch per visited index.
Mutation validation is a bounded O(number of indexes) planner-time scan
per resolved table boundary, with no allocations on the healthy path.
There is no row-level or batch-level work, catalog I/O, logging, retry
loop, background task, cache, or new resource ownership.

Invalid metadata returns one deterministic internal error. It is not
logged repeatedly and cannot proceed far enough to create index
divergence or orphan hidden tables.

## Validation

- deterministic RED reproductions for SHOW COLUMNS, SELECT FOR UPDATE,
DML/DDL mutation paths, foreign-key unique-parent locking, and
cascade-child mutation
- regressions for nil-before-valid filter, join, vector, SHOW
CREATE/COLUMNS, PREPARE, and plugin dependency paths
- INSERT, LOAD, REPLACE, UPDATE, DELETE, ALTER, RENAME, TRUNCATE, DROP,
CREATE/DROP INDEX, CREATE LIKE, and CLONE fail-closed matrix
- full pkg/sql/plan tests
- go list, go build, and go vet for pkg/sql/plan
- git diff --check
- rebased onto current main at 3f2ed9b

This branch was previously deployed

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

Labels

size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants