Skip to content

[Bug]: CREATE INDEX silently no-ops on partitioned tables #32211

Closed

Description

@Ariznawlll

Environment

  • MatrixOne main@HEAD (c6683bd), 3-CN local cluster
  • part8 (k INT NOT NULL PRIMARY KEY, v INT, pad VARCHAR(64)) — RANGE partitioned into 8 partitions, 1M rows
  • Same behavior on part_big (2 partitions)

Reproduction

-- DDL succeeds silently:
CREATE INDEX p8_v ON part8(v);
-- Query OK, 0 rows affected  ← no warning, no error

-- But the index does not exist:
SHOW INDEX FROM part8;
-- only PRIMARY

SHOW CREATE TABLE part8;
-- partition clauses only, no KEY p8_v

-- and using it explicitly fails:
SELECT COUNT(*) FROM part8 FORCE INDEX(p8_v) WHERE v = 4242;
-- ERROR 1176 (42000): Key 'p8_v' doesn't exist in table 'part8'

Meanwhile the other DDL entry point works on the same table:

ALTER TABLE part8 ADD INDEX p8_v2 (v);
-- OK — SHOW INDEX now lists p8_v2  ✓

So CREATE INDEX ... ON <partitioned table> (the standalone syntax) accepts the command, returns OK, and silently writes nothing to the catalog, while ALTER TABLE ... ADD INDEX succeeds. Both paths were verified twice on two different partitioned tables.

Consequences

  • Queries against the intended index column degrade to full scans (observed: v = 4242 scans the whole 1M-row partitioned table; the equivalent non-partitioned table uses its index at 10x less cost).
  • The failure is silent and invisible in the two places users look (SHOW INDEX, SHOW CREATE TABLE) — it only surfaces when someone adds FORCE INDEX and gets error 1176.
  • Migration tools and ORMs (Django migrations, Flyway, Liquibase, hand-written deploy scripts) overwhelmingly emit the standalone CREATE INDEX syntax → partitioned tables silently lose all their secondary indexes.
  • MySQL semantics: both statements are supported on partitioned tables and are equivalent.

Suggested fix direction

Make the CREATE INDEX statement resolve to the same ALTER TABLE ADD INDEX implementation on partitioned tables — or reject with a clear error if genuinely unsupported. Emitting "OK" while writing nothing to the catalog is data-definition data loss. A regression test comparing the two syntaxes on a partitioned table would pin this.

