Skip to content

[Bug]: Optimizer still uses indexes marked INVISIBLE #26862

Closed as not planned
Closed as not planned

Description

@Ariznawlll

Version

main at 0676200da47052659cf46ad9e22d67ab9654e393

Environment

Local standalone mo-service (1 CN / 1 TN / 1 Log service), MySQL text protocol.

Reproduction

create database repro;
use repro;

create table t(id int primary key, a int, key idx_a(a));
insert into t select result, result from generate_series(1,10000) g;

alter table t alter index idx_a invisible;
show index from t;
explain select * from t where a=5000;

Actual result

SHOW INDEX correctly reports idx_a as Visible = NO, but EXPLAIN still selects it:

Project
  -> Index Table Scan on t.idx_a
       Filter Cond: prefix_eq(__mo_index_idx_col)

Reproduced on three independent tables from a new client connection. The invisible plan choice also persists after a full service restart, so it is not a stale session plan cache.

Invisible UNIQUE indexes correctly continue enforcing uniqueness; the issue is optimizer eligibility, not index maintenance.

Expected result

The optimizer should not select an invisible index by default. Making it visible again should restore its eligibility.

Suspected cause

ALTER updates IndexDef.Visible/mo_indexes.is_visible, but the query planner's index-selection paths do not appear to inspect the visibility flag.

Activity

  1. added this to the MO-202608 milestone on Aug 9, 2026
  2. added
    kind/bug
    on Aug 9, 2026
  3. added theissue type on Aug 9, 2026
  4. self-assigned this
    on Aug 9, 2026
  5. added a commit that references this issue on Aug 10, 2026
    6042ca6
  6. slyunnn commented on Aug 13, 2026

    @slyunnn

    Optimizer still uses indexes marked INVISIBLE

    Verification Environment

    • MatrixOne branch and commit: main / 1d7b631
    • MOTR branch and commit: test/issue-26862-invisible-index-planner / none
    • Related fix: PR fix(plan): honor invisible indexes in optimizer #26881, commit 6042ca6
    • Topology: local standalone mo-service with 1 CN, 1 TN, and 1 Log service; MySQL text protocol.
    • Not covered: multi-CN deployment, restart persistence, and external MySQL execution.

    Reproduction Result

    • Original scenario: Still reproducible.

    • Evidence: after ALTER TABLE t ALTER INDEX idx_a INVISIBLE, SHOW INDEX reported Visible=NO, but EXPLAIN SELECT * FROM
      t WHERE a=50 still contained Index Table Scan on t.idx_a.

    • Query result: the selective lookup correctly returned row (5,50,'five'), but it used the invisible index.

    • Reproduction frequency: reproduced in the local standalone verification.

    • Expected behavior: an invisible secondary index must be excluded from normal optimizer candidates; making it visible
      again should restore eligibility.

    Findings

    • The related fix is merged into the verified MatrixOne version: Yes.

    • Current behavior: index visibility metadata is persisted correctly, but the optimizer still selects the invisible
      secondary index.

    • Possible cause: at least one normal index-selection path does not apply the persisted visibility eligibility check
      introduced by PR fix(plan): honor invisible indexes in optimizer #26881.

    • Unrelated noise: invisible UNIQUE index enforcement remains correct; duplicate insertion returned ERROR 1062. This
      is expected maintenance behavior and does not resolve the optimizer eligibility defect.

  7. XuPeng-SH commented on Aug 13, 2026

    @XuPeng-SH
    Contributor

    not needed

  8. added 3 commits that reference this issue on Sep 17, 2026
    89acc50
    b635445
    c71a598
  9. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    Reopening: this reproduces again on current main (3ad9adbb4c, 2026-10-22) with the exact SQL from the original report.

    create database repro; use repro;
    create table t(id int primary key, a int, key idx_a(a));
    insert into t select result, result from generate_series(1,10000) g;
    alter table t alter index idx_a invisible;
    show index from t;

    SHOW INDEX reports Visible = NO for idx_a:

    t | 0 | PRIMARY | 1 | id   | A | ... | YES | id
    t | 1 | idx_a   | 1 | a    | A | ... | NO  | a
    

    information_schema.statistics.is_visible also returns NO. The planner nevertheless keeps it:

    Project
      ->  Index Table Scan on t.idx_a
            Filter Cond: prefix_eq(__mo_index_idx_col)
    

    Two additional data points:

    • create index idx_b on t(a) invisible behaves identically — explain select * from t where a=5000 plans Index Table Scan on t.idx_b, so it is not specific to the ALTER INDEX ... INVISIBLE path.
    • After a full service restart the catalog still reports is_visible = NO and the plan still uses idx_b, so this is not a stale session or plan cache.

    White-box: the only consumers of index visibility in the planner are pkg/sql/plan/build_show_util.go:292/372/450 — i.e. the SHOW rendering path. Nothing in index selection (apply_indices.go / query_builder.go) filters candidates by IndexOption_Visibility, which matches the observed behaviour: the flag is stored, reported, and ignored when choosing an access path.

  10. XuPeng-SH commented on Oct 23, 2026

    @XuPeng-SH
    Contributor

    Closing again — I reopened this by mistake. Maintainers confirm that invisible indexes being metadata-only in MatrixOne is an intentional design decision, not a defect: INVISIBLE is reported by SHOW INDEX / information_schema.statistics and does not filter optimizer access-path candidates. The behaviour I observed is therefore expected, and the planner-side opt-in was tracked separately in #26947.

    My measurements above stand as a description of current behaviour; they are not a regression claim. Apologies for the noise.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions