Skip to content

[Bug]: ONLY_FULL_GROUP_BY rejects MySQL-compatible single-value and functional-dependency queries #25327

Closed

Description

@Ariznawlll

Branch

main at 200bfa7e0efb.

Summary

MatrixOne rejects some ONLY_FULL_GROUP_BY queries that MySQL accepts:

  1. A non-grouped column is constrained to a single value by WHERE.
  2. A non-grouped column is functionally dependent on the grouped primary key.

MySQL documents both as valid behavior under ONLY_FULL_GROUP_BY.

Reproduction

drop database if exists mysql_compat_module8_ofgb;
create database mysql_compat_module8_ofgb;
use mysql_compat_module8_ofgb;
set session sql_mode='ONLY_FULL_GROUP_BY';

create table t_sales(region varchar(10), product varchar(10), qty int);
insert into t_sales values
  ('east','phone',2),
  ('east','phone',null),
  ('west','phone',3),
  (null,'phone',5);

select region, product, sum(qty) as s_qty
from t_sales
where product='phone'
group by region
order by region is null, region;

create table t_fd(id int primary key, name varchar(20), amount int);
insert into t_fd values (1,'a',10),(2,'b',20),(3,'c',30);

select id, name, sum(amount)
from t_fd
group by id
order by id;

MySQL result

+--------+---------+-------+
| region | product | s_qty |
+--------+---------+-------+
| east   | phone   |     2 |
| west   | phone   |     3 |
| NULL   | phone   |     5 |
+--------+---------+-------+

+----+------+-------------+
| id | name | sum(amount) |
+----+------+-------------+
|  1 | a    |          10 |
|  2 | b    |          20 |
|  3 | c    |          30 |
+----+------+-------------+

MatrixOne result

ERROR 1149 (HY000): SQL syntax error: column "t_sales.product" must appear in the GROUP BY clause or be used in an aggregate function
ERROR 1149 (HY000): SQL syntax error: column "t_fd.name" must appear in the GROUP BY clause or be used in an aggregate function

Expected behavior

MatrixOne should accept these queries when the non-grouped column is limited to one value or functionally dependent on the grouped primary key, matching MySQL ONLY_FULL_GROUP_BY behavior.

Activity

  1. added
    kind/bug
    severity/s1
    on Jul 1, 2026
  2. added
    severity/s0
    and removed
    severity/s1
    on Jul 2, 2026
  3. added this to the MO-202607 milestone on Jul 2, 2026
  4. added theissue type on Jul 2, 2026
  5. removed
    severity/s0
    on Jul 2, 2026
  6. added
    ai-medium
    on Jul 3, 2026
  7. Ariznawlll commented on Aug 10, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本

    • 分支:main
    • commit:3c7392a0f86b23712da71f31d7a9198a2c8591a9
    • 部署方式:本地单节点 Log/TN/CN,独立数据目录;测试日期:2026-08-10。

    原问题验证

    在 ONLY_FULL_GROUP_BY 下,issue 的单值 WHERE product='phone' 和主键函数依赖两类查询连续执行 3 次均成功,不再报列必须出现在 GROUP BY 的错误。

    Happy Path 覆盖

    1. 单值 WHERE:包含普通、NULL group key 和 NULL 聚合输入,结果保持正确。
    2. 函数依赖:以主键分组、投影非分组 name,三行结果与各自主键一致。

    Unhappy Path 覆盖

    1. 移除单值 WHERE 后,非分组 product 的查询连续 3 次均正确被拒绝(错误 1149),说明放宽没有误接受一般不确定分组。
    2. 每次拒绝后 SELECT 1 均成功;只读查询无失败写入原子性维度。

    白盒验证

    不适用:使用公开 SQL mode 和结果语义黑盒验证。

    回归测试

    已加入 motr PR #89 的 suites/14_issue_regression/t/issue_26269_25973_25389_25327_25326_sql_semantics.test(commit a6a50dfcf7053027dab5e9117fde7bdd7b5cdefb);拒绝对照另行连续验证 3 次。

    测试证据

    MOTR 固定回归连续 3 轮通过;关联 5 个场景合计 15/15 成功、171 条断言成功。

    测试结论

    测试通过。

  8. dengn commented on Oct 11, 2026

    @dengn
    Contributor

    Application compatibility replay on official v4.2.5

    Branch Name

    Official stable release v4.2.5; current main has not been retested for this report.

    Commit ID

    1a44f3db3056e32975fde86ca0ab69a094996a3f (SELECT git_version() returns 1a44f3d).

    Other Environment Information

    Linux x86_64 standalone official binary, 4 CPUs, ~16 GiB container memory limit. SELECT VERSION() = 8.0.30-MatrixOne-v4.2.5. PyMySQL 1.2.3 client. Only fresh owned test schemas were used for SQL probes; the native Airflow diagnostic is a read-only SELECT against the retained test fixture.

    Actual Behavior

    Native application impact: 原生调度/聚合查询失败。

    ERROR 1149: SQL syntax error: column "grouped.name" must appear in the GROUP BY clause or be used in an aggregate function
    

    Expected Behavior

    Recognize functional dependence on the complete grouped primary key under ONLY_FULL_GROUP_BY, while continuing to reject ambiguous groupings.

    Steps to Reproduce

    Use a dedicated fresh test schema (create one without DROP DATABASE), then run:

    CREATE TABLE grouped(id INT PRIMARY KEY,name VARCHAR(20),value INT);
    
    INSERT INTO grouped VALUES(1,'owned',7);
    
    SELECT id,name,SUM(value) FROM grouped GROUP BY id;

    Additional information

    • Native applications: Airflow, Vikunja, FreshRSS, Mautic.
    • This is release v4.2.5 evidence, not a claim that the same failure remains on current main.
    • Observation family MO-OBS-009. App-side workarounds do not constitute an engine fix.
    • All disclosed values are owned synthetic fixtures; no passwords, tokens, application cookies or raw private logs are attached.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-mediumkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions