I create and populate a table like this:
DROP TABLE IF EXISTS t1;
|
CREATE OR REPLACE TABLE t1 (a TIME);
|
INSERT INTO t1 VALUES ('00:00:10'),('00:00:20');
|
Now I do some time arithmetic:
SELECT a, SUBTIME(a,TIME'00:00:01'), ADDTIME(a,TIME'00:00:01') FROM t1;
|
+----------+---------------------------+---------------------------+
|
| a | SUBTIME(a,TIME'00:00:01') | ADDTIME(a,TIME'00:00:01') |
|
+----------+---------------------------+---------------------------+
|
| 00:00:10 | 00:00:09 | 00:00:11 |
|
| 00:00:20 | 00:00:19 | 00:00:21 |
|
+----------+---------------------------+---------------------------+
|
Now I put the same arithmetic expressions into WHERE:
SELECT * FROM t1 WHERE SUBTIME(a,TIME'00:00:01')=TIME'00:00:09';
|
+----------+
|
| a |
|
+----------+
|
| 00:00:10 |
|
+----------+
|
SELECT * FROM t1 WHERE ADDTIME(a,TIME'00:00:01')<=TIME'00:00:09';
|
So far so good:
- The first query correctly returned one row
- The second query correctly returned empty set
Now I mix these two conditions using AND and expect to get empty set again:
SELECT * FROM t1 WHERE SUBTIME(a,TIME'00:00:01')=TIME'00:00:09' AND ADDTIME(a,TIME'00:00:01')<=TIME'00:00:09';
|
+----------+
|
| a |
|
+----------+
|
| 00:00:10 |
|
+----------+
|
However, the server returned one row. This is wrong!
The following EXPLAIN script demonstrates that the second condition part was erroneously eliminated by the optimizer:
EXPLAIN EXTENDED SELECT * FROM t1 WHERE SUBTIME(a,TIME'00:00:01')=TIME'00:00:09' AND ADDTIME(a,TIME'00:00:01')<=TIME'00:00:09';
|
SHOW WARNINGS;
|
...
|
+-------+------+---------------------------------------------------------------------------------------------------------------+
|
| Level | Code | Message |
|
+-------+------+---------------------------------------------------------------------------------------------------------------+
|
| Note | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where subtime(`test`.`t1`.`a`,TIME'00:00:01') = TIME'00:00:09' |
|
+-------+------+---------------------------------------------------------------------------------------------------------------+
|
Notice, there is no the ADDTIME() condition in the optimzed query.
The problem happens because Item_func_add_time::func_name() erroneously always returns the same value, which makes the equal expression propagation code erroneously think ADDTIME() and SUBTIME() are equal to each other.
Item_func_add_time::func_name() should return three different names depending on the exact SQL function it handles:
- timestamp
- addtime
- subtime
- relates to
-
MDEV-16398
Spider Creates Query With Non-Existent Function
-
-
Closed
{"report":{"fcp":753.5999994277954,"ttfb":165.89999961853027,"pageVisibility":"visible","entityId":68988,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"ea8ec40d-3834-43b6-9469-d0a58359a9a0","navigationType":0,"readyForUser":842.8999996185303,"redirectCount":0,"resourceLoadedEnd":774.3999996185303,"resourceLoadedStart":171,"resourceTiming":[{"duration":15,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":171,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":171,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":186,"responseStart":0,"secureConnectionStart":0},{"duration":15.100000381469727,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":171.29999923706055,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":171.29999923706055,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":186.39999961853027,"responseStart":0,"secureConnectionStart":0},{"duration":70.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":171.5,"connectEnd":171.5,"connectStart":171.5,"domainLookupEnd":171.5,"domainLookupStart":171.5,"fetchStart":171.5,"redirectEnd":0,"redirectStart":0,"requestStart":171.5,"responseEnd":242.19999980926514,"responseStart":242.19999980926514,"secureConnectionStart":171.5},{"duration":155.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":171.69999980926514,"connectEnd":171.69999980926514,"connectStart":171.69999980926514,"domainLookupEnd":171.69999980926514,"domainLookupStart":171.69999980926514,"fetchStart":171.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":171.69999980926514,"responseEnd":327.5,"responseStart":327.5,"secureConnectionStart":171.69999980926514},{"duration":159.60000038146973,"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":171.89999961853027,"connectEnd":171.89999961853027,"connectStart":171.89999961853027,"domainLookupEnd":171.89999961853027,"domainLookupStart":171.89999961853027,"fetchStart":171.89999961853027,"redirectEnd":0,"redirectStart":0,"requestStart":171.89999961853027,"responseEnd":331.5,"responseStart":331.5,"secureConnectionStart":171.89999961853027},{"duration":160,"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":172.0999994277954,"connectEnd":172.0999994277954,"connectStart":172.0999994277954,"domainLookupEnd":172.0999994277954,"domainLookupStart":172.0999994277954,"fetchStart":172.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":172.0999994277954,"responseEnd":332.0999994277954,"responseStart":332.0999994277954,"secureConnectionStart":172.0999994277954},{"duration":160.20000076293945,"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":172.29999923706055,"connectEnd":172.29999923706055,"connectStart":172.29999923706055,"domainLookupEnd":172.29999923706055,"domainLookupStart":172.29999923706055,"fetchStart":172.29999923706055,"redirectEnd":0,"redirectStart":0,"requestStart":172.29999923706055,"responseEnd":332.5,"responseStart":332.5,"secureConnectionStart":172.29999923706055},{"duration":214.69999980926514,"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":172.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":172.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":387.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":165.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":172.69999980926514,"connectEnd":172.69999980926514,"connectStart":172.69999980926514,"domainLookupEnd":172.69999980926514,"domainLookupStart":172.69999980926514,"fetchStart":172.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":172.69999980926514,"responseEnd":338.5,"responseStart":338.5,"secureConnectionStart":172.69999980926514},{"duration":214.5,"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":172.79999923706055,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":172.79999923706055,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":387.29999923706055,"responseStart":0,"secureConnectionStart":0},{"duration":166,"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":173,"connectEnd":173,"connectStart":173,"domainLookupEnd":173,"domainLookupStart":173,"fetchStart":173,"redirectEnd":0,"redirectStart":0,"requestStart":173,"responseEnd":339,"responseStart":339,"secureConnectionStart":173},{"duration":269.80000019073486,"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":178.5999994277954,"connectEnd":178.5999994277954,"connectStart":178.5999994277954,"domainLookupEnd":178.5999994277954,"domainLookupStart":178.5999994277954,"fetchStart":178.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":178.5999994277954,"responseEnd":448.3999996185303,"responseStart":448.3999996185303,"secureConnectionStart":178.5999994277954},{"duration":315,"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":178.5999994277954,"connectEnd":178.5999994277954,"connectStart":178.5999994277954,"domainLookupEnd":178.5999994277954,"domainLookupStart":178.5999994277954,"fetchStart":178.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":178.5999994277954,"responseEnd":493.5999994277954,"responseStart":493.5999994277954,"secureConnectionStart":178.5999994277954},{"duration":49.40000057220459,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":399.29999923706055,"connectEnd":399.29999923706055,"connectStart":399.29999923706055,"domainLookupEnd":399.29999923706055,"domainLookupStart":399.29999923706055,"fetchStart":399.29999923706055,"redirectEnd":0,"redirectStart":0,"requestStart":399.29999923706055,"responseEnd":448.69999980926514,"responseStart":448.69999980926514,"secureConnectionStart":399.29999923706055},{"duration":303.1000003814697,"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","startTime":471.29999923706055,"connectEnd":471.29999923706055,"connectStart":471.29999923706055,"domainLookupEnd":471.29999923706055,"domainLookupStart":471.29999923706055,"fetchStart":471.29999923706055,"redirectEnd":0,"redirectStart":0,"requestStart":471.29999923706055,"responseEnd":774.3999996185303,"responseStart":774.3999996185303,"secureConnectionStart":471.29999923706055},{"duration":136.69999980926514,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":747.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":747.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":884.3999996185303,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":4,"responseStart":166,"responseEnd":173,"domLoading":169,"domInteractive":909,"domContentLoadedEventStart":910,"domContentLoadedEventEnd":960,"domComplete":1263,"loadEventStart":1263,"loadEventEnd":1264,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":886.0999994277954},{"name":"bigPipe.sidebar-id.end","time":886.8999996185303},{"name":"bigPipe.activity-panel-pipe-id.start","time":887.0999994277954},{"name":"bigPipe.activity-panel-pipe-id.end","time":889.6999998092651},{"name":"activityTabFullyLoaded","time":968}],"measures":[],"correlationId":"c727ca2dc4ff42","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":97,"dbReadsTimeInMs":10,"dbConnsTimeInMs":16,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}