SELECT using ORDER BY DESC and LIMIT with suitably selected table
structure, indexes and row content produces unexpected results with
InnoDB/XtraDB engine.
(Note: This may be related to (or even duplicate of?) MDEV-4323, but
with quite different test setups its pretty hard to tell especially
when the set of affected engines seem to differ.)
Reproduced on: Linux ***** 3.2.0-4-amd64 #1 SMP Debian 3.2.51-1 x86_64 GNU/Linux
Errors/warnings on log: none
Reproducible at least on MariaDB versions: 5.5.34, 5.5.33a, 5.5.32,
5.5.30, 5.5.29.
Was NOT able to reproduce (using this test setup at least) on MariaDB
versions: 5.5.28a and 5.5.23.
Was not able to reproduce this using MyISAM engine.
Reproducible on MySQL: unknown (so no bug filed for MySQL yet)
Test case to reproduce and results:
1) Used test case
cat mysql-test/t/select_order_by_desc_limit_problem.test
# Test case for ORDER BY DESC and LIMIT.
|
# Both selects should return same result set in same order.
|
|
--source include/have_innodb.inc
|
|
--disable_warnings
|
drop table if exists t1, t2;
|
--enable_warnings
|
|
create table t1 (a bigint not null unique auto_increment, b varchar(10), primary key (a), key (b(2))) engine = myisam default character set utf8;
|
create table t2 (a bigint not null unique auto_increment, b varchar(10), primary key (a), key (b(2))) engine = innodb default character set utf8;
|
|
insert into t1 (b) values (null), (null), (null);
|
insert into t2 (b) values (null), (null), (null);
|
|
select a from t1 where b is null order by a desc limit 2;
|
select a from t2 where b is null order by a desc limit 2;
|
|
--disable_warnings
|
drop table if exists t1, t2;
|
--enable_warnings
|
2) First expected/correct results on MariaDB 5.5.28a
cd mariadb-5.5.28a-linux-x86_64/mysql-test/
|
./mysql-test-run.pl --embedded-server --record select_order_by_desc_limit_problem
|
cat r/select_order_by_desc_limit_problem.result
|
drop table if exists t1, t2;
|
create table t1 (a bigint not null unique auto_increment, b varchar(10), primary key (a), key (b(2))) engine = myisam default character set utf8;
|
create table t2 (a bigint not null unique auto_increment, b varchar(10), primary key (a), key (b(2))) engine = innodb default character set utf8;
|
insert into t1 (b) values (null), (null), (null);
|
insert into t2 (b) values (null), (null), (null);
|
select a from t1 where b is null order by a desc limit 2;
|
a
|
3
|
2
|
select a from t2 where b is null order by a desc limit 2;
|
a
|
3
|
2
|
drop table if exists t1, t2;
|
3) Then unexpected InnoDB results on MariaDB 5.5.29 (and later):
cd mariadb-5.5.29-linux-x86_64/mysql-test/
|
./mysql-test-run.pl --embedded-server --record select_order_by_desc_limit_problem
|
cat r/select_order_by_desc_limit_problem.result
|
drop table if exists t1, t2;
|
create table t1 (a bigint not null unique auto_increment, b varchar(10), primary key (a), key (b(2))) engine = myisam default character set utf8;
|
create table t2 (a bigint not null unique auto_increment, b varchar(10), primary key (a), key (b(2))) engine = innodb default character set utf8;
|
insert into t1 (b) values (null), (null), (null);
|
insert into t2 (b) values (null), (null), (null);
|
select a from t1 where b is null order by a desc limit 2;
|
a
|
3
|
2
|
select a from t2 where b is null order by a desc limit 2;
|
a
|
1
|
2
|
drop table if exists t1, t2;
|
{"report":{"fcp":1111.7999999523163,"ttfb":234.39999997615814,"pageVisibility":"visible","entityId":28001,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"cbe6eee2-8ec8-42c1-9a0f-5ea360c37de0","navigationType":0,"readyForUser":1195.1999999284744,"redirectCount":0,"resourceLoadedEnd":1064.8999999761581,"resourceLoadedStart":240.60000002384186,"resourceTiming":[{"duration":384.89999997615814,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":240.60000002384186,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":240.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":625.5,"responseStart":0,"secureConnectionStart":0},{"duration":384.89999997615814,"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":240.89999997615814,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":240.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":625.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":393.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":241.10000002384186,"connectEnd":241.10000002384186,"connectStart":241.10000002384186,"domainLookupEnd":241.10000002384186,"domainLookupStart":241.10000002384186,"fetchStart":241.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":241.10000002384186,"responseEnd":634.6999999284744,"responseStart":634.6000000238419,"secureConnectionStart":241.10000002384186},{"duration":434.39999997615814,"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":241.29999995231628,"connectEnd":241.29999995231628,"connectStart":241.29999995231628,"domainLookupEnd":241.29999995231628,"domainLookupStart":241.29999995231628,"fetchStart":241.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":241.29999995231628,"responseEnd":675.6999999284744,"responseStart":675.6999999284744,"secureConnectionStart":241.29999995231628},{"duration":437.7999999523163,"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":241.60000002384186,"connectEnd":241.60000002384186,"connectStart":241.60000002384186,"domainLookupEnd":241.60000002384186,"domainLookupStart":241.60000002384186,"fetchStart":241.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":241.60000002384186,"responseEnd":679.3999999761581,"responseStart":679.3999999761581,"secureConnectionStart":241.60000002384186},{"duration":439,"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":241.79999995231628,"connectEnd":241.79999995231628,"connectStart":241.79999995231628,"domainLookupEnd":241.79999995231628,"domainLookupStart":241.79999995231628,"fetchStart":241.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":241.79999995231628,"responseEnd":680.7999999523163,"responseStart":680.7999999523163,"secureConnectionStart":241.79999995231628},{"duration":440.2000000476837,"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":241.89999997615814,"connectEnd":241.89999997615814,"connectStart":241.89999997615814,"domainLookupEnd":241.89999997615814,"domainLookupStart":241.89999997615814,"fetchStart":241.89999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":241.89999997615814,"responseEnd":682.1000000238419,"responseStart":682.1000000238419,"secureConnectionStart":241.89999997615814},{"duration":539.3000000715256,"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":242.19999992847443,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":242.19999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":781.5,"responseStart":0,"secureConnectionStart":0},{"duration":441.3000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":242.29999995231628,"connectEnd":242.29999995231628,"connectStart":242.29999995231628,"domainLookupEnd":242.29999995231628,"domainLookupStart":242.29999995231628,"fetchStart":242.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":242.29999995231628,"responseEnd":683.6000000238419,"responseStart":683.6000000238419,"secureConnectionStart":242.29999995231628},{"duration":539.1000000238419,"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":242.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":242.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":781.6000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":442.40000009536743,"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":242.69999992847443,"connectEnd":242.69999992847443,"connectStart":242.69999992847443,"domainLookupEnd":242.69999992847443,"domainLookupStart":242.69999992847443,"fetchStart":242.69999992847443,"redirectEnd":0,"redirectStart":0,"requestStart":242.69999992847443,"responseEnd":685.1000000238419,"responseStart":685.1000000238419,"secureConnectionStart":242.69999992847443},{"duration":583.7999999523163,"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":243.60000002384186,"connectEnd":243.60000002384186,"connectStart":243.60000002384186,"domainLookupEnd":243.60000002384186,"domainLookupStart":243.60000002384186,"fetchStart":243.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":243.60000002384186,"responseEnd":827.3999999761581,"responseStart":827.3999999761581,"secureConnectionStart":243.60000002384186},{"duration":646.5,"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":248.29999995231628,"connectEnd":248.29999995231628,"connectStart":248.29999995231628,"domainLookupEnd":248.29999995231628,"domainLookupStart":248.29999995231628,"fetchStart":248.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":248.29999995231628,"responseEnd":894.7999999523163,"responseStart":894.7999999523163,"secureConnectionStart":248.29999995231628},{"duration":36.10000002384186,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":810.7999999523163,"connectEnd":810.7999999523163,"connectStart":810.7999999523163,"domainLookupEnd":810.7999999523163,"domainLookupStart":810.7999999523163,"fetchStart":810.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":810.7999999523163,"responseEnd":846.8999999761581,"responseStart":846.8999999761581,"secureConnectionStart":810.7999999523163},{"duration":211.5,"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":853.3999999761581,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":853.3999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1064.8999999761581,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":59,"responseStart":235,"responseEnd":241,"domLoading":238,"domInteractive":1299,"domContentLoadedEventStart":1299,"domContentLoadedEventEnd":1356,"domComplete":1701,"loadEventStart":1701,"loadEventEnd":1702,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1241.2999999523163},{"name":"bigPipe.sidebar-id.end","time":1242.1000000238419},{"name":"bigPipe.activity-panel-pipe-id.start","time":1242.1999999284744},{"name":"bigPipe.activity-panel-pipe-id.end","time":1243.7999999523163},{"name":"activityTabFullyLoaded","time":1370.6999999284744}],"measures":[],"correlationId":"6a2787280dede8","effectiveType":"4g","downlink":9.9,"rtt":0,"serverDuration":107,"dbReadsTimeInMs":14,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks for the perfect test case. Reproducible as described.
The problem was introduced in 5.5 tree with the following revision:
------------------------------------------------------------
revno: 3620
fixes bug: https://mariadb.atlassian.net/browse/MDEV-3992
committer: timour@askmonty.org
branch nick: 5.5
timestamp: Tue 2013-01-15 14:33:08 +0200
message:
Fix for bug
MDEV-3992, second attemptThe previous fix for
MDEV-3992was incomplete, because it still computedincorrectly the number of keyparts of the extended secondary key in the
case when columns of the PK participate in the secondary key.
------------------------------------------------------------