Type:
Bug
Priority:
Major
Resolution:
Unresolved
Affects Version/s:
11.8.0 , 10.5 , 10.6 , 10.11 , 11.4 , 11.8
Environment:
git rev-parse HEAD
11a6c1b30a12c448ddfe05e1b818a6a228e90e43
Description: The behavior of the INTERVAL function is inconsistent when used in a SELECT query. The first query, which uses the INTERVAL function and selects columns, returns correct results. However, when the same INTERVAL function is used in the WHERE clause to filter the results, the query returns an empty set. These results should be consistent, but they are not.
Steps to Reproduce:
DROP TABLE IF EXISTS `t0`;
CREATE TABLE `t0` (
`c1` double ,
`c2` double
);
INSERT INTO `t0` VALUES ( 23 ,- 16 );
query1:
select distinct
subq_0.c_0 as c_0,
subq_0.c_1 as c_1,
subq_0.c_2 as c_2,
INTERVAL(subq_0.c_0,
subq_0.c_1,
subq_0.c_2) as c_7,
(INTERVAL(subq_0.c_0,
subq_0.c_1,
subq_0.c_2)
> 0 ) as w_1
from
(select distinct
ref_0.c1 as c_0,
ref_0.c2 as c_1,
(ref_0.c2) / (ref_0.c1) as c_2
from
t0 as ref_0
) as subq_0
where (INTERVAL(subq_0.c_0,
subq_0.c_1,
subq_0.c_2))
output:
+------+------+---------------------+-----+-----+
| c_0 | c_1 | c_2 | c_7 | w_1 |
+------+------+---------------------+-----+-----+
| 23 | - 16 | - 0.6956521739130435 | 2 | 1 |
+------+------+---------------------+-----+-----+
1 row in set ( 0.00 sec)
query2:
select distinct
subq_0.c_0 as c_0,
subq_0.c_1 as c_1,
subq_0.c_2 as c_2,
INTERVAL(subq_0.c_0,
subq_0.c_1,
subq_0.c_2) as c_7,
(INTERVAL(subq_0.c_0,
subq_0.c_1,
subq_0.c_2)
> 0 ) as w_1
from
(select distinct
ref_0.c1 as c_0,
ref_0.c2 as c_1,
(ref_0.c2) / (ref_0.c1) as c_2
from
t0 as ref_0
) as subq_0
where (INTERVAL(subq_0.c_0,
subq_0.c_1,
subq_0.c_2)> 0 )
output:
Expected Behavior:
Both queries should return the same result
Actual Behavior:
but the second query returns an empty set, while the first query returns the expected row.
{"report":{"fcp":1476.2000000476837,"ttfb":633.2000000476837,"pageVisibility":"visible","entityId":133338,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"90e64a1e-d88e-4669-b2cc-5ea45c37502b","navigationType":0,"readyForUser":1564.5,"redirectCount":0,"resourceLoadedEnd":1197.2999999523163,"resourceLoadedStart":642.0999999046326,"resourceTiming":[{"duration":84.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":642.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":642.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":726.5,"responseStart":0,"secureConnectionStart":0},{"duration":84.29999995231628,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":642.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":642.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":726.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":392.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":642.5,"connectEnd":642.5,"connectStart":642.5,"domainLookupEnd":642.5,"domainLookupStart":642.5,"fetchStart":642.5,"redirectEnd":0,"redirectStart":0,"requestStart":729.7000000476837,"responseEnd":1034.9000000953674,"responseStart":766.5,"secureConnectionStart":642.5},{"duration":127.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":642.7000000476837,"connectEnd":642.7000000476837,"connectStart":642.7000000476837,"domainLookupEnd":642.7000000476837,"domainLookupStart":642.7000000476837,"fetchStart":642.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":732.4000000953674,"responseEnd":770.2000000476837,"responseStart":767.7000000476837,"secureConnectionStart":642.7000000476837},{"duration":554.5999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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","startTime":642.7000000476837,"connectEnd":642.7000000476837,"connectStart":642.7000000476837,"domainLookupEnd":642.7000000476837,"domainLookupStart":642.7000000476837,"fetchStart":642.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":730.7999999523163,"responseEnd":1197.2999999523163,"responseStart":811.5999999046326,"secureConnectionStart":642.7000000476837},{"duration":130.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":642.7999999523163,"connectEnd":642.7999999523163,"connectStart":642.7999999523163,"domainLookupEnd":642.7999999523163,"domainLookupStart":642.7999999523163,"fetchStart":642.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":733.2000000476837,"responseEnd":772.9000000953674,"responseStart":768.7000000476837,"secureConnectionStart":642.7999999523163},{"duration":130.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":643,"connectEnd":643,"connectStart":643,"domainLookupEnd":643,"domainLookupStart":643,"fetchStart":643,"redirectEnd":0,"redirectStart":0,"requestStart":733.4000000953674,"responseEnd":773.0999999046326,"responseStart":770.5,"secureConnectionStart":643},{"duration":89.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":643.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":643.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":732.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":90.70000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":643.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":643.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":733.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":130.20000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":643.2000000476837,"connectEnd":643.2000000476837,"connectStart":643.2000000476837,"domainLookupEnd":643.2000000476837,"domainLookupStart":643.2000000476837,"fetchStart":643.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":735.7999999523163,"responseEnd":773.4000000953674,"responseStart":771,"secureConnectionStart":643.2000000476837},{"duration":130.60000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":643.2999999523163,"connectEnd":643.2999999523163,"connectStart":643.2999999523163,"domainLookupEnd":643.2999999523163,"domainLookupStart":643.2999999523163,"fetchStart":643.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":736.4000000953674,"responseEnd":773.9000000953674,"responseStart":771.7000000476837,"secureConnectionStart":643.2999999523163},{"duration":483.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":646.7999999523163,"connectEnd":646.7999999523163,"connectStart":646.7999999523163,"domainLookupEnd":646.7999999523163,"domainLookupStart":646.7999999523163,"fetchStart":646.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":853.5999999046326,"responseEnd":1130.7000000476837,"responseStart":1126.7000000476837,"secureConnectionStart":646.7999999523163},{"duration":484,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":646.9000000953674,"connectEnd":646.9000000953674,"connectStart":646.9000000953674,"domainLookupEnd":646.9000000953674,"domainLookupStart":646.9000000953674,"fetchStart":646.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":854.5,"responseEnd":1130.9000000953674,"responseStart":1127.4000000953674,"secureConnectionStart":646.9000000953674},{"duration":117.09999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1185.2000000476837,"connectEnd":1185.2000000476837,"connectStart":1185.2000000476837,"domainLookupEnd":1185.2000000476837,"domainLookupStart":1185.2000000476837,"fetchStart":1185.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":1271.4000000953674,"responseEnd":1302.2999999523163,"responseStart":1301.5999999046326,"secureConnectionStart":1185.2000000476837},{"duration":255.90000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1430.0999999046326,"connectEnd":1430.0999999046326,"connectStart":1430.0999999046326,"domainLookupEnd":1430.0999999046326,"domainLookupStart":1430.0999999046326,"fetchStart":1430.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1650.5999999046326,"responseEnd":1686,"responseStart":1682.9000000953674,"secureConnectionStart":1430.0999999046326},{"duration":181.79999995231628,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1469,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1469,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1650.7999999523163,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":451,"responseStart":633,"responseEnd":642,"domLoading":636,"domInteractive":1640,"domContentLoadedEventStart":1640,"domContentLoadedEventEnd":1713,"domComplete":1992,"loadEventStart":1992,"loadEventEnd":1993,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1613.0999999046326},{"name":"bigPipe.sidebar-id.end","time":1613.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1614.2000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1616.7999999523163},{"name":"activityTabFullyLoaded","time":1767.0999999046326}],"measures":[],"correlationId":"99103cb47f2175","effectiveType":"4g","downlink":9.9,"rtt":0,"serverDuration":98,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks! I repeated as described on 10.5-11.8, Myism/InnoDB. Without DISTINCT clause - returnes results:
MariaDB [test]> CREATE TABLE t0 ( c1 double, c2 double);
Query OK, 0 rows affected (0,034 sec)
MariaDB [test]> INSERT INTO t0 VALUES (23, -16);
Query OK, 1 row affected (0,006 sec)
MariaDB [test]> SELECT 1 FROM (SELECT DISTINCT c1, c2, c2 / c1 AS c FROM t0 ) dt WHERE interval(dt.c1, dt.c2, dt.c) ;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0,002 sec)
MariaDB [test]> SELECT 1 FROM (SELECT DISTINCT c1, c2, c2 / c1 AS c FROM t0 ) dt WHERE interval(dt.c1, dt.c2, dt.c)>0 ;
Empty set (0,001 sec)
MariaDB [test]> explain extended SELECT 1 FROM (SELECT DISTINCT c1, c2, c2 / c1 AS c FROM t0 ) dt WHERE interval(dt.c1, dt.c2, dt.c)>0 ;
+------+-------------+------------+------+---------------+------+---------+------+------+----------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+------------------------------+
| 1 | PRIMARY | <derived2> | ALL | NULL | NULL | NULL | NULL | 2 | 100.00 | Using where |
| 2 | DERIVED | t0 | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using where; Using temporary |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+------------------------------+
2 rows in set, 1 warning (0,003 sec)
Note (Code 1003): /* select#1 */ select 1 AS `1` from (/* select#2 */ select distinct `test`.`t0`.`c1` AS `c1`,`test`.`t0`.`c2` AS `c2`,`test`.`t0`.`c2` / `test`.`t0`.`c1` AS `c` from `test`.`t0` where interval(`test`.`t0`.`c1`,`test`.`t0`.`c2`,`test`.`t0`.`c2` / `test`.`t0`.`c1`) > 0) `dt` where interval(`dt`.`c1`,`dt`.`c2`,`dt`.`c`) > 0
MariaDB [test]> SELECT 1 FROM (SELECT c1, c2, c2 / c1 AS c FROM t0 ) dt WHERE interval(dt.c1, dt.c2, dt.c)>0 ;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0,003 sec)
MariaDB [test]> explain extended SELECT 1 FROM (SELECT c1, c2, c2 / c1 AS c FROM t0 ) dt WHERE interval(dt.c1, dt.c2, dt.c)>0 ;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| 1 | SIMPLE | t0 | ALL | NULL | NULL | NULL | NULL | 1 | 100.00 | Using where |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0,003 sec)
Note (Code 1003): select 1 AS `1` from `test`.`t0` where interval(`test`.`t0`.`c1`,`test`.`t0`.`c2`,`test`.`t0`.`c2` / `test`.`t0`.`c1`) > 0
MariaDB [test]> select interval(dt.c1, dt.c2, dt.c) FROM (SELECT c1, c2, c2 / c1 AS c FROM t0 ) dt;
+------------------------------+
| interval(dt.c1, dt.c2, dt.c) |
+------------------------------+
| 2 |
+------------------------------+
1 row in set (0,003 sec)
MariaDB [test]> DROP TABLE IF EXISTS t0;
Query OK, 0 rows affected (0,033 sec)
MariaDB [test]> CREATE TABLE t0 ( c1 double, c2 double);
Query OK, 0 rows affected (0,032 sec)
MariaDB [test]> INSERT INTO t0 VALUES (23, -16);
Query OK, 1 row affected (0,006 sec)
MariaDB [test]> SELECT 1 FROM (SELECT DISTINCT c1, c2, c2 / c1 AS c FROM t0 ) dt WHERE interval(dt.c1, dt.c2, dt.c) ;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0,001 sec)
MariaDB [test]> SELECT 1 FROM (SELECT DISTINCT c1, c2, c2 / c1 AS c FROM t0 ) dt WHERE interval(dt.c1, dt.c2, dt.c)>0 ;
Empty set (0,001 sec)