Skip to content

[Bug]: Renaming a Fulltext2 INCLUDE column leaves stale metadata and stops incremental indexing #27964

Closed

Description

@Ariznawlll

Description

Renaming a column that is listed in a Fulltext2 index INCLUDE clause leaves the persisted include-column metadata stale. Subsequent inserts remain in the base table but are not indexed by the Fulltext2 incremental-maintenance path.

Environment

  • Branch: main
  • Commit: 33af6ae3c0c23e4f277137460577ea64678f7ecf
  • Deployment: isolated local single-CN/single-TN instance
  • Test date: 2026-09-01

Steps to reproduce

SET experimental_fulltext2_index = 1;
CREATE TABLE renamed (id BIGINT PRIMARY KEY, body TEXT, status INT, prio INT);
CREATE TABLE control_t (id BIGINT PRIMARY KEY, body TEXT, status INT, prio INT);
INSERT INTO renamed VALUES (1, 'alpha original', 10, 100), (2, 'beta only', 20, 200);\nINSERT INTO control_t SELECT * FROM renamed;\nCREATE FULLTEXT2 INDEX ft_ren ON renamed(body) INCLUDE(status, prio);\nCREATE FULLTEXT2 INDEX ft_ctl ON control_t(body) INCLUDE(status, prio);\n\nALTER TABLE renamed RENAME COLUMN status TO state;\nINSERT INTO renamed VALUES (3, 'alpha incremental', 30, 300);\nINSERT INTO control_t VALUES (3, 'alpha incremental', 30, 300);\n\n-- Wait for asynchronous index maintenance, then compare.\nSELECT id FROM renamed WHERE MATCH(body) AGAINST('alpha') ORDER BY id;\nSELECT id FROM control_t WHERE MATCH(body) AGAINST('alpha') ORDER BY id;\nSHOW CREATE TABLE renamed;\n```\n\n## Actual behavior\n\nAfter a 30-second observation window, the renamed table returns only `1`; the no-rename control returns `1, 3` within 2 seconds. The base table has all three rows. `SHOW CREATE TABLE renamed` still renders `INCLUDE (status, prio)`, although `status` no longer exists. Both Fulltext2 catalog rows also retain `included_columns` containing `status`.\n\n## Expected behavior\n\nThe rename must rewrite Fulltext2 INCLUDE metadata to `state`, `SHOW CREATE TABLE` must render the valid new column name, and the inserted matching document must be returned just as it is by the no-rename control.\n\n## Stability and controls\n\n- Controlled reproducer: 3/3 on latest official main.\n- Control: the identical Fulltext2 INCLUDE index without column rename indexes the new document and returns `1, 3`.\n- Timing control: the renamed table still omits document `3` after 30 seconds; the control becomes correct at 2 seconds.\n- Metadata check: 3/3, both `SHOW CREATE TABLE` and `mo_catalog.mo_indexes.algo_params` keep the old include name.\n- Cleanup: all temporary databases were dropped after each run.\n\n## Code analysis\n\n`pkg/sql/plan/build_alter_rename_column.go` rewrites `IndexDef.Parts` and `mo_indexes.column_name` for an indexed key. INCLUDE-column metadata is delegated to optional plugin alter hooks. The Fulltext2 plan plugin does not implement `AlterColumnHooks`, so its `included_columns` payload is not rewritten. This matches the stale catalog payload and broken incremental-maintenance behavior above.\n\n## Regression coverage\n\nAdd a distributed Fulltext2 regression under `test/distributed/cases/fulltext2/`: create an index with INCLUDE columns, rename one include column, assert `SHOW CREATE TABLE` and catalog payload use the new name, then assert post-rename insert/update is searchable. Cover a no-rename control and a duplicate-target rename rejection.\n\n## Related\n\n- #27950 is distinct: it concerns DATA BRANCH materialization, not ALTER COLUMN metadata rewriting.

Activity

  1. added this to the MO-202609 milestone on Sep 1, 2026
  2. added
    kind/bug
    on Sep 1, 2026
  3. added theissue type on Sep 1, 2026
  4. added
    severity/s0
    and removed on Sep 1, 2026
  5. cpegeric commented on Sep 2, 2026

    @cpegeric
    Contributor

    The right fix is to disallow user to rename the included columns too.

  6. cpegeric commented on Sep 2, 2026

    @cpegeric
    Contributor

    please verify and close

  7. Ariznawlll commented on Sep 3, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • Commit:17c161a31b47a22e71ca222839143f66717ac365
    • 环境:本地最新 main,单 CN / 单 TN(isolated local single-CN/single-TN)
    • 日期:2026-09-03

    原问题验证

    原问题是在 Fulltext2 索引的 INCLUDE(status, prio) 中将 status 重命名后,目录元数据仍保留旧列名,后续增量写入虽然进入基表但无法被 MATCH 搜索到。当前 main 上按原复现步骤执行,重命名后插入 alpha incremental,等待异步索引维护 10 秒后,重命名表和未重命名 control 表的 MATCH 结果均为 1, 3。

    Happy Path 覆盖

    • 创建 FULLTEXT2(body) INCLUDE(status, prio) 索引。
    • ALTER TABLE renamed RENAME COLUMN status TO state 成功。
    • 重命名后的 SHOW CREATE TABLE 显示 INCLUDE (state, prio)。
    • mo_catalog.mo_indexes.algo_params 两条记录均为 {"included_columns":"[\"state\",\"prio\"]","parser":"ngram"}。
    • 重命名后新增匹配行可被 MATCH 搜索到,结果与 control 表一致:1, 3。

    Unhappy Path 覆盖

    • 执行 ALTER TABLE renamed RENAME COLUMN prio TO state,按预期返回 ERROR 1060: Duplicate column name 'state'。
    • 失败后列仍为 id, body, state, prio,行数仍为 3,连接继续可用(select 1 返回 1),确认重复目标重命名是原子的。

    白盒验证

    本次验证对应修复提交 e0a8738651(Fulltext2 INCLUDE 列 ALTER plan hooks,合入为 #28009),其作用是把列重命名同步改写到 Fulltext2 INCLUDE 元数据;上述 SHOW CREATE TABLE 和 mo_catalog.mo_indexes.algo_params 已直接验证新列名持久化。

    回归测试

    已加入 MOTR:motr#141,测试文件 suites/14_issue_regression/t/issue_27964_fulltext2_include_rename.test。

    • MOTR 单次:23/23 statements passed。
    • MOTR 重复 3 轮:3/3 通过(每轮 23/23)。

    测试证据

    MOTR 三轮总计:6 个 case 执行成功,129/129 statements 通过。每轮均包含异步索引等待、MATCH 对比、目录元数据校验、重复目标重命名错误恢复和清理。

    最新 main 已修复 #27964 描述的问题,Happy/Unhappy 场景均通过;黑盒回归已加入 MOTR,不需要 big-data、stability 或 chaos 专项。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions