Skip to content

[Bug]: distinct aggregates split vectors with SQL-equal signed-zero elements #28861

Closed

Description

@Ariznawlll

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, commit 07fdd4ae0f80f287b93fc4b525fd296d5617abc7
  • 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

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 VECF32 and VECF64;
  • 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

  1. added this to the MO-202609 milestone on Sep 14, 2026
  2. added
    kind/bug
    on Sep 14, 2026
  3. added theissue type on Sep 14, 2026
  4. self-assigned this
    on Sep 14, 2026
  5. added a commit that references this issue on Sep 20, 2026
    c2a1d63
  6. Ariznawlll commented on Sep 20, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:22d43911d3f6c51872c1852340265a7d3f206925
    • 环境:隔离单机 Log/TN/CN
    • 日期:2026-09-20

    原问题验证

    对 VECF64 和 VECF32 分别写入 [0,1]、[-0,1]、[2,1]。两种类型的 COUNT(DISTINCT)、APPROX_COUNT_DISTINCT、HLL_ADD_AGG/HLL_CARDINALITY 与 GROUP BY 均得到 2:前两个 SQL 等值 signed-zero 向量合并,第三个非零向量保留为另一值。

    覆盖范围

    • VECF32、VECF64;
    • 精确 DISTINCT、近似 DISTINCT、HLL 以及 GROUP BY;
    • signed-zero 向量与非零向量并存的区分控制。

    回归测试

    已加入 MOTR PR #193:

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

    在上述 commit 录制基线后连续执行 3 轮,30/30 statements 通过。

    测试证据

    修复合入提交 c2a1d63ee08d31c09cc30099af54b7a51168e236 已包含在本次验证的 main 中;仓库原有 BVT fixture 与本次 MOTR 黑盒回归共同覆盖该语义,MOTR 回归提交为 faf895aa。

    测试结论

    测试通过。

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions