Skip to content

[Bug]: statistical aggregates accept YEAR at binding but fail in the executor #30181

Closed

Description

@Ariznawlll

Summary

YEAR is accepted by MatrixOne's statistical-aggregate type checker, but the executor cannot construct the aggregate for that type and returns an internal error. MySQL 8.0.46 executes the same aggregate.

Reproduction

CREATE TABLE t (y YEAR);
INSERT INTO t VALUES (2020), (2021), (2022);
SELECT VAR_POP(y) FROM t;

MySQL 8.0.46 returns:

0.6666666666666666

MatrixOne returns:

ERROR 20101 (HY000): internal error: unsupported type 'YEAR' for var/stddev

The explicit numeric control SELECT VAR_POP(CAST(y AS DOUBLE)) FROM t executes in MO and returns the MySQL value.

Scope / code path

The shared statistical-aggregate binder accepts YEAR through its supported numeric type set, so the query reaches executor construction. The executor then rejects YEAR as unsupported. This is a type-checker/executor mismatch, not the binding-time rejection tracked by #30180.

Duplicate / known-issue check

Environment

  • MatrixOne local runtime commit: 2ce4e58af6f03b943ee288ffad81012766cf830a.
  • Current origin/main inspected at a53390c57de48ac280249ff0e88831e502e20fb0; the relevant aggregate binder and executor files are unchanged from the tested runtime. The runtime itself was not rebuilt at that newer SHA.
  • MySQL: 8.0.46.

Activity

  1. added this to the MO-202610 milestone on Oct 14, 2026
  2. added theissue type on Oct 14, 2026
  3. XuPeng-SH commented on Oct 16, 2026

    @XuPeng-SH
    Contributor

    转测 @Ariznawlll。

    已在 main 提交 0723ae37b1183a03bac9eda16669dfc7e474dfb8 对关联修复 #30365 完成本 issue 对应的定向验证,所测场景通过。

    已运行对应功能回归;本轮测试结果支持进入测试验收。

    测试入口:

    • TestVarianceYearResults

    请在目标验收版本复核后决定关闭;本次转测保留 issue 为 OPEN。

  4. Ariznawlll commented on Oct 16, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:官方 main
    • commit:7387b96afd3f996379e2ff48faeace9e1790fc35
    • 修复 PR:matrixone#30365,merge commit 0bf5bc7058852c9069b8db7df40c260782dfb905 已确认进入上述 main。
    • 部署方式:本机隔离 1 CN / 1 TN / 1 LogService,独立数据目录与 MySQL 协议端口;未使用共享集群。
    • 测试日期:2026-10-17(北京时间)。

    原问题验证

    按 issue 原 SQL 创建 YEAR 列并写入 2020、2021、2022。VAR_POP(y) 连续 3/3 次返回 0.6666666666666666,不再报 unsupported type 'YEAR' for var/stddev;同数据的 VAR_POP(CAST(y AS DOUBLE)) 也是 0.6666666666666666。

    Happy Path 覆盖

    1. VAR_SAMP(y)=1、STDDEV_POP(y)=0.816496580927726、STDDEV_SAMP(y)=1;VAR_POP(DISTINCT y)=0.6666666666666666。
    2. 插入一个 NULL 后总行数为 4、非 NULL YEAR 为 3,VAR_POP(y) 仍为 0.6666666666666666。
    3. 空集上的四种统计聚合均为 NULL;单行 YEAR 的总体方差为 0、样本方差为 NULL。上述 SQL 组合 3/3 次一致。

    Unhappy Path 覆盖

    1. 向 YEAR 列插入 invalid-year,3/3 次返回错误 20301;每次拒绝后原 3 行保持不变,VAR_POP(y) 仍为 0.6666666666666666。失败没有留下部分写入。

    白盒验证

    已有修复 UT TestVarianceYearResults 在该 main 上以 -count=3 运行通过;本次未新增或修改 Go UT。并发和外部故障注入不适用于该确定性聚合类型缺陷。

    回归测试

    • MatrixOne 修复 PR 已包含 func_aggr_var_pop 的 YEAR BVT 覆盖。
    • 按持续回归要求另补 MOTR:motr#247,提交 03163dedbef6f9d74e0017507b0699f4b6082653,文件 suites/14_issue_regression/t/issue_30181_year_statistical_aggregates.test 与对应 .result。独立核实正确数值后,定向比较 3/3 次、42/42 条语句通过。
    • MOTR PR 目前仍 Open;完整 14_issue_regression suite 和集成 CI 尚未运行。本地定向结果不等同于集成 CI 通过,后续继续跟踪 PR 合入和 CI。

    测试证据

    测试结论

    测试通过。

  5. daviszhen commented on Oct 20, 2026

    @daviszhen
    Contributor

    最新 main 验证(2026-10-20)

    基线:309f618995af4ee23e3b9149365f4af77264090d;关联修复 PR:#30365。

    结论:原问题已解决。exact-main SQL 计算 VAR_POP(YEAR) 得到 0.6666666666666666,pkg/sql/colexec/aggexec 对应测试通过。

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

Metadata

Metadata

Assignees

Labels

area/compatibilitykind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions