You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: GROUP BY query rejects correlated subquery referencing grouped column #25352
Existing issue #25327 covers ONLY_FULL_GROUP_BY single-value and functional-dependency cases. This issue is different: the outer column referenced by the correlated subquery is itself present in the GROUP BY list, but MatrixOne still rejects it.
Branch Name
main
Commit ID
0e8602b78
Other Environment Information
Local MatrixOne built from latest origin/main
MySQL oracle: MySQL 8.0.45
Actual Behavior
MatrixOne rejects a grouped query when a scalar correlated subquery references the grouped outer column:
ERROR 1149 (HY000): SQL syntax error: column "t.status" must appear in the GROUP BY clause or be used in an aggregate function
But t.status is already in the outer GROUP BY list.
Expected Behavior
MySQL accepts the query and evaluates the correlated subquery per grouped row.
Expected result:
status c
active 2
archived 1
pending 1
Steps to Reproduce
DROPDATABASE IF EXISTS mysql_compat_group_subquery_min;
CREATEDATABASEmysql_compat_group_subquery_min;
USE mysql_compat_group_subquery_min;
CREATETABLEt (
id intprimary key,
status varchar(16),
payload int,
index idx_status(status,id)
);
INSERT INTO t VALUES
(1,'active',10),
(2,'active',20),
(3,'archived',30),
(4,'pending',40);
SELECT status,
(SELECTCOUNT(*) FROM t t2 WHEREt2.status=t.status) AS c
FROM t
GROUP BY status
ORDER BY status;
Additional information
MySQL 8.0.45 result:
status c
active 2
archived 1
pending 1
MatrixOne latest main at 0e8602b78 rejects the query with:
ERROR 1149 (HY000): SQL syntax error: column "t.status" must appear in the GROUP BY clause or be used in an aggregate function
This was found while backfilling aggregate / GROUP BY compatibility coverage with indexed tables.
Activity
LeftHandCold commentedon Jul 8, 2026
fixed
Ariznawlll commentedon Jul 8, 2026
Verified on latest
mainatbd2497354.Result: fixed. The grouped outer column can now be referenced by scalar correlated subqueries when it is already present in the outer
GROUP BYlist.Covered:
Actual result:
Also added extensions for correlated
MAX(...)inHAVINGand correlatedGROUP_CONCAT(...)over the grouped key.Added motr regression:
suites/14_issue_regression/t/issue_25352_grouped_correlated_subquery.testsuites/14_issue_regression/r/issue_25352_grouped_correlated_subquery.result