CREATE TABLE `books` (
`id` int(16) NOT NULL AUTO_INCREMENT,
`library_id` int(16) NOT NULL DEFAULT 0,
`wings_id` int(12) NOT NULL DEFAULT 0,
`scheduled_for_removal` int(1) DEFAULT 0,
PRIMARY KEY (`id`),
KEY `library_idx` (`library_id`)
) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
INSERT INTO `books` VALUES (32625,8663,707,0),(32624,8663,505,1);
CREATE TABLE `wings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`department_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
INSERT INTO `wings` VALUES (505,11745),(707,11768);
SELECT wings.id as wing_id, wings.department_id FROM wings WHERE wings.id IN ( SELECT books.wings_id FROM books WHERE books.library_id = 8663 AND books.scheduled_for_removal=0 ) ORDER BY wings.id;
The result should be (707, 11768), but it results in (505, 11745).
Changing the engine for the books table to InnoDB, resolves the problem. Removing the library_idx on books also resolves the problem.
I also tested on mysql 5.5.57, 5.6.37, 5.7.19, and mariadb 5.5.57, 10.0.32 and 10.1.28, where the problem does not occur.
I've added `script.sql` containing the sql from above, and a wrapper script `reproduce.sh` to set up a docker environment for testing.
{"report":{"fcp":946.5,"ttfb":188,"pageVisibility":"visible","entityId":63470,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"1ef0b59e-fc90-4fad-a1df-7afc180e2145","navigationType":0,"readyForUser":1030.3000001907349,"redirectCount":0,"resourceLoadedEnd":1366.8000001907349,"resourceLoadedStart":193.5,"resourceTiming":[{"duration":247.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":193.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":193.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":441.30000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":247.89999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":193.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":193.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":441.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":194,"connectEnd":194,"connectStart":194,"domainLookupEnd":194,"domainLookupStart":194,"fetchStart":194,"redirectEnd":0,"redirectStart":0,"requestStart":194,"responseEnd":451,"responseStart":451,"secureConnectionStart":194},{"duration":308.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":194.10000038146973,"connectEnd":194.10000038146973,"connectStart":194.10000038146973,"domainLookupEnd":194.10000038146973,"domainLookupStart":194.10000038146973,"fetchStart":194.10000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":194.10000038146973,"responseEnd":502.4000005722046,"responseStart":502.4000005722046,"secureConnectionStart":194.10000038146973},{"duration":312.29999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":194.4000005722046,"connectEnd":194.4000005722046,"connectStart":194.4000005722046,"domainLookupEnd":194.4000005722046,"domainLookupStart":194.4000005722046,"fetchStart":194.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":194.4000005722046,"responseEnd":506.69999980926514,"responseStart":506.69999980926514,"secureConnectionStart":194.4000005722046},{"duration":312.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":194.60000038146973,"connectEnd":194.60000038146973,"connectStart":194.60000038146973,"domainLookupEnd":194.60000038146973,"domainLookupStart":194.60000038146973,"fetchStart":194.60000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":194.60000038146973,"responseEnd":507.1000003814697,"responseStart":507.1000003814697,"secureConnectionStart":194.60000038146973},{"duration":312.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":194.80000019073486,"connectEnd":194.80000019073486,"connectStart":194.80000019073486,"domainLookupEnd":194.80000019073486,"domainLookupStart":194.80000019073486,"fetchStart":194.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":194.80000019073486,"responseEnd":507.5,"responseStart":507.5,"secureConnectionStart":194.80000019073486},{"duration":410.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":194.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":194.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":605.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":312.8999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":195.10000038146973,"connectEnd":195.10000038146973,"connectStart":195.10000038146973,"domainLookupEnd":195.10000038146973,"domainLookupStart":195.10000038146973,"fetchStart":195.10000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":195.10000038146973,"responseEnd":508,"responseStart":508,"secureConnectionStart":195.10000038146973},{"duration":410.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/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":195.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":195.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":605.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":313.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/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":195.4000005722046,"connectEnd":195.4000005722046,"connectStart":195.4000005722046,"domainLookupEnd":195.4000005722046,"domainLookupStart":195.4000005722046,"fetchStart":195.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":195.4000005722046,"responseEnd":508.6000003814697,"responseStart":508.6000003814697,"secureConnectionStart":195.4000005722046},{"duration":1098.6000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":196.5,"connectEnd":196.5,"connectStart":196.5,"domainLookupEnd":196.5,"domainLookupStart":196.5,"fetchStart":196.5,"redirectEnd":0,"redirectStart":0,"requestStart":196.5,"responseEnd":1295.1000003814697,"responseStart":1295.1000003814697,"secureConnectionStart":196.5},{"duration":1095.1000003814697,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":201.30000019073486,"connectEnd":201.30000019073486,"connectStart":201.30000019073486,"domainLookupEnd":201.30000019073486,"domainLookupStart":201.30000019073486,"fetchStart":201.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":201.30000019073486,"responseEnd":1296.4000005722046,"responseStart":1296.4000005722046,"secureConnectionStart":201.30000019073486},{"duration":247.60000038146973,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":618.8000001907349,"connectEnd":618.8000001907349,"connectStart":618.8000001907349,"domainLookupEnd":618.8000001907349,"domainLookupStart":618.8000001907349,"fetchStart":618.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":618.8000001907349,"responseEnd":866.4000005722046,"responseStart":866.4000005722046,"secureConnectionStart":618.8000001907349},{"duration":469,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/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":897.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":897.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1366.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":468.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/50bc9be5bfead1a25e72c1a9338c94f6-CDN/lu2cib/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/css/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":897.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":897.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1366.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":432.9000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/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":898.6999998092651,"connectEnd":898.6999998092651,"connectStart":898.6999998092651,"domainLookupEnd":898.6999998092651,"domainLookupStart":898.6999998092651,"fetchStart":898.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":898.6999998092651,"responseEnd":1331.6000003814697,"responseStart":1331.6000003814697,"secureConnectionStart":898.6999998092651},{"duration":466.0999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/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":899.1000003814697,"connectEnd":899.1000003814697,"connectStart":899.1000003814697,"domainLookupEnd":899.1000003814697,"domainLookupStart":899.1000003814697,"fetchStart":899.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":899.1000003814697,"responseEnd":1365.1999998092651,"responseStart":1365.1999998092651,"secureConnectionStart":899.1000003814697},{"duration":467.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/e0bf5781d46ea69fb123572974cf39de-CDN/lu2cib/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/js/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":899.5,"connectEnd":899.5,"connectStart":899.5,"domainLookupEnd":899.5,"domainLookupStart":899.5,"fetchStart":899.5,"redirectEnd":0,"redirectStart":0,"requestStart":899.5,"responseEnd":1366.8000001907349,"responseStart":1366.8000001907349,"secureConnectionStart":899.5}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":21,"responseStart":188,"responseEnd":194,"domLoading":191,"domInteractive":1377,"domContentLoadedEventStart":1377,"domContentLoadedEventEnd":1424,"domComplete":1854,"loadEventStart":1854,"loadEventEnd":1855,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1299.9000005722046},{"name":"bigPipe.sidebar-id.end","time":1300.8000001907349},{"name":"bigPipe.activity-panel-pipe-id.start","time":1300.9000005722046},{"name":"bigPipe.activity-panel-pipe-id.end","time":1303.6000003814697},{"name":"activityTabFullyLoaded","time":1441.1999998092651}],"measures":[],"correlationId":"e0b90053e84f35","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":108,"dbReadsTimeInMs":13,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thanks for the report and test case. For a workaround, try setting optimizer_switch='orderby_uses_equalities=off'.
Same test case as in script.sql, suitable for MTR:
--source include/have_innodb.inc
Actual result (10.2)
+---------+---------------+
| wing_id | department_id |
+---------+---------------+
| 505 | 11745 |
+---------+---------------+
Expected result
+---------+---------------+
| wing_id | department_id |
+---------+---------------+
| 707 | 11768 |
+---------+---------------+
1 row in set (0.00 sec)