Based on StackOverflow question posted by Joyce Babu
https://stackoverflow.com/questions/45146830/non-grouping-field-used-in-having-clause-with-sub-query
With condition_pushdown_for_derived=on (which is default in 10.2) and sql_mode=ONLY_FULL_GROUP_BY , the query from the test case below returns an error:
Non-grouping field 'ct' is used in HAVING clause
The query appears to be valid, and without ONLY_FULL_GROUP_BY and/or with condition_pushdown_for_derived=off it works.
The error message is also incorrect, as there was no HAVING clause in query.
SET sql_mode = 'ONLY_FULL_GROUP_BY' ;
create table t1 (id int ,id2 int );
insert into t1 values (1,1), (2,3),(3,4), (7,2);
create table t2(id2 int );
insert t2 values (1),(2),(3);
SELECT * FROM t1
LEFT OUTER JOIN
( SELECT id2, COUNT (*) as ct FROM t2 GROUP BY id2) vc USING (id2)
WHERE (vc.ct>0);
Alice Sherepa
made changes -
2017-08-04 21:06
Field
Original Value
New Value
Affects Version/s
10.2.2
[ 22013
]
Elena Stepanova
made changes -
2017-08-04 21:31
Remote Link
This issue links to "StackOverflow (Web Link)"
[ 28017
]
Elena Stepanova
made changes -
2017-08-04 21:32
Description
Query returns error in ONLY_FULL_GROUP_BY sql_mode, while in "" returns correct results.
{noformat}
Non-grouping field 'ct' is used in HAVING clause
{noformat}
The error message is also incorrect, as there was no HAVING clause in query.
{code:sql}
SET sql_mode = 'ONLY_FULL_GROUP_BY';
create table t1 (id int,id2 int);
insert into t1 values (1,1), (2,3),(3,4), (7,2);
create table t2(id2 int);
insert t2 values (1),(2),(3);
SELECT * FROM t1
LEFT OUTER JOIN
(SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
WHERE (vc.ct>0);
{code}
Based on StackOverflow question posted by *Joyce Babu*
https://stackoverflow.com/questions/45146830/non-grouping-field-used-in-having-clause-with-sub-query
Query returns error in ONLY_FULL_GROUP_BY sql_mode, while in "" returns correct results.
{noformat}
Non-grouping field 'ct' is used in HAVING clause
{noformat}
The error message is also incorrect, as there was no HAVING clause in query.
{code:sql}
SET sql_mode = 'ONLY_FULL_GROUP_BY';
create table t1 (id int,id2 int);
insert into t1 values (1,1), (2,3),(3,4), (7,2);
create table t2(id2 int);
insert t2 values (1),(2),(3);
SELECT * FROM t1
LEFT OUTER JOIN
(SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
WHERE (vc.ct>0);
{code}
Elena Stepanova
made changes -
2017-08-04 21:34
Status
Open
[ 1
]
Confirmed
[ 10101
]
Elena Stepanova
made changes -
2017-08-04 21:41
Component/s
Data Manipulation - Subquery
[ 10107
]
Fix Version/s
10.2
[ 14601
]
Affects Version/s
10.3
[ 22126
]
Assignee
Igor Babaev
[ igor
]
Description
Based on StackOverflow question posted by *Joyce Babu*
https://stackoverflow.com/questions/45146830/non-grouping-field-used-in-having-clause-with-sub-query
Query returns error in ONLY_FULL_GROUP_BY sql_mode, while in "" returns correct results.
{noformat}
Non-grouping field 'ct' is used in HAVING clause
{noformat}
The error message is also incorrect, as there was no HAVING clause in query.
{code:sql}
SET sql_mode = 'ONLY_FULL_GROUP_BY';
create table t1 (id int,id2 int);
insert into t1 values (1,1), (2,3),(3,4), (7,2);
create table t2(id2 int);
insert t2 values (1),(2),(3);
SELECT * FROM t1
LEFT OUTER JOIN
(SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
WHERE (vc.ct>0);
{code}
Based on StackOverflow question posted by *Joyce Babu*
https://stackoverflow.com/questions/45146830/non-grouping-field-used-in-having-clause-with-sub-query
With {{condition_pushdown_for_derived=on}} (which is default in 10.2) and {{sql_mode=ONLY_FULL_GROUP_BY}}, the query from the test case below returns an error:
{noformat}
Non-grouping field 'ct' is used in HAVING clause
{noformat}
The query appears to be valid, and without {{ONLY_FULL_GROUP_BY}} and/or with {{condition_pushdown_for_derived=off}} it works.
The error message is also incorrect, as there was no HAVING clause in query.
{code:sql}
SET sql_mode = 'ONLY_FULL_GROUP_BY';
create table t1 (id int,id2 int);
insert into t1 values (1,1), (2,3),(3,4), (7,2);
create table t2(id2 int);
insert t2 values (1),(2),(3);
SELECT * FROM t1
LEFT OUTER JOIN
(SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
WHERE (vc.ct>0);
{code}
Summary
Improper error message in ONLY_FULL_GROUP_BY sql_mode
Improper error in ONLY_FULL_GROUP_BY sql_mode with condition_pushdown_for_derived=on
Igor Babaev (Inactive)
made changes -
2018-01-05 18:23
issue.field.resolutiondate
2018-01-05 18:23:06.0
2018-01-05 18:23:06.647
Igor Babaev (Inactive)
made changes -
2018-01-05 18:23
Fix Version/s
10.2.12
[ 22810
]
Fix Version/s
10.2
[ 14601
]
Resolution
Fixed
[ 1
]
Status
In Progress
[ 3
]
Closed
[ 6
]
Sergei Golubchik
made changes -
2021-12-06 21:45
Workflow
MariaDB v3
[ 81916
]
MariaDB v4
[ 152570
]
{"report":{"fcp":1604.9000000953674,"ttfb":496.80000019073486,"pageVisibility":"visible","entityId":62510,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"ad286c45-dbd0-447c-9725-3e8331106775","navigationType":0,"readyForUser":1763.7000002861023,"redirectCount":0,"resourceLoadedEnd":1247,"resourceLoadedStart":516.3000001907349,"resourceTiming":[{"duration":119.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":516.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":516.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":635.5,"responseStart":0,"secureConnectionStart":0},{"duration":120.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":516.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":516.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":637.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":413.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":516.7000002861023,"connectEnd":516.7000002861023,"connectStart":516.7000002861023,"domainLookupEnd":516.7000002861023,"domainLookupStart":516.7000002861023,"fetchStart":516.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":649.6000003814697,"responseEnd":930,"responseStart":698.3000001907349,"secureConnectionStart":516.7000002861023},{"duration":721.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":516.9000000953674,"connectEnd":516.9000000953674,"connectStart":516.9000000953674,"domainLookupEnd":516.9000000953674,"domainLookupStart":516.9000000953674,"fetchStart":516.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":650.3000001907349,"responseEnd":1238.8000001907349,"responseStart":714.3000001907349,"secureConnectionStart":516.9000000953674},{"duration":209.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":517.1000003814697,"connectEnd":517.1000003814697,"connectStart":517.1000003814697,"domainLookupEnd":517.1000003814697,"domainLookupStart":517.1000003814697,"fetchStart":517.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":651.2000002861023,"responseEnd":726.4000000953674,"responseStart":719.5,"secureConnectionStart":517.1000003814697},{"duration":203.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":517.3000001907349,"connectEnd":517.3000001907349,"connectStart":517.3000001907349,"domainLookupEnd":517.3000001907349,"domainLookupStart":517.3000001907349,"fetchStart":517.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":651.6000003814697,"responseEnd":720.9000000953674,"responseStart":715.2000002861023,"secureConnectionStart":517.3000001907349},{"duration":210.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":517.5,"connectEnd":517.5,"connectStart":517.5,"domainLookupEnd":517.5,"domainLookupStart":517.5,"fetchStart":517.5,"redirectEnd":0,"redirectStart":0,"requestStart":652.7000002861023,"responseEnd":728.3000001907349,"responseStart":721.3000001907349,"secureConnectionStart":517.5},{"duration":121.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":517.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":517.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":638.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":212,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":518.1000003814697,"connectEnd":518.1000003814697,"connectStart":518.1000003814697,"domainLookupEnd":518.1000003814697,"domainLookupStart":518.1000003814697,"fetchStart":518.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":653.5,"responseEnd":730.1000003814697,"responseStart":723.3000001907349,"secureConnectionStart":518.1000003814697},{"duration":121.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":518.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":518.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":640,"responseStart":0,"secureConnectionStart":0},{"duration":214,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":518.4000000953674,"connectEnd":518.4000000953674,"connectStart":518.4000000953674,"domainLookupEnd":518.4000000953674,"domainLookupStart":518.4000000953674,"fetchStart":518.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":654,"responseEnd":732.4000000953674,"responseStart":724.3000001907349,"secureConnectionStart":518.4000000953674},{"duration":601.5999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":519.3000001907349,"connectEnd":519.3000001907349,"connectStart":519.3000001907349,"domainLookupEnd":519.3000001907349,"domainLookupStart":519.3000001907349,"fetchStart":519.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":845.2000002861023,"responseEnd":1120.9000000953674,"responseStart":1084.9000000953674,"secureConnectionStart":519.3000001907349},{"duration":727.6999998092651,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":519.3000001907349,"connectEnd":519.3000001907349,"connectStart":519.3000001907349,"domainLookupEnd":519.3000001907349,"domainLookupStart":519.3000001907349,"fetchStart":519.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":756.5,"responseEnd":1247,"responseStart":1241.1000003814697,"secureConnectionStart":519.3000001907349},{"duration":397.2999997138977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1136.7000002861023,"connectEnd":1136.7000002861023,"connectStart":1136.7000002861023,"domainLookupEnd":1136.7000002861023,"domainLookupStart":1136.7000002861023,"fetchStart":1136.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":1490.1000003814697,"responseEnd":1534,"responseStart":1532,"secureConnectionStart":1136.7000002861023}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":288,"responseStart":497,"responseEnd":507,"domLoading":513,"domInteractive":1877,"domContentLoadedEventStart":1877,"domContentLoadedEventEnd":1982,"domComplete":4149,"loadEventStart":4149,"loadEventEnd":4150,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1828.8000001907349},{"name":"bigPipe.sidebar-id.end","time":1829.6000003814697},{"name":"bigPipe.activity-panel-pipe-id.start","time":1829.8000001907349},{"name":"bigPipe.activity-panel-pipe-id.end","time":1834.7000002861023},{"name":"activityTabFullyLoaded","time":2012.6000003814697}],"measures":[],"correlationId":"e2dfeded520d99","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":127,"dbReadsTimeInMs":20,"dbConnsTimeInMs":29,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
MariaDB [test]> select version();
+----------------+
| version() |
+----------------+
| 10.2.2-MariaDB |
+----------------+
1 row in set (0.00 sec)
MariaDB [test]> SET sql_mode = 'ONLY_FULL_GROUP_BY';
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> explain extended SELECT * FROM t1
-> LEFT OUTER JOIN
-> (SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
-> WHERE (vc.ct>0);
ERROR 1463 (42000): Non-grouping field 'ct' is used in HAVING clause
MariaDB [test]> SET optimizer_switch='condition_pushdown_for_derived=off';
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> explain extended SELECT * FROM t1
-> LEFT OUTER JOIN
-> (SELECT id2, COUNT(*) as ct FROM t2 GROUP BY id2) vc USING (id2)
-> WHERE (vc.ct>0);
+------+-------------+------------+------+---------------+------+---------+-------------+------+----------+---------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+------------+------+---------------+------+---------+-------------+------+----------+---------------------------------+
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 8 | 100.00 | Using where |
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 5 | test.t1.id2 | 2 | 100.00 | Using where |
| 2 | DERIVED | t2 | ALL | NULL | NULL | NULL | NULL | 6 | 100.00 | Using temporary; Using filesort |
+------+-------------+------------+------+---------------+------+---------+-------------+------+----------+---------------------------------+
3 rows in set, 1 warning (0.00 sec)