Skip to content

[Bug]: IVFFLAT drops ENUM member metadata for hidden PK and INCLUDE columns #28994

Closed

Description

@Ariznawlll

Description

CREATE INDEX ... USING IVFFLAT ... INCLUDE(enum_column) is accepted by DDL validation but fails while populating the hidden entries table. The IVFFLAT plugin advertises ENUM as a supported INCLUDE type, so this prevents a documented/supported index shape from being created.

Environment

  • Branch: main
  • Commit: 01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90
  • Deployment: local mo-service, 2 CN / 1 TN / 1 Log service
  • Date: 2026-09-16

Steps to reproduce

create database ivf_enum_repro;
use ivf_enum_repro;

create table t (
  id bigint primary key,
  e enum('cold','hot'),
  v vecf32(2)
);
insert into t values
  (1,'cold','[1,0]'),
  (2,'hot','[2,0]');

create index ix using ivfflat on t(v)
  op_type 'vector_l2_ops' lists=1 include(e);

Actual behavior

The index build fails:

ERROR 20203 (HY000): invalid argument operator cast, bad value [VARCHAR ENUM]

No ix metadata row or hidden index table remains after the rejected DDL, and the two base-table rows remain unchanged.

Expected behavior

The index should be created and preserve the ENUM member metadata so INCLUDE filtering and projection use the same labels and ordinals as the source column. If ENUM is intentionally unsupported, DDL validation must reject it before creating/building hidden objects rather than advertising it as supported and failing inside the build.

Stability and controls

  • Reproducer: 3/3 on CN1 and 3/3 on CN2 with the same VARCHAR ENUM cast error.
  • Control: an IVFFLAT index on the same vector column with INCLUDE(json_col, uuid_col, binary_col, varbinary_col, text_col) builds successfully and returns the expected indexed rows.
  • SET control: INCLUDE(set_col) builds and matches the full-scan filter/projection result.
  • Failure atomicity: base row count stays at 2; matching mo_indexes rows and hidden tables both remain 0.

Evidence

Minimal SQL and the extended type matrix are retained in evidence/ivfflat_include_exotic.sql in the local validation worktree.

Code analysis

pkg/vectorindex/ivfflat/plugin/runtime/runtime.go includes types.T_enum in SupportedIncludeColumnTypes(). During hidden entries-table construction, pkg/vectorindex/ivfflat/plugin/plan/schema.go copies only Id, Width, and Scale from each INCLUDE column and drops plan.Type.Enumvalues. The hidden ENUM column therefore loses its member list, and the synchronous population query in pkg/vectorindex/ivfflat/plugin/compile/compile.go fails when assigning the source ENUM value to that incomplete target type.

Regression coverage

Add an IVFFLAT INCLUDE lifecycle case for ENUM covering initial build, label and ordinal predicates, projection, INSERT/UPDATE/DELETE maintenance, rollback, ALTER ... REINDEX, and multi-CN reads. Assert that failed DDL leaves no catalog or hidden-table residue.

Related

Activity

  1. added this to the MO-202609 milestone on Sep 16, 2026
  2. added
    kind/bug
    on Sep 16, 2026
  3. added theissue type on Sep 16, 2026
  4. changed the title [-][Bug]: IVFFLAT INCLUDE on ENUM fails index build after dropping member metadata[/-] [+][Bug]: IVFFLAT drops ENUM member metadata for hidden PK and INCLUDE columns[/+] on Sep 16, 2026
  5. Ariznawlll commented on Sep 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充确认相同 schema 生成缺陷也影响源表主键,不需要 INCLUDE 即可触发。

    create table t(
      e enum('cold','hot') primary key,
      v vecf32(2)
    );
    insert into t values('cold','[1,0]'),('hot','[2,0]');
    create index ix using ivfflat on t(v)
      op_type 'vector_l2_ops' lists=1;

    当前 commit 在两台 CN 均报:

    invalid argument operator cast, bad value [VARCHAR ENUM]
    

    稳定性与原子性:基表仍为 2 行,mo_indexes 中该索引为 0 行,且没有隐藏表残留。

    对应源码是 entries 隐藏表的 origin_pk 也只复制 Id/Width/Scale,同样遗漏 Enumvalues;所以 #28994 的准确影响面是 ENUM 主键或 ENUM INCLUDE 列。我已据此把标题从仅 INCLUDE 调整为 hidden PK/INCLUDE metadata,根因和修复点仍是同一个,不另开单。

  6. Ariznawlll commented on Sep 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充异步 IVFFLAT 路径的影响。根因仍是本 issue 描述的隐藏列丢失 Enumvalues,不另开单。

    在相同 commit 01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90 上:

    create table t(
      id bigint primary key,
      status enum('red','green','blue'),
      v vecf32(2)
    );
    insert into t
    select result,
           case result % 3 when 0 then 'red' when 1 then 'green' else 'blue' end,
           cast(concat('[',result,',0]') as vecf32(2))
    from generate_series(1,12) g;
    
    create index ix using ivfflat on t(v)
      lists=1 op_type 'vector_l2_ops'
      quantization 'float16'
      include(status)
      async;

    异步 DDL 返回成功,但隐藏 entries 列被创建成:

    __mo_index_include_status  ENUM(0)
    

    后续结果:

    • 3 个独立数据库等待 20 秒以上,entries 均保持 0/12;
    • 同期普通类型异步对照约 14 秒达到完整行数;
    • SHOW FULL COLUMNS 可见 ENUM(0);
    • SHOW CREATE TABLE <entries> 因生成的 ENUM 定义不完整而直接报 SQL parser error;
    • 同一 schema 去掉 ASYNC 后仍是原 issue 的同步错误:invalid argument operator cast, bad value [VARCHAR ENUM];
    • 空表、全部 NULL 的 ENUM INCLUDE 也在同步 CREATE 阶段触发相同 cast 错误,因此与具体枚举标签无关。

    所以 #28994 需要同时覆盖两种用户可见行为:

    1. 同步构建:CREATE INDEX 直接失败;
    2. 异步构建:CREATE INDEX 表面成功,但留下不可用的 ENUM(0) 隐藏列,索引维护不前进。

    建议回归中增加异步 DDL 成功后的目录定义、SHOW CREATE TABLE、初始 replay 与 DML 维护断言,避免只验证同步报错路径。

  7. added a commit that references this issue on Oct 11, 2026
    5cc6816
  8. added
    ai-easy
    on Oct 12, 2026
  9. Ariznawlll commented on Oct 12, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main;commit:02a2823c2007d5e4fb4ada148e93743df337551a;日期:2026-10-12。
    • 部署:本地独立单 CN / 单 TN / 单 LogService;同步 IVFFLAT。

    原问题验证

    按原 issue 建 ENUM('cold','hot') INCLUDE 列的 IVFFLAT,建索引成功;又建 ENUM 主键表并创建不带 INCLUDE 的 IVFFLAT,也成功。两表在 FORCE、PRE、POST、AUTO、INCLUDE 模式下各 3 轮均能正确读到 'cold',未再出现 VARCHAR ENUM cast 错误。

    Happy Path 覆盖

    同步索引创建、ENUM 主键和 ENUM INCLUDE 两种隐藏列路径均通过;查询投影返回原成员名称,未变为空值或错误 ordinal。

    Unhappy Path 覆盖

    非匹配成员 'hot' 仍存在于两张源表,WHERE e='cold' 只返回目标行,排除建索引后错误扩大匹配。本轮未测异步 CDC 维护、事务回滚或 DROP/CREATE 失败残留,不将同步创建成功扩大为这些生命周期场景全部通过。

    白盒验证

    同时验证隐藏 entries 的 origin_pk 和 INCLUDE ENUM 两条元数据传播路径,避免只测其中之一。未做多 CN 读一致性。

    回归测试

    已加入 MOTR PR #229 的两种 ENUM 建索引与五模式查询,compare 3/3。类型元数据缺陷不需要 big-data;异步、更新/删除和回滚建议由现有 IVFFLAT 生命周期测试另行补足,故本次不以这些未测路径作为关闭条件。

    测试证据

    • 本地复核:两种表形态索引均成功,五模式 × 3 轮结果正确。
    • MOTR 脚本与 golden:compare 3/3。

    测试结论

    测试通过。

  10. Ariznawlll commented on Oct 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:MatrixOne 官方 main
    • commit:48dbe277b6d20216c1c513d03c5cbd681380a8a2(执行前后核对 origin/main;修复 PR #29835 已 MERGED,合入提交 5cc681623bb0ca821d4422bc145c9e4ccf365fa1 已进入该 main)
    • 部署方式:本地 2 CN / 1 TN / 1 LogService;异步 IVFFLAT 和本地 CDC replay,非共享 TKE/128/129。
    • 测试日期:2026-10-16

    原问题验证

    此前已在 本 issue 的同步验收评论 确认同步 ENUM 主键与 INCLUDE 索引构建成功,但该评论明确未覆盖异步路径。本轮补测 issue 中原始 12 行 status ENUM('red','green','blue') + INCLUDE(status) ASYNC:CREATE INDEX 成功;隐藏 entries 列为完整 enum('red','green','blue'),不再是 ENUM(0);SHOW CREATE TABLE 可以解析;初始 entries 在约 20 秒内从 0 追平至 12/12,成员计数 red/green/blue=4/4/4,与源表一致。

    Happy Path 覆盖

    1. 原始 12 行异步构建后,执行 UPDATE id=1 的 ENUM 状态、INSERT id=13 和 DELETE id=2;entries 最终仍为 12 行,red/green/blue=5/3/4,旧 id=2 条目为 0、新 id=13 条目为 1。第二台 CN 读取源表和隐藏 entries,得到相同计数与标签/序号。
    2. 独立 MOTR 场景以不同的 ENUM 主键列表和 INCLUDE 列列表建异步索引:两列隐藏类型分别保持 enum('cold','hot','warm') 与 enum('warm','cold','hot');SHOW CREATE TABLE 正常;初始 replay 的主键/INCLUDE 序号精确为 (1,3),(2,2)。该完整场景重复 3/3。

    Unhappy Path 覆盖

    1. 异步维护中将 INCLUDE 改为 NULL、将 ENUM 主键 cold 更新为 warm,再插入新的 cold;活动版本 entries 精确为 (1,2),(2,NULL),(3,1)(断言中 NULL 使用独立哨兵 -1),未混淆成员序号或旧主键。随后删除 hot,entries 精确变为 (1,2),(3,1),与源表一致;3/3。
    2. 每轮场景结束后按精确库名清理;复核不存在遗留的测试库。未进行人为节点故障注入或共享集群验收。

    白盒验证

    • 本轮重点核对隐藏 origin_pk 与 INCLUDE 列两套 ENUM 元数据,以及异步初始构建和后续 CDC replay;MatrixOne main 已有对应的异步 IVFFLAT 生命周期 BVT 源码。本轮未执行完整 BVT 或 -race,不将源码存在视为 CI 已通过。

    回归测试

    测试证据

    • 产品修复:MatrixOne PR #29835。
    • 持续回归及 oracle:MOTR PR #237;定向日志显示三轮各约 39.5 秒,全部 success,无失败与跳过。
    • 本轮本机原始 12 行复现:隐藏列 enum('red','green','blue'),初始 12/12 与 4/4/4,DML 后 12/12 与 5/3/4;两台 CN 读数一致,测试库已删除。

    测试结论

    测试通过。

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