DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (id INT NOT NULL, a DATE, KEY(id,a)) ENGINE=MyISAM;
|
INSERT INTO t1 VALUES (1,'2001-01-01');
|
INSERT INTO t1 VALUES (1,'2001-01-02');
|
INSERT INTO t1 VALUES (1,'2001-01-03');
|
INSERT INTO t1 VALUES (1,'2001-01-04');
|
INSERT INTO t1 VALUES (2,'2001-01-01');
|
INSERT INTO t1 VALUES (2,'2001-01-02');
|
INSERT INTO t1 VALUES (2,'2001-01-03');
|
INSERT INTO t1 VALUES (2,'2001-01-04');
|
INSERT INTO t1 VALUES (3,'2001-01-01');
|
INSERT INTO t1 VALUES (3,'2001-01-02');
|
INSERT INTO t1 VALUES (3,'2001-01-03');
|
INSERT INTO t1 VALUES (3,'2001-01-04');
|
INSERT INTO t1 VALUES (4,'2001-01-01');
|
INSERT INTO t1 VALUES (4,'2001-01-02');
|
INSERT INTO t1 VALUES (4,'2001-01-03');
|
INSERT INTO t1 VALUES (4,'2001-01-04');
|
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='2001-01-04' GROUP BY id;
|
returns:
+------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
|
| 1 | SIMPLE | t1 | range | NULL | id | 8 | NULL | 9 | Using where; Using index for group-by |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
|
It's going to scan 9 out of 16 rows, which means group_min_max optimization is enabled.
Now if I change the constant from '2001-01-05' to 20010104 and rerun EXPLAIN:
EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=20010104 GROUP BY id;
|
it returns:
+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
|
| 1 | SIMPLE | t1 | index | NULL | id | 8 | NULL | 16 | Using where; Using index |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
|
It will scan all 16 rows, that means group_min_max optimization is not applied.
It safely could. Comparison in both cases is done by DATE anyway.
The same is true for DECIMAL and DOUBLE literals.
There are no comments yet on this issue.
{"report":{"fcp":769.5,"ttfb":177.29999995231628,"pageVisibility":"visible","entityId":48002,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"8e046366-b6c0-45fd-a1d3-c8a824239cc2","navigationType":0,"readyForUser":839.9000000953674,"redirectCount":0,"resourceLoadedEnd":473.2000000476837,"resourceLoadedStart":182.09999990463257,"resourceTiming":[{"duration":20.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":182.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":202.5,"responseStart":0,"secureConnectionStart":0},{"duration":20.199999809265137,"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":182.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":182.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":202.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":171.70000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":182.5,"connectEnd":204.29999995231628,"connectStart":204.29999995231628,"domainLookupEnd":204.29999995231628,"domainLookupStart":204.29999995231628,"fetchStart":182.5,"redirectEnd":0,"redirectStart":0,"requestStart":204.5,"responseEnd":354.2000000476837,"responseStart":217.40000009536743,"secureConnectionStart":204.29999995231628},{"duration":278.2000000476837,"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":182.59999990463257,"connectEnd":182.59999990463257,"connectStart":182.59999990463257,"domainLookupEnd":182.59999990463257,"domainLookupStart":182.59999990463257,"fetchStart":182.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":205.5,"responseEnd":460.7999999523163,"responseStart":222,"secureConnectionStart":182.59999990463257},{"duration":37.799999952316284,"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":182.79999995231628,"connectEnd":182.79999995231628,"connectStart":182.79999995231628,"domainLookupEnd":182.79999995231628,"domainLookupStart":182.79999995231628,"fetchStart":182.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":206.79999995231628,"responseEnd":220.59999990463257,"responseStart":218.90000009536743,"secureConnectionStart":182.79999995231628},{"duration":46.40000009536743,"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":187.09999990463257,"connectEnd":187.09999990463257,"connectStart":187.09999990463257,"domainLookupEnd":187.09999990463257,"domainLookupStart":187.09999990463257,"fetchStart":187.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":208.20000004768372,"responseEnd":233.5,"responseStart":228.70000004768372,"secureConnectionStart":187.09999990463257},{"duration":48.200000047683716,"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":187.20000004768372,"connectEnd":187.20000004768372,"connectStart":187.20000004768372,"domainLookupEnd":187.20000004768372,"domainLookupStart":187.20000004768372,"fetchStart":187.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":209.29999995231628,"responseEnd":235.40000009536743,"responseStart":232.40000009536743,"secureConnectionStart":187.20000004768372},{"duration":20.799999952316284,"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":187.29999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":187.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":208.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":51.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":187.40000009536743,"connectEnd":187.40000009536743,"connectStart":187.40000009536743,"domainLookupEnd":187.40000009536743,"domainLookupStart":187.40000009536743,"fetchStart":187.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":211.90000009536743,"responseEnd":238.5,"responseStart":234.29999995231628,"secureConnectionStart":187.40000009536743},{"duration":24,"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":187.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":187.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":211.5,"responseStart":0,"secureConnectionStart":0},{"duration":51.200000047683716,"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":187.59999990463257,"connectEnd":187.59999990463257,"connectStart":187.59999990463257,"domainLookupEnd":187.59999990463257,"domainLookupStart":187.59999990463257,"fetchStart":187.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":214.20000004768372,"responseEnd":238.79999995231628,"responseStart":235.59999990463257,"secureConnectionStart":187.59999990463257},{"duration":282.2000000476837,"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":190.09999990463257,"connectEnd":190.09999990463257,"connectStart":190.09999990463257,"domainLookupEnd":190.09999990463257,"domainLookupStart":190.09999990463257,"fetchStart":190.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":271.5,"responseEnd":472.2999999523163,"responseStart":466.7999999523163,"secureConnectionStart":190.09999990463257},{"duration":283.10000014305115,"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":190.09999990463257,"connectEnd":190.09999990463257,"connectStart":190.09999990463257,"domainLookupEnd":190.09999990463257,"domainLookupStart":190.09999990463257,"fetchStart":190.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":332.09999990463257,"responseEnd":473.2000000476837,"responseStart":467.7999999523163,"secureConnectionStart":190.09999990463257},{"duration":127.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":484.40000009536743,"connectEnd":484.40000009536743,"connectStart":484.40000009536743,"domainLookupEnd":484.40000009536743,"domainLookupStart":484.40000009536743,"fetchStart":484.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":583,"responseEnd":612.0999999046326,"responseStart":611.2999999523163,"secureConnectionStart":484.40000009536743},{"duration":224.70000004768372,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":694.0999999046326,"connectEnd":694.0999999046326,"connectStart":694.0999999046326,"domainLookupEnd":694.0999999046326,"domainLookupStart":694.0999999046326,"fetchStart":694.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":887.5999999046326,"responseEnd":918.7999999523163,"responseStart":917.5999999046326,"secureConnectionStart":694.0999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":29,"responseStart":177,"responseEnd":189,"domLoading":181,"domInteractive":888,"domContentLoadedEventStart":888,"domContentLoadedEventEnd":927,"domComplete":1557,"loadEventStart":1557,"loadEventEnd":1557,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":872.5999999046326},{"name":"bigPipe.sidebar-id.end","time":873.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":873.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":873.9000000953674},{"name":"activityTabFullyLoaded","time":936.4000000953674}],"measures":[],"correlationId":"1d0210e442a22a","effectiveType":"4g","downlink":9.8,"rtt":0,"serverDuration":74,"dbReadsTimeInMs":11,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}