Repository navigation
Description
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 changedNOtoYES. - Database-level reproducer:
3/3; every clone changedNOtoYES. - CREATE TABLE LIKE reproducer:
3/3; every target changedNOtoYES. - Normal control: a newly created index with no
INVISIBLEalteration reportsVisible = 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:
pkg/sql/plan/build_ddl.go:1081-1099rebuilds the CLONE/LIKE table plan by passing the sourceTableDefthroughconstructCreateTableSQL, reparsing the generated SQL, and then callingbuildCreateTable.pkg/sql/plan/build_show_util.go:334-423serializes index name, algorithm, parts, prefix lengths, algorithm parameters, INCLUDE columns, and comments, but never serializesindexdef.Visible. The reparsed index consequently gets the default visibility (VISIBLE), losing the source value (false).- Independently,
pkg/sql/compile/util.go:305-306writes every newly created index catalog row with the hard-codedINDEX_VISIBLE_YESinstead of usingindexDef.Visible. A complete fix must preserve visibility through both the reconstructed DDL/plan and themo_indexescatalog insert. - 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:
- creates one visible and one invisible secondary index;
- verifies table-level clone preserves both visibility values;
- verifies database-level clone preserves both visibility values;
- verifies rows and index-backed predicates still work;
- also checks
CREATE TABLE ... LIKE ...because it uses the same serializer.
Related
- [Bug]: CREATE DATABASE ... CLONE accepts a nonexistent source and creates an empty target #27041 is an adjacent database-clone validation bug, not a duplicate.
- No matching open/closed issue or PR was found for
clone invisible index,clone index visibility,CREATE TABLE LIKE invisible index, or equivalent terms.
Activity
fix: preserve index visibility in clone (#27143)
gouhongshen commentedon Aug 17, 2026
fixed by #27143
Ariznawlll commentedon Aug 17, 2026
测试版本
最新
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 覆盖
NO,2 行数据保持不变。NO,并验证 LIKE 不复制数据(0 行)。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。测试结论
测试通过。
fix: preserve index visibility in clone (matrixorigin#27143)
fix: preserve index visibility in clone (matrixorigin#27143)
fix: preserve index visibility in clone (matrixorigin#27143)