Repository navigation
Description
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_opsbuilds 6/6 times. - Magnitude control: the same 30-row
VECF64(2)table using1e153/2e153/3e153builds each of L2/IP/cosine definitions 18/18 times. - Atomicity: after every failed DDL, source state is
30 rows, all vector dimensions are2, 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
- [Bug]: IVFFLAT index creation panics on vectors containing NaN or Infinity #28688 (closed non-finite input variant)
- [Bug]: vector functions underflow or overflow on finite extreme magnitudes #29083 (finite vector numeric-overflow behavior)
- [Bug]: v4.2.1 multi-CN IVF post search returns nondeterministic candidates due to unordered LIMIT merge #28943 (vector-index robustness exploration)
Activity
fix(vectorindex): refuse a negative centroid key, and check distances…
fix(vectorindex): standardize vector distances on the float32 domain (#…
Ariznawlll commentedon Sep 24, 2026
测试版本
maind7d940e93bd037e9aacdc0f1256b91e32df84642原问题验证
使用原问题中的三条有限
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 覆盖
1e153、2e153、3e153有限向量作为正常量级控制,L2、Cosine、IP 三种 IVFFLAT 定义均连续 3/3 创建成功。Unhappy Path 覆盖
mo_indexes中无iv_l2残留。mo_indexes中无iv_cos残留。白盒验证
不适用。本问题可由公开 SQL 稳定触发并验证错误边界与 DDL 原子性,本次未使用内部注入。
回归测试
已加入 matrixorigin/motr#204:
suites/14_issue_regression/t/issue_29090_ivfflat_finite_extreme.testsuites/14_issue_regression/r/issue_29090_ivfflat_finite_extreme.result新增用例本地重复 3 次全部通过(3/3,66/66 statements)。完整
14_issue_regression套件中本用例通过;套件的其他既有协议/基线失败与本用例无关。测试证据
99089c8b测试结论
测试通过。