Problem 1:
I create a table and populate it with data like this:
DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (id INT NOT NULL, a VARCHAR(20)) 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');
|
Notice, the values with ' 2001-01-04' in the column 'a' have leading spaces
('*space*2001-01-04'), while the other values have no spaces.
Now I run this query:
SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=DATE'2001-01-04' GROUP BY id;
|
returns the following result:
+----+-------------+-------------+
|
| id | MIN(a) | MAX(a) |
|
+----+-------------+-------------+
|
| 1 | 2001-01-04 | 2001-01-04 |
|
| 2 | 2001-01-04 | 2001-01-04 |
|
| 3 | 2001-01-04 | 2001-01-04 |
|
| 4 | 2001-01-04 | 2001-01-04 |
|
+----+-------------+-------------+
|
Looks fine so far. Notice, the column is VARCHAR and comparison is done as DATE.
Now if I add an index and re-run the query:
ALTER TABLE t1 ADD KEY(id,a);
|
SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>=DATE'2001-01-04' GROUP BY id;
|
it returns empty set. Looks wrong. The result set should not change when a new index is added.
Tracing the code reveals that GROUP_MIN_MAX optimization is applied after adding the index. This is wrong, because comparison is done according to DATE in this example. The index on a VARCHAR column should not be used to optimize DATE operations.
Problem 2:
I create a table with a ENUM column with values ordered in counter-alphabetic order:
DROP TABLE IF EXISTS t1;
|
CREATE TABLE t1 (id INT NOT NULL, a ENUM('04','03','02','01')) ENGINE=MyISAM;
|
INSERT INTO t1 VALUES (1,'01');
|
INSERT INTO t1 VALUES (1,'02');
|
INSERT INTO t1 VALUES (1,'03');
|
INSERT INTO t1 VALUES (1,'04');
|
INSERT INTO t1 VALUES (2,'01');
|
INSERT INTO t1 VALUES (2,'02');
|
INSERT INTO t1 VALUES (2,'03');
|
INSERT INTO t1 VALUES (2,'04');
|
INSERT INTO t1 VALUES (3,'01');
|
INSERT INTO t1 VALUES (3,'02');
|
INSERT INTO t1 VALUES (3,'03');
|
INSERT INTO t1 VALUES (3,'04');
|
INSERT INTO t1 VALUES (4,'01');
|
INSERT INTO t1 VALUES (4,'02');
|
INSERT INTO t1 VALUES (4,'03');
|
INSERT INTO t1 VALUES (4,'04');
|
SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='02' GROUP BY id;
|
The query returns:
+----+--------+--------+
|
| id | MIN(a) | MAX(a) |
|
+----+--------+--------+
|
| 1 | 02 | 04 |
|
| 2 | 02 | 04 |
|
| 3 | 02 | 04 |
|
| 4 | 02 | 04 |
|
+----+--------+--------+
|
Looks good so far.
Now I add a key and rerun the query:
ALTER TABLE t1 ADD KEY(id,a);
|
SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='02' GROUP BY id;
|
It returns empty set. This is wrong.
Explain tells that only 9 out of 16 rows are examined, and tracing reveals that GROUP_MIN_MAX optimization is erroneously enabled to optimize this.
mysql> EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a>='03' GROUP BY id;
|
+------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
|
| 1 | SIMPLE | t1 | range | NULL | id | 6 | NULL | 9 | Using where; Using index for group-by |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
|
1 row in set (0.00 sec)
|
- blocks
-
MDEV-6983
BIGINT 99991231000000 to TIME'00:00:00' comparison is not consistent
-
-
Open
There are no comments yet on this issue.
{"report":{"fcp":819.2999999523163,"ttfb":230.29999995231628,"pageVisibility":"visible","entityId":48003,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"08ebd45f-64fe-492b-a296-9286d8575780","navigationType":0,"readyForUser":904.2999999523163,"redirectCount":0,"resourceLoadedEnd":540,"resourceLoadedStart":238.09999990463257,"resourceTiming":[{"duration":11.800000071525574,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":238.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":238.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":249.89999997615814,"responseStart":0,"secureConnectionStart":0},{"duration":12,"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":238.39999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":238.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":250.39999997615814,"responseStart":0,"secureConnectionStart":0},{"duration":190.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":238.5,"connectEnd":238.5,"connectStart":238.5,"domainLookupEnd":238.5,"domainLookupStart":238.5,"fetchStart":238.5,"redirectEnd":0,"redirectStart":0,"requestStart":253,"responseEnd":429,"responseStart":281.89999997615814,"secureConnectionStart":238.5},{"duration":49.800000071525574,"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":238.69999992847443,"connectEnd":238.69999992847443,"connectStart":238.69999992847443,"domainLookupEnd":238.69999992847443,"domainLookupStart":238.69999992847443,"fetchStart":238.69999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":255.39999997615814,"responseEnd":288.5,"responseStart":286.5,"secureConnectionStart":238.69999992847443},{"duration":301.3000000715256,"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":238.69999992847443,"connectEnd":238.69999992847443,"connectStart":238.69999992847443,"domainLookupEnd":238.69999992847443,"domainLookupStart":238.69999992847443,"fetchStart":238.69999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":253.79999995231628,"responseEnd":540,"responseStart":282.39999997615814,"secureConnectionStart":238.69999992847443},{"duration":52.39999997615814,"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":238.79999995231628,"connectEnd":238.79999995231628,"connectStart":238.79999995231628,"domainLookupEnd":238.79999995231628,"domainLookupStart":238.79999995231628,"fetchStart":238.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":258.1999999284744,"responseEnd":291.1999999284744,"responseStart":287.2999999523163,"secureConnectionStart":238.79999995231628},{"duration":52.60000002384186,"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":238.89999997615814,"connectEnd":238.89999997615814,"connectStart":238.89999997615814,"domainLookupEnd":238.89999997615814,"domainLookupStart":238.89999997615814,"fetchStart":238.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":258.39999997615814,"responseEnd":291.5,"responseStart":289.59999990463257,"secureConnectionStart":238.89999997615814},{"duration":16.59999990463257,"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":239,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":239,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":255.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":56.200000047683716,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":239.09999990463257,"connectEnd":239.09999990463257,"connectStart":239.09999990463257,"domainLookupEnd":239.09999990463257,"domainLookupStart":239.09999990463257,"fetchStart":239.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":261.2999999523163,"responseEnd":295.2999999523163,"responseStart":292.6999999284744,"secureConnectionStart":239.09999990463257},{"duration":18.600000023841858,"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":239.19999992847443,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":239.19999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":257.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":55.299999952316284,"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":239.29999995231628,"connectEnd":239.29999995231628,"connectStart":239.29999995231628,"domainLookupEnd":239.29999995231628,"domainLookupStart":239.29999995231628,"fetchStart":239.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":262.5,"responseEnd":294.59999990463257,"responseStart":291.6999999284744,"secureConnectionStart":239.29999995231628},{"duration":264.8000000715256,"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":240.19999992847443,"connectEnd":240.19999992847443,"connectStart":240.19999992847443,"domainLookupEnd":240.19999992847443,"domainLookupStart":240.19999992847443,"fetchStart":240.19999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":272.1999999284744,"responseEnd":505,"responseStart":499.6999999284744,"secureConnectionStart":240.19999992847443},{"duration":263.39999997615814,"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":242.19999992847443,"connectEnd":242.19999992847443,"connectStart":242.19999992847443,"domainLookupEnd":242.19999992847443,"domainLookupStart":242.19999992847443,"fetchStart":242.19999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":275.59999990463257,"responseEnd":505.59999990463257,"responseStart":501.59999990463257,"secureConnectionStart":242.19999992847443},{"duration":105.19999992847443,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":575.5,"connectEnd":575.5,"connectStart":575.5,"domainLookupEnd":575.5,"domainLookupStart":575.5,"fetchStart":575.5,"redirectEnd":0,"redirectStart":0,"requestStart":647.0999999046326,"responseEnd":680.6999999284744,"responseStart":679.5,"secureConnectionStart":575.5},{"duration":83.69999992847443,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":812.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":812.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":896.1999999284744,"responseStart":0,"secureConnectionStart":0},{"duration":114.60000002384186,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":818.8999999761581,"connectEnd":818.8999999761581,"connectStart":818.8999999761581,"domainLookupEnd":818.8999999761581,"domainLookupStart":818.8999999761581,"fetchStart":818.8999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":902,"responseEnd":933.5,"responseStart":932.7999999523163,"secureConnectionStart":818.8999999761581}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":36,"responseStart":231,"responseEnd":244,"domLoading":234,"domInteractive":1006,"domContentLoadedEventStart":1006,"domContentLoadedEventEnd":1050,"domComplete":1233,"loadEventStart":1233,"loadEventEnd":1234,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":988.5},{"name":"bigPipe.sidebar-id.end","time":989.2999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":989.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":989.8999999761581},{"name":"activityTabFullyLoaded","time":1062.0999999046326}],"measures":[],"correlationId":"7f369a33f01998","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":95,"dbReadsTimeInMs":13,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}