Skip to content

[Bug]: IVFFLAT build panics on finite extreme VECF64 values #29090

Closed

Description

@Ariznawlll

Description

IVFFLAT index creation can reach an internal bounds panic for entirely finite VECF64 input. The table accepts the vectors and their dimensions are valid; only the index build fails. The error is returned to the SQL client with a Go stack trace rather than a controlled vector/index error.

The trigger is metric-dependent: the same data panics under vector_l2_ops and vector_cosine_ops, while the vector_ip_ops control builds successfully. This isolates the failure to the squared-norm distance/training path rather than generic VECF64 parsing or IVFFLAT DDL.

This is distinct from closed #28688: that issue covered already-stored NaN/Infinity input. Here every source component is finite (1e200, 2e200, or 3e200), so the non-finite value is produced inside the IVFFLAT build path.

Environment

  • Branch: main
  • Commit: 01d60e1c4ded1b0f3fc1a4ecd75ce54e95e23b90
  • Deployment: local 1 LogService / 1 TN / 2 independent CN processes

Steps to reproduce

CREATE TABLE t(id BIGINT PRIMARY KEY, v VECF64(2));
INSERT INTO t VALUES
  (1, '[1e200,0]'),
  (2, '[2e200,0]'),
  (3, '[3e200,0]');

CREATE INDEX iv USING ivfflat ON t(v)
  lists=1
  op_type 'vector_l2_ops'
  kmeans_train_percent 100
  kmeans_max_iteration 10;

Replacing vector_l2_ops with vector_cosine_ops reaches the same panic. Replacing it with vector_ip_ops is a successful control.

Actual behavior

The index DDL returns:

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

The source table remains queryable with its original finite 2-dimensional vectors, and SHOW INDEX contains only PRIMARY; no partial IVFFLAT index remains.

Expected behavior

Finite, valid VECF64 values must not reach a Go bounds panic during IVFFLAT build. The engine should either build the index using numerically stable operations or return a controlled validation/capability error without exposing a runtime panic.

Stability and controls

  • Reproducer: two CN endpoints × three independent databases × L2/cosine = 12/12 panics.
  • Metric control: the same high-magnitude table with vector_ip_ops builds 6/6 times.
  • Magnitude control: the same 30-row VECF64(2) table using 1e153/2e153/3e153 builds each of L2/IP/cosine definitions 18/18 times.
  • Atomicity: after every failed DDL, source state is 30 rows, all vector dimensions are 2, only the primary-key index exists, and a subsequent SQL read succeeds.
  • Process health: both CN processes remained available after all six attempts.

Evidence

evidence/ivfflat_finite_vecf64_panic_matrix.py and its output record the six reproductions and six controls.

Code analysis

The failure reaches pkg/sql/colexec/productl2/product_l2.go::probeRun. brute_force.SearchFloat32 returns a cluster key which is subsequently passed to Vector.UnionOne without validating that it is within the centroid batch range. The observed key is negative (-8).

The source vectors are finite, while their squared L2 intermediates can overflow a direct float64 accumulator at this magnitude. L2 and cosine both need squared norms and reproduce; IP does not and succeeds. This strongly suggests an internal non-finite distance/candidate result reaches probeRun; the exact production point should be traced through the IVFFLAT training/assignment path. The same unchecked-index sink was fixed for non-finite source data in #28688, but that input boundary does not cover finite values that overflow internally.

Regression coverage

Add an IVFFLAT UT/integration case for finite high-magnitude VECF64 values under L2 and cosine, asserting no panic/stack exposure and checking post-failure source/index atomicity. Keep vector_ip_ops and the 1e153 successful L2/IP/cosine controls.

Related

Activity

  1. added this to the MO-202609 milestone on Sep 18, 2026
  2. added theissue type on Sep 18, 2026
  3. Ariznawlll commented on Sep 24, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:d7d940e93bd037e9aacdc0f1256b91e32df84642
    • 部署方式:本地分布式,1 LogService / 1 TN / 1 CN;全新数据目录
    • 测试日期:2026-09-24

    原问题验证

    使用原问题中的三条有限 VECF64(2) 数据(1e200、2e200、3e200)分别创建 L2、Cosine 和 IP IVFFLAT 索引,独立建库重复 3 次。

    • vector_l2_ops:返回受控错误 brute force: no nearest centroid for query; every candidate distance is out of range;未出现 Go panic、负下标或调用栈。
    • vector_cosine_ops:返回受控错误 cosine distance: vector magnitude overflows the float64 domain;未出现 Go panic 或调用栈。
    • vector_ip_ops:索引创建成功。

    Happy Path 覆盖

    1. 相同表结构使用 1e153、2e153、3e153 有限向量作为正常量级控制,L2、Cosine、IP 三种 IVFFLAT 定义均连续 3/3 创建成功。
    2. IP 极大值控制连续 3/3 创建成功,证明不是 VECF64 解析、存储或通用 IVFFLAT DDL 失败。

    Unhappy Path 覆盖

    1. L2 极值构建失败后,源表仍为 3 行,向量可继续读取,mo_indexes 中无 iv_l2 残留。
    2. Cosine 极值构建失败后,源表仍为 3 行,向量可继续读取,mo_indexes 中无 iv_cos 残留。
    3. 三轮中均未观察到 panic、hang、服务退出或半成品索引。

    白盒验证

    不适用。本问题可由公开 SQL 稳定触发并验证错误边界与 DDL 原子性,本次未使用内部注入。

    回归测试

    已加入 matrixorigin/motr#204:

    • suites/14_issue_regression/t/issue_29090_ivfflat_finite_extreme.test
    • suites/14_issue_regression/r/issue_29090_ivfflat_finite_extreme.result

    新增用例本地重复 3 次全部通过(3/3,66/66 statements)。完整 14_issue_regression 套件中本用例通过;套件的其他既有协议/基线失败与本用例无关。

    测试证据

    • 回归 PR:matrixorigin/motr#204
    • 回归提交:99089c8b
    • 本地测试汇总:目标三项合计重复 9/9 通过,177/177 statements 成功。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

area/frontendkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions