MIN/MAX Optimization (Select tables optimized away) does not work for DateTime.
This is similar to bug #3855:
https://mariadb.atlassian.net/browse/MDEV-3855
However, that bug is specifically about inet_aton.
This one is regarding datetime values, and they are not optimized away, thus the query can take much longer than expected.
MariaDB:
mysql> EXPLAIN SELECT MIN(b) FROM t1 WHERE b <= '2013-11-06 23:59:59';
|
+------+-------------+-------+-------+---------------+-------+---------+------+------+--------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+-------+---------------+-------+---------+------+------+--------------------------+
|
| 1 | SIMPLE | t1 | range | idx_b | idx_b | 9 | NULL | 11 | Using where; Using index |
|
+------+-------------+-------+-------+---------------+-------+---------+------+------+--------------------------+
|
MySQL:
mysql> EXPLAIN SELECT MIN(b) FROM t1 WHERE b <= '2013-11-06 23:59:59';
|
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Select tables optimized away |
|
+----+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|
The following illustrates this:
CREATE TABLE `t1` (
|
`a` int(11) NOT NULL AUTO_INCREMENT,
|
`b` datetime DEFAULT NULL,
|
PRIMARY KEY (`a`),
|
KEY `idx_b` (`b`)
|
) ENGINE=InnoDB;
|
|
INSERT INTO `t1` (b) VALUES ('2013-01-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-02-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-03-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-04-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-05-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-06-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-07-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-08-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-09-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-10-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-11-06 23:59:59');
|
INSERT INTO `t1` (b) VALUES ('2013-12-06 23:59:59');
|
|
EXPLAIN SELECT MIN(b) FROM t1 WHERE b <= '2013-11-06 23:59:59';
|
{"report":{"fcp":961.5,"ttfb":278.80000019073486,"pageVisibility":"visible","entityId":26330,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"43ac4825-9dce-4ca4-8b75-e6875f483b23","navigationType":0,"readyForUser":1046.5,"redirectCount":0,"resourceLoadedEnd":1346.6000003814697,"resourceLoadedStart":290.19999980926514,"resourceTiming":[{"duration":175.4000005722046,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":290.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":290.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":465.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":175.39999961853027,"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":290.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":290.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":466,"responseStart":0,"secureConnectionStart":0},{"duration":184,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":290.8999996185303,"connectEnd":290.8999996185303,"connectStart":290.8999996185303,"domainLookupEnd":290.8999996185303,"domainLookupStart":290.8999996185303,"fetchStart":290.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":290.8999996185303,"responseEnd":474.8999996185303,"responseStart":474.8999996185303,"secureConnectionStart":290.8999996185303},{"duration":303.9000005722046,"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":291.3999996185303,"connectEnd":291.3999996185303,"connectStart":291.3999996185303,"domainLookupEnd":291.3999996185303,"domainLookupStart":291.3999996185303,"fetchStart":291.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":291.3999996185303,"responseEnd":595.3000001907349,"responseStart":595.3000001907349,"secureConnectionStart":291.3999996185303},{"duration":307.5,"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":291.69999980926514,"connectEnd":291.69999980926514,"connectStart":291.69999980926514,"domainLookupEnd":291.69999980926514,"domainLookupStart":291.69999980926514,"fetchStart":291.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":291.69999980926514,"responseEnd":599.1999998092651,"responseStart":599.1999998092651,"secureConnectionStart":291.69999980926514},{"duration":307.9000005722046,"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":291.8999996185303,"connectEnd":291.8999996185303,"connectStart":291.8999996185303,"domainLookupEnd":291.8999996185303,"domainLookupStart":291.8999996185303,"fetchStart":291.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":291.8999996185303,"responseEnd":599.8000001907349,"responseStart":599.8000001907349,"secureConnectionStart":291.8999996185303},{"duration":308.0999994277954,"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":292.1000003814697,"connectEnd":292.1000003814697,"connectStart":292.1000003814697,"domainLookupEnd":292.1000003814697,"domainLookupStart":292.1000003814697,"fetchStart":292.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":292.1000003814697,"responseEnd":600.1999998092651,"responseStart":600.1999998092651,"secureConnectionStart":292.1000003814697},{"duration":330.8999996185303,"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":292.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":292.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":623.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":308.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":292.3999996185303,"connectEnd":292.3999996185303,"connectStart":292.3999996185303,"domainLookupEnd":292.3999996185303,"domainLookupStart":292.3999996185303,"fetchStart":292.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":292.3999996185303,"responseEnd":600.6999998092651,"responseStart":600.6999998092651,"secureConnectionStart":292.3999996185303},{"duration":330.80000019073486,"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":292.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":292.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":623.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":308.80000019073486,"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":292.69999980926514,"connectEnd":292.69999980926514,"connectStart":292.69999980926514,"domainLookupEnd":292.69999980926514,"domainLookupStart":292.69999980926514,"fetchStart":292.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":292.69999980926514,"responseEnd":601.5,"responseStart":601.5,"secureConnectionStart":292.69999980926514},{"duration":405.69999980926514,"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":303.30000019073486,"connectEnd":303.30000019073486,"connectStart":303.30000019073486,"domainLookupEnd":303.30000019073486,"domainLookupStart":303.30000019073486,"fetchStart":303.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":303.30000019073486,"responseEnd":709,"responseStart":709,"secureConnectionStart":303.30000019073486},{"duration":1040.6000003814697,"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":306,"connectEnd":306,"connectStart":306,"domainLookupEnd":306,"domainLookupStart":306,"fetchStart":306,"redirectEnd":0,"redirectStart":0,"requestStart":306,"responseEnd":1346.6000003814697,"responseStart":1346.6000003814697,"secureConnectionStart":306},{"duration":74.09999942779541,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":635.3000001907349,"connectEnd":635.3000001907349,"connectStart":635.3000001907349,"domainLookupEnd":635.3000001907349,"domainLookupStart":635.3000001907349,"fetchStart":635.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":635.3000001907349,"responseEnd":709.3999996185303,"responseStart":709.3999996185303,"secureConnectionStart":635.3000001907349},{"duration":495.1000003814697,"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","startTime":912,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":912,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1407.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":484.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":913,"connectEnd":913,"connectStart":913,"domainLookupEnd":913,"domainLookupStart":913,"fetchStart":913,"redirectEnd":0,"redirectStart":0,"requestStart":913,"responseEnd":1397.1000003814697,"responseStart":1397.1000003814697,"secureConnectionStart":913},{"duration":490.0999994277954,"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","startTime":913.3000001907349,"connectEnd":913.3000001907349,"connectStart":913.3000001907349,"domainLookupEnd":913.3000001907349,"domainLookupStart":913.3000001907349,"fetchStart":913.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":913.3000001907349,"responseEnd":1403.3999996185303,"responseStart":1403.3999996185303,"secureConnectionStart":913.3000001907349}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":94,"responseStart":279,"responseEnd":306,"domLoading":283,"domInteractive":1365,"domContentLoadedEventStart":1365,"domContentLoadedEventEnd":1407,"domComplete":2845,"loadEventStart":2845,"loadEventEnd":2847,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1348.6000003814697},{"name":"bigPipe.sidebar-id.end","time":1349.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1349.6000003814697},{"name":"bigPipe.activity-panel-pipe-id.end","time":1352.1000003814697},{"name":"activityTabFullyLoaded","time":1414.6000003814697}],"measures":[],"correlationId":"93c32a4b3586a6","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":88,"dbReadsTimeInMs":8,"dbConnsTimeInMs":15,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}