Skip to content

[Bug]: VARIANCE alias cannot be used as a window aggregate #25482

Closed

Description

@Ariznawlll

Branch Name

main

Commit ID

d261752

Other Environment Information

  • MySQL baseline: 8.0.45
  • MatrixOne SQL endpoint used for validation: local latest-main build on 127.0.0.1:26001

Actual Behavior

MatrixOne supports var_pop(...) over (...), but the MySQL-compatible alias variance(...) over (...) fails to parse.

MO result:

ERROR 1064 (HY000): SQL parser error: ... syntax error ... near " over (partition by customer_id) ..."

Expected Behavior

MySQL accepts variance(...) over (...) as a window aggregate. It returns the same values as var_pop(...) over (...).

Steps to Reproduce

DROP DATABASE IF EXISTS mysql_compat_window_variance;
CREATE DATABASE mysql_compat_window_variance;
USE mysql_compat_window_variance;

CREATE TABLE orders (
  id int primary key,
  customer_id int,
  amount decimal(10,2)
);
INSERT INTO orders VALUES
(1,10,100.00),(2,10,200.00),(3,10,200.00),
(4,20,NULL),(5,20,150.50),(6,20,150.50),
(7,30,300.00),(8,30,100.00);

SELECT 'var_pop' q, id, var_pop(amount) over (partition by customer_id) v
FROM orders ORDER BY id;

SELECT 'variance' q, id, variance(amount) over (partition by customer_id) v
FROM orders ORDER BY id;

Additional information

var_pop, var_samp, stddev, stddev_pop, and stddev_samp were also checked as window aggregates on latest main; those parsed and executed successfully. The gap appears specific to the variance alias.

Activity

  1. added this to the MO-202607 milestone on Jul 6, 2026
  2. added
    kind/bug
    on Jul 6, 2026
  3. added theissue type on Jul 6, 2026
  4. daviszhen commented on Jul 30, 2026

    @daviszhen
    Contributor

    fixed

  5. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main(截至 2026-07-30 16:30,Asia/Shanghai)
    • commit:41332062a6740978f269088a92ee362a888c7bd7
    • 部署方式:从该官方 commit 源码构建;etc/launch-with-proxy/launch.toml(2 CN + 1 TN + Proxy),SQL 入口 127.0.0.1:6001
    • 测试日期:2026-07-30

    原问题验证

    variance(v) over(partition by g) 可解析执行,并逐行与 var_pop(v) 完全一致;完整黑盒 3/3 通过。

    Happy Path 覆盖

    1. 多行分区中 VARIANCE 与 VAR_POP 值一致。
    2. 带 ROWS BETWEEN 1 PRECEDING AND CURRENT ROW 的滑动 frame 结果一致。
    3. 单行、含 NULL 和全 NULL 分区均正常。

    Unhappy Path 覆盖

    1. 全 NULL 分区返回 NULL,未出现除零、parser error 或 panic。
    2. NULL 混合分区忽略 NULL 后与 VAR_POP 保持相同语义。

    白盒验证

    TestVarianceWindowSpec 连续 3 轮通过;window 全包连续 3 轮及 -race 通过。

    回归测试

    修复提交 a4389a72f 已加入 test/distributed/cases/window/mysql_compat_window_variance.sql。

    测试证据

    完整 3 轮 SQL 结果、测试脚本、Proxy 黑盒日志、定向 UT 与 -race 输出:https://gist.github.com/Ariznawlll/b8f1a22642a58fd5264482687534728b

    测试结论

    测试通过。

  6. Ariznawlll commented on Jul 30, 2026

    @Ariznawlll
    CollaboratorAuthor

    motr 黑盒回归已补充

    • PR:matrixorigin/motr#72
    • 用例:suites/14_issue_regression/t/issue_25482_window_variance.test
    • 覆盖:分区和滚动窗口中的 VARIANCE 与 VAR_POP 一致,含 NULL/单值分区
    • 本地验证:基于 MatrixOne main@41332062a6740978f269088a92ee362a888c7bd7,该批 14 个用例连续 3 轮为 42/42 成功(504/504 语句);完整 14_issue_regression suite 为 124 成功、0 失败。
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