Skip to content

[Bug]: IVFFLAT index creation panics on vectors containing NaN or Infinity #28688

Closed

Description

@Ariznawlll

问题描述

VECF32/VECF64 当前允许存储 NaN、+Inf 和 -Inf。当已有数据包含任一非有限分量时,在该列上创建 IVFFLAT 索引会进入内部越界 panic,并把 Go 运行时堆栈返回给客户端。索引创建失败,表上不保留该索引。

普通有限向量以及包含 NULL 的向量列均可正常创建同配置的 IVFFLAT 索引,因此触发条件是非有限向量分量,不是行数、空值或索引参数。

环境

  • MatrixOne main: 47d72b104a15e212c983e9ecdbeb7f44ecf7a0b8
  • 部署:本地 launch 2 CN / 1 TN / 1 Log
  • 入口:CN 16001

最小复现

drop database if exists repro_ivf_nonfinite;
create database repro_ivf_nonfinite;
use repro_ivf_nonfinite;

create table t(id bigint primary key, v vecf32(3));
insert into t values
  (1, '[1,2,3]'),
  (2, '[0,0,0]'),
  (3, '[NaN,0,0]'),
  (4, '[2,1,0]');

create index ix using ivfflat on t(v)
  lists=2
  op_type 'vector_l2_ops'
  kmeans_train_percent 100
  kmeans_max_iteration 20;

实际行为

ERROR 20101 (HY000): internal error: panic runtime error: index out of range [-8]:
runtime.panicBounds64
runtime.panicBounds
github.com/matrixorigin/matrixone/pkg/container/vector.(*Vector).UnionOne
github.com/matrixorigin/matrixone/pkg/sql/colexec/productl2.probeRun[...]

将第三行分别改为 [Inf,0,0] 或 [-Inf,0,0] 会进入同一越界路径。NaN 场景连续执行三次均可复现。

对照

以下两种数据均能创建索引:

-- 有限值
insert into t values
  (1, '[1,2,3]'), (2, '[0,0,0]'),
  (3, '[-1,-2,-3]'), (4, '[2,1,0]');

-- NULL 不触发
insert into t values
  (1, '[1,2,3]'), (2, '[0,0,0]'),
  (3, null), (4, '[2,1,0]');

期望行为

系统应在一致的边界上处理非有限向量:要么在向量写入/转换时拒绝 NaN 和无限值,要么由 IVFFLAT 建索引路径返回清晰的参数/数据错误;不能进入内部越界 panic 或向客户端暴露 Go 堆栈。

初步代码定位

IVFFLAT 聚类分配通过 pkg/sql/colexec/productl2/product_l2.go 的 probeRun 获取 leastClusterIndex。非有限距离下搜索结果可产生负索引值,当前代码只检查结果切片长度,没有验证每个索引是否位于 centroid batch 的有效范围,随后把该值传给 Vector.UnionOne,最终以 -8 的底层偏移触发边界 panic。

Activity

  1. added this to the MO-202609 milestone on Sep 11, 2026
  2. added
    kind/bug
    on Sep 11, 2026
  3. added theissue type on Sep 11, 2026
  4. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    补充类型范围:同一问题也影响新窄向量类型 VECF16 和 VECBF16。

    • VECF16(3) 含 [Inf,0,0] 时,CREATE INDEX ... USING IVFFLAT 进入相同的 productl2.probeRun -> Vector.UnionOne、index out of range [-8] 路径。
    • VECBF16(3) 含 [NaN,0,0] 时进入相同路径。
    • 两种类型的有限值对照均可正常建索引。

    因此触发范围不是仅限 VECF32/VECF64,而是所有允许携带非有限分量且由 IVFFLAT 支持的浮点向量类型;整数窄向量 VECINT8/VECUINT8 不存在该输入。环境仍为 main 47d72b104a15e212c983e9ecdbeb7f44ecf7a0b8。

  5. Ariznawlll commented on Sep 11, 2026

    @Ariznawlll
    CollaboratorAuthor

    最新 main 复验:7013fbbd6e152ba31da2d3dbba7012ac7f8b8462(其中包含 #28622 的 IVF 计划读取/执行观测改动),使用全新本地 2CN/1TN/1Log 数据目录。

    • VECF32 + NaN:连续 3 次均返回 index out of range [-8] 的内部 panic。
    • VECF32 + +Inf:进入同一 panic 路径。
    • 仅有限向量的相同建索引语句成功。

    因此该问题在当前最新 main 仍存在,新合入的 IVF 改动未改变该触发路径。

  6. added
    severity/s0
    and removed on Sep 11, 2026
  7. cpegeric commented on Sep 14, 2026

    @cpegeric
    Contributor

    please verify

  8. Ariznawlll commented on Sep 15, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • MatrixOne main:0c3a04f390adaf6281fd592a49778ea5b1155e67
    • 本地 standalone(1 CN / 1 TN / 1 LogService),2026-09-15。

    原问题验证

    向向量表插入 NaN 后创建 IVFFLAT 索引;当前在写入阶段返回受控错误 vector element cannot be NaN or Inf,服务未退出。

    Happy Path 覆盖

    覆盖有限 float 向量的写入、IVFFLAT 索引创建和索引元数据存在性。

    Unhappy Path 覆盖

    覆盖 NaN/Infinity 非有限元素,确认拒绝发生在建索引前且不会 panic。

    白盒验证

    公开 SQL 路径已覆盖关键输入校验与索引创建边界。

    回归测试

    已加入 MOTR:issue_28688_ivfflat_nonfinite,见 motr#176。

    测试证据

    新 MOTR 用例连续运行 3 轮成功;NaN 拒绝、有限行保留及 IVFFLAT 创建均稳定通过。

    测试结论

    测试通过。

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