MIN/MAX optimizer doesn't take into account type conversions. This may cause query results to be different depending on whether there is an index.
Testcase (not minimal, it may be possible to simplify further):
create table t2 ( a char(10) not null, key(a)) engine=innodb;
|
|
insert into t2 values ('foo-123');
|
insert into t2 values ('bar-123');
|
insert into t2 values ('baz-123');
|
insert into t2 values ('abc-123');
|
insert into t2 values ('-1234');
|
insert into t2 values ('-99');
|
insert into t2 values ('-99999');
|
|
select max(a) from t2 where a < 432;
|
select max(a) from t2 ignore index(a) where a < 432;
|
MariaDB [j3]> select max(a) from t2 where a < 432;
|
+--------+
|
| max(a) |
|
+--------+
|
| -99999 |
|
+--------+
|
1 row in set (0.00 sec)
|
MariaDB [j3]> select max(a) from t2 ignore index(a) where a < 432;
|
+---------+
|
| max(a) |
|
+---------+
|
| foo-123 |
|
+---------+
|
1 row in set, 4 warnings (0.01 sec)
|
EXPLAINs:
MariaDB [j3]> explain select max(a) from t2 where a < 432;
|
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|
| 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 |
|
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
|
1 row in set (0.00 sec)
|
|
MariaDB [j3]> explain select max(a) from t2 ignore index(a) where a < 432;
|
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
|
| 1 | SIMPLE | t2 | ALL | NULL | NULL | NULL | NULL | 7 | Using where |
|
+------+-------------+-------+------+---------------+------+---------+------+------+-------------+
|
1 row in set (0.01 sec)
|
Filed in the upstream as http://bugs.mysql.com/bug.php?id=70886
{"report":{"fcp":864.2000000476837,"ttfb":327.10000002384186,"pageVisibility":"visible","entityId":26411,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"0184fb45-12f8-46d4-b5a5-370461ca3b1a","navigationType":0,"readyForUser":930.3999999761581,"redirectCount":0,"resourceLoadedEnd":733,"resourceLoadedStart":332.7000000476837,"resourceTiming":[{"duration":37.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":332.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":332.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":369.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":38.39999997615814,"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":333,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":333,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":371.39999997615814,"responseStart":0,"secureConnectionStart":0},{"duration":83.19999992847443,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":333.2000000476837,"connectEnd":333.2000000476837,"connectStart":333.2000000476837,"domainLookupEnd":333.2000000476837,"domainLookupStart":333.2000000476837,"fetchStart":333.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":373.2999999523163,"responseEnd":416.39999997615814,"responseStart":387.2000000476837,"secureConnectionStart":333.2000000476837},{"duration":57.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":333.39999997615814,"connectEnd":333.39999997615814,"connectStart":333.39999997615814,"domainLookupEnd":333.39999997615814,"domainLookupStart":333.39999997615814,"fetchStart":333.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":376.7000000476837,"responseEnd":391.2000000476837,"responseStart":390.2000000476837,"secureConnectionStart":333.39999997615814},{"duration":114.20000004768372,"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":333.39999997615814,"connectEnd":333.39999997615814,"connectStart":333.39999997615814,"domainLookupEnd":333.39999997615814,"domainLookupStart":333.39999997615814,"fetchStart":333.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":376,"responseEnd":447.60000002384186,"responseStart":395.89999997615814,"secureConnectionStart":333.39999997615814},{"duration":64.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":333.60000002384186,"connectEnd":333.60000002384186,"connectStart":333.60000002384186,"domainLookupEnd":333.60000002384186,"domainLookupStart":333.60000002384186,"fetchStart":333.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":377.39999997615814,"responseEnd":398,"responseStart":397.10000002384186,"secureConnectionStart":333.60000002384186},{"duration":65,"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":333.7999999523163,"connectEnd":333.7999999523163,"connectStart":333.7999999523163,"domainLookupEnd":333.7999999523163,"domainLookupStart":333.7999999523163,"fetchStart":333.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":377.60000002384186,"responseEnd":398.7999999523163,"responseStart":398.10000002384186,"secureConnectionStart":333.7999999523163},{"duration":41.60000002384186,"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":333.89999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":333.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":375.5,"responseStart":0,"secureConnectionStart":0},{"duration":67.69999992847443,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":334.10000002384186,"connectEnd":334.10000002384186,"connectStart":334.10000002384186,"domainLookupEnd":334.10000002384186,"domainLookupStart":334.10000002384186,"fetchStart":334.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":378.7999999523163,"responseEnd":401.7999999523163,"responseStart":401.10000002384186,"secureConnectionStart":334.10000002384186},{"duration":42.299999952316284,"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":334.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":334.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":376.5,"responseStart":0,"secureConnectionStart":0},{"duration":66.70000004768372,"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":334.39999997615814,"connectEnd":334.39999997615814,"connectStart":334.39999997615814,"domainLookupEnd":334.39999997615814,"domainLookupStart":334.39999997615814,"fetchStart":334.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":379.39999997615814,"responseEnd":401.10000002384186,"responseStart":399,"secureConnectionStart":334.39999997615814},{"duration":374.1999999284744,"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":357.60000002384186,"connectEnd":357.60000002384186,"connectStart":357.60000002384186,"domainLookupEnd":357.60000002384186,"domainLookupStart":357.60000002384186,"fetchStart":357.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":562.3999999761581,"responseEnd":731.7999999523163,"responseStart":723.7999999523163,"secureConnectionStart":357.60000002384186},{"duration":375.2999999523163,"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":357.7000000476837,"connectEnd":357.7000000476837,"connectStart":357.7000000476837,"domainLookupEnd":357.7000000476837,"domainLookupStart":357.7000000476837,"fetchStart":357.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":573.5,"responseEnd":733,"responseStart":727.2000000476837,"secureConnectionStart":357.7000000476837},{"duration":207,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":625.7000000476837,"connectEnd":625.7000000476837,"connectStart":625.7000000476837,"domainLookupEnd":625.7000000476837,"domainLookupStart":625.7000000476837,"fetchStart":625.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":798.3999999761581,"responseEnd":832.7000000476837,"responseStart":831.7999999523163,"secureConnectionStart":625.7000000476837}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":157,"responseStart":327,"responseEnd":357,"domLoading":331,"domInteractive":990,"domContentLoadedEventStart":990,"domContentLoadedEventEnd":1025,"domComplete":1671,"loadEventStart":1671,"loadEventEnd":1671,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":971.1000000238419},{"name":"bigPipe.sidebar-id.end","time":972},{"name":"bigPipe.activity-panel-pipe-id.start","time":972.1000000238419},{"name":"bigPipe.activity-panel-pipe-id.end","time":972.8999999761581},{"name":"activityTabFullyLoaded","time":1038.8999999761581}],"measures":[],"correlationId":"94b941501a1433","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":103,"dbReadsTimeInMs":11,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Setting priority to MINOR as this problem exists for a long time and didn't affect anybody.