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
Sergei Petrunia
made changes -
2013-11-12 12:27
Field
Original Value
New Value
Priority
Major
[ 3
]
Minor
[ 4
]
Sergei Petrunia
made changes -
2013-11-12 12:43
Description
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):
{noformat}
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;
{noformat}
{noformat}
MariaDB [j3]> select max(a) from t2 where a < 432;
+--------+
| max(a) |
+--------+
| -99999 |
+--------+
1 row in set (0.00 sec)
{noformat}
{noformat}
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)
{noformat}
EXPLAINs:
{noformat}
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)
{noformat}
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):
{noformat}
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;
{noformat}
{noformat}
MariaDB [j3]> select max(a) from t2 where a < 432;
+--------+
| max(a) |
+--------+
| -99999 |
+--------+
1 row in set (0.00 sec)
{noformat}
{noformat}
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)
{noformat}
EXPLAINs:
{noformat}
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)
{noformat}
Filed in the upstream as http://bugs.mysql.com/bug.php?id=70886
Sergei Golubchik
made changes -
2014-06-13 15:06
Workflow
defaullt
[ 29711
]
MariaDB v2
[ 44594
]
Elena Stepanova
made changes -
2015-04-03 17:35
Remote Link
This issue links to "Bug #70886 - MIN/MAX optimizer doesn't take into account type conversions (Web Link)"
[ 22902
]
Elena Stepanova
made changes -
2015-04-03 17:36
Component/s
Optimizer
[ 10200
]
Fix Version/s
10.0
[ 16000
]
Affects Version/s
10.0
[ 16000
]
Affects Version/s
5.5
[ 15800
]
Affects Version/s
5.5.33a
[ 13500
]
Elena Stepanova
made changes -
2015-04-03 17:38
Labels
upstream
upstream verified
Elena Stepanova
made changes -
2015-04-03 17:56
Fix Version/s
10.1
[ 16100
]
Fix Version/s
10.0
[ 16000
]
Sergei Golubchik
made changes -
2021-12-06 21:32
Workflow
MariaDB v3
[ 61260
]
MariaDB v4
[ 139559
]
{"report":{"fcp":924.7999999523163,"ttfb":320.60000002384186,"pageVisibility":"visible","entityId":26411,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"fc5435a5-8aa8-4b36-a2ff-aca2a8de26fb","navigationType":0,"readyForUser":1027.7000000476837,"redirectCount":0,"resourceLoadedEnd":997.8999999761581,"resourceLoadedStart":326.2999999523163,"resourceTiming":[{"duration":123,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":326.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":326.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":449.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":123.10000002384186,"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":326.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":326.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":449.60000002384186,"responseStart":0,"secureConnectionStart":0},{"duration":146.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":326.7000000476837,"connectEnd":326.7000000476837,"connectStart":326.7000000476837,"domainLookupEnd":326.7000000476837,"domainLookupStart":326.7000000476837,"fetchStart":326.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":326.7000000476837,"responseEnd":473.2999999523163,"responseStart":473.2000000476837,"secureConnectionStart":326.7000000476837},{"duration":221.89999997615814,"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":326.89999997615814,"connectEnd":326.89999997615814,"connectStart":326.89999997615814,"domainLookupEnd":326.89999997615814,"domainLookupStart":326.89999997615814,"fetchStart":326.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":326.89999997615814,"responseEnd":548.7999999523163,"responseStart":548.7999999523163,"secureConnectionStart":326.89999997615814},{"duration":225.19999992847443,"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":327.10000002384186,"connectEnd":327.10000002384186,"connectStart":327.10000002384186,"domainLookupEnd":327.10000002384186,"domainLookupStart":327.10000002384186,"fetchStart":327.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":327.10000002384186,"responseEnd":552.2999999523163,"responseStart":552.2999999523163,"secureConnectionStart":327.10000002384186},{"duration":225.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":327.2999999523163,"connectEnd":327.2999999523163,"connectStart":327.2999999523163,"domainLookupEnd":327.2999999523163,"domainLookupStart":327.2999999523163,"fetchStart":327.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":327.2999999523163,"responseEnd":552.7000000476837,"responseStart":552.6000000238419,"secureConnectionStart":327.2999999523163},{"duration":225.70000004768372,"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":327.5,"connectEnd":327.5,"connectStart":327.5,"domainLookupEnd":327.5,"domainLookupStart":327.5,"fetchStart":327.5,"redirectEnd":0,"redirectStart":0,"requestStart":327.5,"responseEnd":553.2000000476837,"responseStart":553.2000000476837,"secureConnectionStart":327.5},{"duration":286,"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":327.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":327.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":613.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":226.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":327.89999997615814,"connectEnd":327.89999997615814,"connectStart":327.89999997615814,"domainLookupEnd":327.89999997615814,"domainLookupStart":327.89999997615814,"fetchStart":327.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":327.89999997615814,"responseEnd":554,"responseStart":554,"secureConnectionStart":327.89999997615814},{"duration":285.7999999523163,"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":328,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":328,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":613.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":226.5,"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":328.2000000476837,"connectEnd":328.2000000476837,"connectStart":328.2000000476837,"domainLookupEnd":328.2000000476837,"domainLookupStart":328.2000000476837,"fetchStart":328.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":328.2000000476837,"responseEnd":554.7000000476837,"responseStart":554.7000000476837,"secureConnectionStart":328.2000000476837},{"duration":662.7000000476837,"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":334.2999999523163,"connectEnd":334.2999999523163,"connectStart":334.2999999523163,"domainLookupEnd":334.2999999523163,"domainLookupStart":334.2999999523163,"fetchStart":334.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":334.2999999523163,"responseEnd":997,"responseStart":997,"secureConnectionStart":334.2999999523163},{"duration":659.6999999284744,"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":338.2000000476837,"connectEnd":338.2000000476837,"connectStart":338.2000000476837,"domainLookupEnd":338.2000000476837,"domainLookupStart":338.2000000476837,"fetchStart":338.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":338.2000000476837,"responseEnd":997.8999999761581,"responseStart":997.8999999761581,"secureConnectionStart":338.2000000476837},{"duration":255.19999992847443,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":625.2000000476837,"connectEnd":625.2000000476837,"connectStart":625.2000000476837,"domainLookupEnd":625.2000000476837,"domainLookupStart":625.2000000476837,"fetchStart":625.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":625.2000000476837,"responseEnd":880.3999999761581,"responseStart":880.3999999761581,"secureConnectionStart":625.2000000476837},{"duration":219.39999997615814,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":917.8999999761581,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":917.8999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1137.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":267.7999999523163,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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":935.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":935.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1203.5,"responseStart":0,"secureConnectionStart":0},{"duration":267.1999999284744,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/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":936.6000000238419,"connectEnd":936.6000000238419,"connectStart":936.6000000238419,"domainLookupEnd":936.6000000238419,"domainLookupStart":936.6000000238419,"fetchStart":936.6000000238419,"redirectEnd":0,"redirectStart":0,"requestStart":936.6000000238419,"responseEnd":1203.7999999523163,"responseStart":1203.7999999523163,"secureConnectionStart":936.6000000238419},{"duration":273.2999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/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":937.1000000238419,"connectEnd":937.1000000238419,"connectStart":937.1000000238419,"domainLookupEnd":937.1000000238419,"domainLookupStart":937.1000000238419,"fetchStart":937.1000000238419,"redirectEnd":0,"redirectStart":0,"requestStart":937.1000000238419,"responseEnd":1210.3999999761581,"responseStart":1210.3999999761581,"secureConnectionStart":937.1000000238419}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":92,"responseStart":320,"responseEnd":338,"domLoading":324,"domInteractive":1149,"domContentLoadedEventStart":1149,"domContentLoadedEventEnd":1199,"domComplete":1519,"loadEventStart":1519,"loadEventEnd":1519,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1115.1000000238419},{"name":"bigPipe.sidebar-id.end","time":1115.8999999761581},{"name":"bigPipe.activity-panel-pipe-id.start","time":1116.2000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1119.7000000476837},{"name":"activityTabFullyLoaded","time":1217.2999999523163}],"measures":[],"correlationId":"bef0a214070c1e","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":163,"dbReadsTimeInMs":21,"dbConnsTimeInMs":30,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Setting priority to MINOR as this problem exists for a long time and didn't affect anybody.