Activity

  1. added this to the MO-202611 milestone on Nov 5, 2026
  2. added
    kind/bug
    on Nov 5, 2026
  3. added theissue type on Nov 5, 2026
  4. added a commit that references this issue on Nov 16, 2026
    7fcd9bd
  5. XuPeng-SH commented on Nov 16, 2026

    @XuPeng-SH
    Contributor

    QA 交接(main,待验证,不代表验收通过)

    #32772 已于 2026-11-16 04:18:55 UTC 合入 main,merge SHA 7fcd9bdff8433d72983f0399fd5c10dcab91a00a,最终 head 97226b619a41a606b21764f4beb911295421d861。分区表上符合条件的普通/UNIQUE BTREE CREATE INDEX 复用既有 ALTER ADD INDEX 事务路径,同时发布 logical parent 与 physical children 元数据;保留标识符、可序列化选项、重复名错误及其他索引类型原路径。直接对应本单 SHOW INDEX / SHOW CREATE TABLE 不可见及 FORCE INDEX 1176 的问题。

    已核对 issue 全部评论、PR 完整讨论与修改范围,未见当前适用的已验证反例或未完成研发 follow-up。作者报告 25/25 SQL 检查,包括 1061/1062、同连接复用及后续分区失败时精确 catalog rollback,17/17 完整 metadata MoTester 通过。公开评审 #5914616189 对应 22a18559867e1bdb0a01b78c27ea950cd44d24a4,不是最终 head:报告四个完整 normal suites 的 7,156 roots、13 个改动/受影响 roots、task normal/race 及 readiness helper 100 次重复、两轮 17 条 MoTester 和 510 包静态检查;有两个无关 planner subtests 跳过。DDL/BVT 使用单 CN,只有 task lifecycle 使用双 CN。另一同 head 评审快照的 29 checks 为 13 success、14 skipped、2 neutral,不能写成全通过;合并队列随后显示 CI Required 满足。

    以上均为作者/评审/远端 CI 记录,不是本轮本地实测,也未在 merge SHA 上重新构建运行。作者更广泛执行缺少该评审可用 receipts,未计入其验证;可选 Maven assembly 失败,MoTester 使用已校验的仓库 jars。

    建议 QA 在包含 merge SHA 的 main 上复验原 8 分区 / 1M 行 / 多 CN 场景,分别核对 parent/child catalog、SHOW INDEX、SHOW CREATE TABLE、FORCE INDEX 与实际结果,并与 ALTER 入口和非分区对照比较;覆盖 DML 维护、普通/UNIQUE BTREE、quoted identifiers/options、重复名/值错误、late-child 失败原子回滚、失败后同连接复用。其他 vector/plugin/fulltext/spatial 等索引族不在本次改路范围;不据本次宣称所有分区索引能力或性能验收。

    交 Ariznawlll 验证,保持 open;不新增 4.2 backport 要求。

  6. Ariznawlll commented on Nov 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 官方 main:8e8708a8d306a69512d140b40bfcfebc1d404a32(git_version()=8e8708a8d3);修复 PR fix: publish partitioned CREATE INDEX metadata through ALTER #32772 merge SHA 7fcd9bdff8433d72983f0399fd5c10dcab91a00a 已确认在该 main 祖先链。
    • 隔离部署:1 LOG / 1 TN / 1 CN,SQL 端口 17101,全新数据目录。
    • 测试日期:2026-11-16。

    原问题验证

    RANGE 分区表上执行独立 CREATE INDEX p8_v ON part8(v) 后:

    1. SHOW INDEX FROM part8 列出 PRIMARY + p8_v(修复前只有 PRIMARY)。
    2. SHOW CREATE TABLE 输出包含 KEY p8_v(修复前无索引定义)。
    3. SELECT COUNT(*) FROM part8 FORCE INDEX(p8_v) WHERE v=4242 正常返回 3(修复前 ERROR 1176 Key doesn't exist)。
    4. EXPLAIN 确认 Index Table Scan on part8.p8_v 且带健康 prefix_eq Filter/Block Filter。

    Happy Path 覆盖

    1. 普通 BTREE、DESC 列及 CREATE UNIQUE INDEX 独立语法均在分区表上发布元数据;UNIQUE 上重复数据创建时报 1062,与 ALTER 路径一致。
    2. ALTER TABLE ... ADD INDEX 在同一张表上继续工作,两条入口并存。
    3. DML 维护正确:UPDATE 后新旧值命中正确、DELETE 后索引内容一致。
    4. catalog 核对:mo_indexes 中 p8_v 对应 5 个 table_id(1 个 logical parent + 4 个 physical partition children),与修复承诺一致。

    Unhappy Path 覆盖

    重复索引名返回类型化 ERROR 1061(duplicate key name),不再出现“返回 OK 但 catalog 无记录”的静默丢失。

    重启验证

    停止并重启同一数据目录的实例后,SHOW INDEX 仍列出 p8_v / p8_v2 / uq_k,FORCE INDEX(p8_v) 查询结果与重启前一致——经 ALTER 事务路径发布的元数据持久化正确。

    白盒验证

    核对 #32772 修改范围:分区表上的普通/UNIQUE BTREE CREATE INDEX 复用既有 ALTER ADD INDEX 事务路径(pkg/sql/plan/build_ddl.go、pkg/sql/compile/alter.go),同时发布 logical parent 与 physical children;标识符引用、可序列化选项、重复名错误及其他索引族保留原路径。上游单测 TestIssue32211*(parsers/tree、plan)本地全部通过,含 roundtrip 与 delegation 边界。

    Go 单测

    • TestIssue32211*(pkg/sql/parsers/tree、pkg/sql/plan)全部 ok;焦点 -race 运行通过。

    回归测试

    已追加 matrixorigin/motr#349:14_issue_regression/issue_32211_partitioned_create_index(26 语句),覆盖独立/UNIQUE/ALTER 三条入口、FORCE INDEX、DML 维护、1061/1062 错误。录制后普通 diff 模式 3 并发连续多轮通过;PR 4 项 CI 全部成功。用例标记 @target-branch: main(修复未 backport 4.2-dev,该分支下正确跳过)。

    验证边界

    本地为单 CN 小数据量分区表;未重复 issue 中 1M 行 8 分区规模的多 CN 验证。多语句事务内的并发 DDL 行为不在本次范围。

    测试结论

    测试通过,关闭本 issue。

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

Metadata

Metadata

Assignees

Labels

kind/bugneeds-triage

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions