Skip to content

[Bug]: table and database CLONE turn invisible indexes visible #27078

Closed

Description

@Ariznawlll

Description

Table-level and database-level CLONE, plus the adjacent CREATE TABLE ... LIKE ... path, silently change an INVISIBLE secondary index into a VISIBLE index. The rebuilt schema therefore does not preserve the source index visibility metadata and can change optimizer behavior.

Environment

  • Branch: main
  • Commit: 1d7b6311ce91df0968da435bb405f3d68137c595
  • Deployment: local single process, 1 Log Service + 1 TN + 1 CN
  • Test date: 2026-08-13

Steps to reproduce

DROP DATABASE IF EXISTS clone_invisible_index;
DROP DATABASE IF EXISTS clone_invisible_index_db_dst;
CREATE DATABASE clone_invisible_index;
USE clone_invisible_index;

CREATE TABLE src(id INT PRIMARY KEY, a VARCHAR(32), KEY idx_a(a));
INSERT INTO src VALUES (1, 'alpha'), (2, 'beta');
ALTER TABLE src ALTER INDEX idx_a INVISIBLE;
SHOW INDEX FROM src;

CREATE TABLE dst CLONE src;
SHOW INDEX FROM dst;

CREATE TABLE like_dst LIKE src;
SHOW INDEX FROM like_dst;

CREATE DATABASE clone_invisible_index_db_dst CLONE clone_invisible_index;
SHOW INDEX FROM clone_invisible_index_db_dst.src;

Actual behavior

The source index is invisible, but both clone paths recreate it as visible:

source src.idx_a:                        Visible = NO
table clone dst.idx_a:                   Visible = YES
CREATE TABLE LIKE like_dst.idx_a:         Visible = YES
database clone clone_invisible_index_db_dst.src.idx_a: Visible = YES

The cloned rows are otherwise correct ((1, alpha), (2, beta)).

Expected behavior

Table-level clone, database-level clone, and CREATE TABLE ... LIKE ... must preserve idx_a with Visible = NO, matching the source schema.

Stability and controls

  • Table-level reproducer: 3/3; every clone changed NO to YES.
  • Database-level reproducer: 3/3; every clone changed NO to YES.
  • CREATE TABLE LIKE reproducer: 3/3; every target changed NO to YES.
  • Normal control: a newly created index with no INVISIBLE alteration reports Visible = YES.
  • Data control: all source rows were present in the table clone.
  • Failure atomicity/data corruption: no row corruption observed; the failure is deterministic schema metadata loss.

Evidence

Exact result from the final run:

show index from src;
src  1  idx_a  1  a  ...  Visible=NO

create table dst clone src;
show index from dst;
dst  1  idx_a  1  a  ...  Visible=YES

create table like_dst like src;
show index from like_dst;
like_dst  1  idx_a  1  a  ...  Visible=YES

create database clone_invisible_index_db_dst clone clone_invisible_index;
show index from clone_invisible_index_db_dst.src;
src  1  idx_a  1  a  ...  Visible=YES

Minimal runnable SQL and generated output were saved during validation as:

/private/tmp/mo-clone-validation/cases/main_clone_invisible_index_repro.sql
/private/tmp/mo-clone-validation/cases/main_clone_invisible_index_repro.result

Code analysis

Confirmed data flow:

  1. pkg/sql/plan/build_ddl.go:1081-1099 rebuilds the CLONE/LIKE table plan by passing the source TableDef through constructCreateTableSQL, reparsing the generated SQL, and then calling buildCreateTable.
  2. pkg/sql/plan/build_show_util.go:334-423 serializes index name, algorithm, parts, prefix lengths, algorithm parameters, INCLUDE columns, and comments, but never serializes indexdef.Visible. The reparsed index consequently gets the default visibility (VISIBLE), losing the source value (false).
  3. Independently, pkg/sql/compile/util.go:305-306 writes every newly created index catalog row with the hard-coded INDEX_VISIBLE_YES instead of using indexDef.Visible. A complete fix must preserve visibility through both the reconstructed DDL/plan and the mo_indexes catalog insert.
  4. Database clone is affected because it delegates each source table to the same table-clone path.

The same serializer is shared by CREATE TABLE ... LIKE ...; that adjacent path is confirmed affected 3/3, not merely inferred.

Regression coverage

Add a distributed clone BVT under test/distributed/cases/git4data/clone/ that:

  1. creates one visible and one invisible secondary index;
  2. verifies table-level clone preserves both visibility values;
  3. verifies database-level clone preserves both visibility values;
  4. verifies rows and index-backed predicates still work;
  5. also checks CREATE TABLE ... LIKE ... because it uses the same serializer.

Related

Activity

  1. added this to the MO-202608 milestone on Aug 13, 2026
  2. added
    kind/bug
    on Aug 13, 2026
  3. added theissue type on Aug 13, 2026
  4. added
    severity/s0
    and removed on Aug 13, 2026
  5. added
    ai-easy
    on Aug 14, 2026
  6. added a commit that references this issue on Aug 14, 2026
    b189aa6
  7. gouhongshen commented on Aug 17, 2026

    @gouhongshen
    Contributor

    fixed by #27143

  8. added and removed
    severity/s0
    on Aug 17, 2026
  9. Ariznawlll commented on Aug 17, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    最新 main:484e1969531e7fbf7219b20e34d7ef23e110560b;本地隔离 DISK-V2 单 CN + TN + LogService。

    原问题验证

    原问题是 invisible secondary index 在 CLONE 后被错误恢复为 visible。最新 main 上源表 idx_v 的 information_schema.statistics.is_visible 为 NO,表 CLONE、LIKE 和 database CLONE 的对应索引均保持 NO。

    Happy Path 覆盖

    • 表 CLONE:索引可见性保持 NO,2 行数据保持不变。
    • LIKE:索引可见性保持 NO,并验证 LIKE 不复制数据(0 行)。
    • database CLONE:索引可见性保持 NO,2 行数据保持不变。

    Unhappy Path 覆盖

    该 issue 的失败形态是元数据复制错误,不涉及非法 SQL;本轮额外检查了三种复制入口及源表控制值,未发现状态漂移。

    白盒验证

    修复提交 b189aa6 已包含在测试版本中。

    回归测试

    已加入 MOTR PR #113,提交 69242f8 的 issue_27078_clone_invisible_index,3 轮 78 条语句全部通过。

    测试证据

    源表、表 CLONE、LIKE 和 database CLONE 的 idx_v 均输出 is_visible=NO;行数分别为 2、2、0、2。

    测试结论

    测试通过。

  10. added 3 commits that reference this issue on Sep 17, 2026
    e04904c
    db5aeda
    adc8cab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-easykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions