You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: FLOAT and DOUBLE secondary-index equality omits SQL-equal signed zero #28695
createtabled(id intprimary key, v double, key idx_v(v));
insert into d values
(1, cast('-0.0'as double)),
(2, cast('0.0'as double)),
(3, 1.0);
select group_concat(id order by id) from d
where v = cast('-0.0'as double);
-- MO: 1select group_concat(id order by id) from d
where v = cast('0.0'as double);
-- MO: 2select group_concat(id order by id) from d ignore index(idx_v)
where v = cast('-0.0'as double);
-- MO: 1,2
explain select id from d where v = cast('-0.0'as double);
-- Index Table Scan on d.idx_v
同样的 FLOAT 表得到相同行为。
MO 中 -0.0 = +0.0 和 -0.0 <=> +0.0 都为 true;GROUP BY v 合并为一组,且向 DOUBLE UNIQUE KEY 插入 -0.0 后插入 +0.0 会正确报重复键。因此索引谓词的结果与同一实例的 SQL 相等语义不一致。
在 MySQL 8.3,DOUBLE/FLOAT 的索引访问和 IGNORE INDEX 扫描对正、负零谓词均返回 1,2。
pkg/container/types/compare.go 已将 signed zero 定义为 SQL ORDER BY peer;pkg/common/hashmap/keycodec/keycodec.go 的 CanonicalFloat32Bits / CanonicalFloat64Bits 也会将两种零归一化。相对地,二级索引的物理元组键保留浮点原始位表示(Float32TupleAscCompare / Float64TupleAscCompare 的注释明确说明会区分 signed zero)。当前 prefix_eq(__mo_index_idx_col) 没有将 SQL 的零等值谓词扩展到两个物理键,导致漏行。
Activity
Ariznawlll commentedon Sep 11, 2026
补充谓词范围:
v <=> -0.0/v <=> +0.0在本轮返回两行,说明该形式没有触发同样的漏行路径。v IN (-0.0)、v IN (+0.0)仍各只返回一种物理零表示。v >= 0.0 AND v <= 0.0仅返回+0.0;以-0.0为上下界仅返回-0.0。v BETWEEN -0.0 AND +0.0返回两行,因为物理范围恰好覆盖两种编码。FLOAT 与 DOUBLE 均一致;MySQL 对上述所有谓词均返回两行。问题不仅限于
=,还影响走索引的单值IN与退化零范围。fix(sql): align signed-zero index and vector HLL semantics (#29122)
Ariznawlll commentedon Sep 20, 2026
测试版本
原问题验证
建立 FLOAT、DOUBLE 二级索引后分别写入 -0.0、+0.0 和 1.0。
=的正零/负零谓词、IN (-0.0),以及参数化PREPARE/EXECUTE都返回1,2;结果与表扫描的 SQL 等值语义一致,未再出现按物理 signed-zero 位模式漏行。覆盖范围
=-0.0、=+0.0、IN (-0.0);=-0.0、=+0.0、IN (-0.0);回归测试
已加入 MOTR PR #193:
suites/14_issue_regression/t/issue_28695_signed_zero_secondary_index.testsuites/14_issue_regression/r/issue_28695_signed_zero_secondary_index.result在上述 commit 录制基线后连续执行 3 轮,54/54 statements 通过。
测试证据
修复合入提交
c2a1d63ee08d31c09cc30099af54b7a51168e236已包含在本次验证的 main 中;回归提交为 MOTRfaf895aa。测试结论
测试通过。