Repository navigation
Description
Description
Exact and approximate distinct aggregates count vector elements +0.0 and -0.0 as different values even though vector comparison and grouping treat the vectors as equal.
This affects both VECF32 and VECF64.
Environment
- MatrixOne: latest official
main, commit07fdd4ae0f80f287b93fc4b525fd296d5617abc7 - Deployment: local standalone launch (isolated Log/TN/CN ports and data directory)
Reproduction
drop database if exists vector_distinct_signed_zero_minimal;
create database vector_distinct_signed_zero_minimal;
use vector_distinct_signed_zero_minimal;
create table t(id int, v64 vecf64(2), v32 vecf32(2));
insert into t values
(1, '[0,1]', '[0,1]'),
(2, '[-0,1]', '[-0,1]');
select v64 = lead(v64) over(order by id),
v32 = lead(v32) over(order by id)
from t order by id limit 1;
select count(distinct v64), approx_count_distinct(v64),
hll_cardinality(hll_add_agg(v64)) from t;
select count(distinct v32), approx_count_distinct(v32),
hll_cardinality(hll_add_agg(v32)) from t;
select count(*) from (select v64 from t group by v64) g;
select count(*) from (select v32 from t group by v32) g;Actual behavior
type equality COUNT DISTINCT APPROX DISTINCT HLL GROUP BY groups
VECF64 true 2 2 2 1
VECF32 true 2 2 2 1
The result reproduced identically in 3/3 fresh-table runs.
Expected behavior
Each pair must contribute one distinct value, consistent with typed vector equality and GROUP BY.
Controls
- scalar
FLOAT/DOUBLEexactCOUNT(DISTINCT)correctly returns one after fix: canonicalize signed zero for distinct aggregates #27434; - scalar
FLOAT/DOUBLEapproximate/HLL paths remain affected and are tracked in [Bug]: HLL distinct aggregates count positive and negative zero separately #28856; - vector
GROUP BYcorrectly canonicalizes element signed zero and returns one group.
Code-path analysis
pkg/common/hashmap/keycodec has canonical vector encoders for VECF32/VECF64 which normalize signed-zero elements and are used by grouping. Exact distinct argument handling canonicalizes only scalar FLOAT/DOUBLE, while HLL hashes raw vector bytes. Both aggregate paths miss the typed vector canonicalizer.
Suggested regression coverage
- signed zero in every vector position for
VECF32andVECF64; - exact DISTINCT, approximate DISTINCT, HLL add/merge, multi-column DISTINCT, DOP 1/>1, partial/final, and spill;
- non-zero, NULL, dimension, and multiple-distinct-value controls.
Duplicate search
Open and closed issues were searched for vector signed zero, vector DISTINCT, HLL, raw-byte hashing, and #27434's scalar fix; no matching vector report was found.
Activity
fix(sql): align signed-zero index and vector HLL semantics (#29122)
Ariznawlll commentedon Sep 20, 2026
测试版本
原问题验证
对 VECF64 和 VECF32 分别写入
[0,1]、[-0,1]、[2,1]。两种类型的COUNT(DISTINCT)、APPROX_COUNT_DISTINCT、HLL_ADD_AGG/HLL_CARDINALITY与GROUP BY均得到 2:前两个 SQL 等值 signed-zero 向量合并,第三个非零向量保留为另一值。覆盖范围
回归测试
已加入 MOTR PR #193:
suites/14_issue_regression/t/issue_28861_vector_signed_zero_distinct.testsuites/14_issue_regression/r/issue_28861_vector_signed_zero_distinct.result在上述 commit 录制基线后连续执行 3 轮,30/30 statements 通过。
测试证据
修复合入提交
c2a1d63ee08d31c09cc30099af54b7a51168e236已包含在本次验证的 main 中;仓库原有 BVT fixture 与本次 MOTR 黑盒回归共同覆盖该语义,MOTR 回归提交为faf895aa。测试结论
测试通过。