Type:
Bug
Priority:
Major
Resolution:
Unresolved
Affects Version/s:
10.6.11 , 5.5(EOL) , 10.0(EOL) , 10.1(EOL) , 10.2(EOL) , 10.3(EOL) , 10.4(EOL) , 10.6 , 10.7(EOL) , 10.8(EOL) , 10.9(EOL) , 10.10(EOL)
The query with HAVING from the following test case
SET @@sql_mode = '' ;
CREATE TABLE series (
val INT (10) UNSIGNED NOT NULL
);
INSERT INTO series VALUES (1);
CREATE TABLE seq_calls (
c INT
);
INSERT INTO seq_calls VALUES (0);
DELIMITER |;
CREATE FUNCTION next_seq_value() RETURNS INT
BEGIN
DECLARE next_val INT ;
SELECT val INTO next_val FROM series;
UPDATE series SET val=mod(val + 1, 2);
UPDATE seq_calls SET c=c+1;
RETURN next_val;
END ;
|
DELIMITER ;|
CREATE TABLE t1 (t INT , u INT , KEY (t));
INSERT INTO t1 VALUES (10, 10), (11, 11), (12, 12), (12, 13),(14, 15), (15, 16),
(16, 17), (17, 18);
ANALYZE TABLE t1;
SELECT * FROM series, seq_calls;
SELECT DISTINCT t1.t, next_seq_value() r FROM t1, t1 P
WHERE P.t = t1.t HAVING r = 1 ORDER BY t1.u;
DROP TABLE t1;
DROP FUNCTION next_seq_value;
DROP TABLE series, seq_calls;
returns a wrong result set:
MariaDB [test]> SELECT DISTINCT t1.t, next_seq_value() r FROM t1, t1 P
-> WHERE P.t = t1.t HAVING r = 1 ORDER BY t1.u;
+------+------+
| t | r |
+------+------+
| 10 | 0 |
| 11 | 0 |
| 12 | 0 |
| 14 | 0 |
| 15 | 0 |
| 16 | 0 |
| 17 | 0 |
+------+------+
Igor Babaev
made changes -
2017-10-30 04:53
Field
Original Value
New Value
Summary
Wrong result set from a query with DISTINCT and SF call in select list
Wrong result set from a query with DISTINCT and HAVING over a SF call
Igor Babaev
made changes -
2017-10-30 04:57
Description
The query with HAVING from the following test case
{noformat}
SET @@sql_mode = '';
CREATE TABLE series (
val INT(10) UNSIGNED NOT NULL
);
INSERT INTO series VALUES(1);
CREATE TABLE seq_calls (
c INT
);
INSERT INTO seq_calls VALUES(0);
DELIMITER |;
CREATE FUNCTION next_seq_value() RETURNS INT
BEGIN
DECLARE next_val INT;
SELECT val INTO next_val FROM series;
UPDATE series SET val=mod(val + 1, 2);
UPDATE seq_calls SET c=c+1;
RETURN next_val;
END;
|
DELIMITER ;|
CREATE TABLE t1 (t INT, u INT, KEY(t));
INSERT INTO t1 VALUES(10, 10), (11, 11), (12, 12), (12, 13),(14, 15), (15, 16),
(16, 17), (17, 18);
ANALYZE TABLE t1;
SELECT * FROM series, seq_calls;
SELECT DISTINCT t1.t, next_seq_value() r FROM t1, t1 P
WHERE P.t = t1.t HAVING r = 1 ORDER BY t1.u;
DROP TABLE t1;
DROP FUNCTION next_seq_value;
DROP TABLE series, seq_calls;
{noformat}
returns a wrong result set:
{noformat}
MariaDB [test]> SELECT DISTINCT t1.t, next_seq_value() r FROM t1, t1 P
-> WHERE P.t = t1.t HAVING r = 1 ORDER BY t1.u;
+------+------+
| t | r |
+------+------+
| 10 | 0 |
| 11 | 0 |
| 12 | 0 |
| 14 | 0 |
| 15 | 0 |
| 16 | 0 |
| 17 | 0 |
+------+------+
{noformat}
Igor Babaev
made changes -
2017-10-30 04:59
Affects Version/s
5.5
[ 15800
]
Affects Version/s
10.0
[ 16000
]
Affects Version/s
10.1
[ 16100
]
Affects Version/s
10.2
[ 14601
]
Igor Babaev
made changes -
2017-10-30 05:00
Component/s
Optimizer
[ 10200
]
Elena Stepanova
made changes -
2017-11-07 17:27
Fix Version/s
10.2
[ 14601
]
Assignee
Igor Babaev
[ igor
]
Sergei Golubchik
made changes -
2021-12-06 21:33
Workflow
MariaDB v3
[ 83341
]
MariaDB v4
[ 140484
]
Sergei Golubchik
made changes -
2022-12-01 09:10
Description
The query with HAVING from the following test case
{noformat}
SET @@sql_mode = '';
CREATE TABLE series (
val INT(10) UNSIGNED NOT NULL
);
INSERT INTO series VALUES(1);
CREATE TABLE seq_calls (
c INT
);
INSERT INTO seq_calls VALUES(0);
DELIMITER |;
CREATE FUNCTION next_seq_value() RETURNS INT
BEGIN
DECLARE next_val INT;
SELECT val INTO next_val FROM series;
UPDATE series SET val=mod(val + 1, 2);
UPDATE seq_calls SET c=c+1;
RETURN next_val;
END;
|
DELIMITER ;|
CREATE TABLE t1 (t INT, u INT, KEY(t));
INSERT INTO t1 VALUES(10, 10), (11, 11), (12, 12), (12, 13),(14, 15), (15, 16),
(16, 17), (17, 18);
ANALYZE TABLE t1;
SELECT * FROM series, seq_calls;
SELECT DISTINCT t1.t, next_seq_value() r FROM t1, t1 P
WHERE P.t = t1.t HAVING r = 1 ORDER BY t1.u;
DROP TABLE t1;
DROP FUNCTION next_seq_value;
DROP TABLE series, seq_calls;
{noformat}
returns a wrong result set:
{noformat}
MariaDB [test]> SELECT DISTINCT t1.t, next_seq_value() r FROM t1, t1 P
-> WHERE P.t = t1.t HAVING r = 1 ORDER BY t1.u;
+------+------+
| t | r |
+------+------+
| 10 | 0 |
| 11 | 0 |
| 12 | 0 |
| 14 | 0 |
| 15 | 0 |
| 16 | 0 |
| 17 | 0 |
+------+------+
{noformat}
The query with HAVING from the following test case
{code:sql}
SET @@sql_mode = '';
CREATE TABLE series (
val INT(10) UNSIGNED NOT NULL
);
INSERT INTO series VALUES(1);
CREATE TABLE seq_calls (
c INT
);
INSERT INTO seq_calls VALUES(0);
DELIMITER |;
CREATE FUNCTION next_seq_value() RETURNS INT
BEGIN
DECLARE next_val INT;
SELECT val INTO next_val FROM series;
UPDATE series SET val=mod(val + 1, 2);
UPDATE seq_calls SET c=c+1;
RETURN next_val;
END;
|
DELIMITER ;|
CREATE TABLE t1 (t INT, u INT, KEY(t));
INSERT INTO t1 VALUES(10, 10), (11, 11), (12, 12), (12, 13),(14, 15), (15, 16),
(16, 17), (17, 18);
ANALYZE TABLE t1;
SELECT * FROM series, seq_calls;
SELECT DISTINCT t1.t, next_seq_value() r FROM t1, t1 P
WHERE P.t = t1.t HAVING r = 1 ORDER BY t1.u;
DROP TABLE t1;
DROP FUNCTION next_seq_value;
DROP TABLE series, seq_calls;
{code}
returns a wrong result set:
{noformat}
MariaDB [test]> SELECT DISTINCT t1.t, next_seq_value() r FROM t1, t1 P
-> WHERE P.t = t1.t HAVING r = 1 ORDER BY t1.u;
+------+------+
| t | r |
+------+------+
| 10 | 0 |
| 11 | 0 |
| 12 | 0 |
| 14 | 0 |
| 15 | 0 |
| 16 | 0 |
| 17 | 0 |
+------+------+
{noformat}
Alice Sherepa
made changes -
2022-12-01 09:38
Affects Version/s
10.6.11
[ 28441
]
Affects Version/s
10.3
[ 22126
]
Affects Version/s
10.4
[ 22408
]
Affects Version/s
10.6
[ 24028
]
Affects Version/s
10.7
[ 24805
]
Affects Version/s
10.8
[ 26121
]
Affects Version/s
10.9
[ 26905
]
Affects Version/s
10.10
[ 27530
]
Alice Sherepa
made changes -
2022-12-01 09:38
Fix Version/s
10.3
[ 22126
]
Fix Version/s
10.4
[ 22408
]
Fix Version/s
10.5
[ 23123
]
Fix Version/s
10.6
[ 24028
]
Fix Version/s
10.7
[ 24805
]
Fix Version/s
10.8
[ 26121
]
Fix Version/s
10.9
[ 26905
]
Fix Version/s
10.2
[ 14601
]
Alice Sherepa
made changes -
2022-12-01 09:53
Status
Open
[ 1
]
Confirmed
[ 10101
]
Michael Widenius
made changes -
2023-01-27 14:11
Assignee
Igor Babaev
[ igor
]
Michael Widenius
[ monty
]
Julien Fritsch
made changes -
2023-03-03 17:31
Fix Version/s
10.7
[ 24805
]
Julien Fritsch
made changes -
2023-04-27 14:19
Fix Version/s
10.3
[ 22126
]
Julien Fritsch
made changes -
2023-04-27 14:49
Fix Version/s
10.8
[ 26121
]
Julien Fritsch
made changes -
2023-11-28 10:39
Fix Version/s
10.9
[ 26905
]
Julien Fritsch
made changes -
2024-09-10 15:07
Fix Version/s
10.4
[ 22408
]
{"report":{"fcp":1176.4000000953674,"ttfb":372.09999990463257,"pageVisibility":"visible","entityId":63840,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"47502cb6-b6e9-40ac-b8f0-a62f78ad803a","navigationType":0,"readyForUser":1291.0999999046326,"redirectCount":0,"resourceLoadedEnd":1340.4000000953674,"resourceLoadedStart":378.19999980926514,"resourceTiming":[{"duration":216,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":378.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":378.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":594.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":217.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":378.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":378.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":595.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":265.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":378.59999990463257,"connectEnd":378.59999990463257,"connectStart":378.59999990463257,"domainLookupEnd":378.59999990463257,"domainLookupStart":378.59999990463257,"fetchStart":378.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":378.59999990463257,"responseEnd":643.8000001907349,"responseStart":643.8000001907349,"secureConnectionStart":378.59999990463257},{"duration":360.5,"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":378.69999980926514,"connectEnd":378.69999980926514,"connectStart":378.69999980926514,"domainLookupEnd":378.69999980926514,"domainLookupStart":378.69999980926514,"fetchStart":378.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":378.69999980926514,"responseEnd":739.1999998092651,"responseStart":739.1999998092651,"secureConnectionStart":378.69999980926514},{"duration":366.59999990463257,"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":379,"connectEnd":379,"connectStart":379,"domainLookupEnd":379,"domainLookupStart":379,"fetchStart":379,"redirectEnd":0,"redirectStart":0,"requestStart":379,"responseEnd":745.5999999046326,"responseStart":745.5999999046326,"secureConnectionStart":379},{"duration":366.80000019073486,"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":379.19999980926514,"connectEnd":379.19999980926514,"connectStart":379.19999980926514,"domainLookupEnd":379.19999980926514,"domainLookupStart":379.19999980926514,"fetchStart":379.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":379.19999980926514,"responseEnd":746,"responseStart":746,"secureConnectionStart":379.19999980926514},{"duration":367,"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":379.40000009536743,"connectEnd":379.40000009536743,"connectStart":379.40000009536743,"domainLookupEnd":379.40000009536743,"domainLookupStart":379.40000009536743,"fetchStart":379.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":379.40000009536743,"responseEnd":746.4000000953674,"responseStart":746.4000000953674,"secureConnectionStart":379.40000009536743},{"duration":415.90000009536743,"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":379.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":379.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":795.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":367.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":379.69999980926514,"connectEnd":379.69999980926514,"connectStart":379.69999980926514,"domainLookupEnd":379.69999980926514,"domainLookupStart":379.69999980926514,"fetchStart":379.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":379.69999980926514,"responseEnd":746.9000000953674,"responseStart":746.9000000953674,"secureConnectionStart":379.69999980926514},{"duration":416,"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":379.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":379.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":795.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":367.5,"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":380,"connectEnd":380,"connectStart":380,"domainLookupEnd":380,"domainLookupStart":380,"fetchStart":380,"redirectEnd":0,"redirectStart":0,"requestStart":380,"responseEnd":747.5,"responseStart":747.5,"secureConnectionStart":380},{"duration":688.0999999046326,"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":392.5,"connectEnd":392.5,"connectStart":392.5,"domainLookupEnd":392.5,"domainLookupStart":392.5,"fetchStart":392.5,"redirectEnd":0,"redirectStart":0,"requestStart":392.5,"responseEnd":1080.5999999046326,"responseStart":1080.5999999046326,"secureConnectionStart":392.5},{"duration":886.9000000953674,"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":392.59999990463257,"connectEnd":392.59999990463257,"connectStart":392.59999990463257,"domainLookupEnd":392.59999990463257,"domainLookupStart":392.59999990463257,"fetchStart":392.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":392.59999990463257,"responseEnd":1279.5,"responseStart":1279.5,"secureConnectionStart":392.59999990463257},{"duration":250.90000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":830.1999998092651,"connectEnd":830.1999998092651,"connectStart":830.1999998092651,"domainLookupEnd":830.1999998092651,"domainLookupStart":830.1999998092651,"fetchStart":830.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":830.1999998092651,"responseEnd":1081.0999999046326,"responseStart":1081.0999999046326,"secureConnectionStart":830.1999998092651},{"duration":234.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1106,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1106,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1340.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":184.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1107.4000000953674,"connectEnd":1107.4000000953674,"connectStart":1107.4000000953674,"domainLookupEnd":1107.4000000953674,"domainLookupStart":1107.4000000953674,"fetchStart":1107.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1107.4000000953674,"responseEnd":1291.8000001907349,"responseStart":1291.8000001907349,"secureConnectionStart":1107.4000000953674},{"duration":225,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":1107.8000001907349,"connectEnd":1107.8000001907349,"connectStart":1107.8000001907349,"domainLookupEnd":1107.8000001907349,"domainLookupStart":1107.8000001907349,"fetchStart":1107.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1107.8000001907349,"responseEnd":1332.8000001907349,"responseStart":1332.8000001907349,"secureConnectionStart":1107.8000001907349},{"duration":286.09999990463257,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1164.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1164.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1450.5,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":145,"responseStart":373,"responseEnd":383,"domLoading":377,"domInteractive":1524,"domContentLoadedEventStart":1524,"domContentLoadedEventEnd":1595,"domComplete":1986,"loadEventStart":1987,"loadEventEnd":1987,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1452.8000001907349},{"name":"bigPipe.sidebar-id.end","time":1453.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":1453.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":1470.9000000953674},{"name":"activityTabFullyLoaded","time":1635.4000000953674}],"measures":[],"correlationId":"1182a1b8144661","effectiveType":"4g","downlink":9,"rtt":0,"serverDuration":160,"dbReadsTimeInMs":27,"dbConnsTimeInMs":38,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
rmysql-5.6, mysql-5.7 also return wrong result sets.
mysql-8.0 returns the right result set.