Discovered while debugging MDEV-35848.
Preamble:
drop table if exists t1, t2;
|
create table t1 (id int primary key, v int);
|
create table t2 (id int primary key, v int);
|
insert into t1 (id, v) values (2,3),(1,4);
|
insert into t2 (id, v) values (5,5),(6,6);
|
Test case:
UPDATE t1, t2 SET t1.v=-1, t2.v=-1 ORDER BY t1.id, t2.id LIMIT 2;
|
Observed result:
MariaDB [test]> select * from t1;
|
+----+------+
|
| id | v |
|
+----+------+
|
| 1 | -1 |
|
| 2 | -1 |
|
+----+------+
|
2 rows in set (0.002 sec)
|
|
MariaDB [test]> select * from t2;
|
+----+------+
|
| id | v |
|
+----+------+
|
| 5 | -1 |
|
| 6 | 6 |
|
+----+------+
|
2 rows in set (0.001 sec)
|
Expected result:
MariaDB [test]> select * from t1;
|
+----+------+
|
| id | v |
|
+----+------+
|
| 1 | -1 |
|
| 2 | 3 |
|
+----+------+
|
2 rows in set (0.002 sec)
|
|
MariaDB [test]> select * from t2;
|
+----+------+
|
| id | v |
|
+----+------+
|
| 5 | -1 |
|
| 6 | -1 |
|
+----+------+
|
2 rows in set (0.001 sec)
|
From debugging, we see that between the calls to items1= ref_ptr_array_slice(slice_num: 2); and set_items_ref_array(src_arr: items1); (both from JOIN::make_aggr_tables_info()) the ORDER BY clause gets reversed so that t2 is before t1.
- blocks
-
MDEV-35848
Multi-table DELETE with order by...limit works incorrect
-
-
Closed
{"report":{"fcp":882.5,"ttfb":349.5,"pageVisibility":"visible","entityId":132577,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"bc273f45-a0e3-4b37-a951-5ac7a322a4d0","navigationType":0,"readyForUser":1018.1999999880791,"redirectCount":0,"resourceLoadedEnd":952.7999999970198,"resourceLoadedStart":355.29999999701977,"resourceTiming":[{"duration":7.399999991059303,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":355.29999999701977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":355.29999999701977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":362.69999998807907,"responseStart":0,"secureConnectionStart":0},{"duration":7.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":355.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":355.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":363,"responseStart":0,"secureConnectionStart":0},{"duration":68.70000000298023,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":355.69999998807907,"connectEnd":355.69999998807907,"connectStart":355.69999998807907,"domainLookupEnd":355.69999998807907,"domainLookupStart":355.69999998807907,"fetchStart":355.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":355.69999998807907,"responseEnd":424.3999999910593,"responseStart":424.3999999910593,"secureConnectionStart":355.69999998807907},{"duration":132.6000000089407,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":355.8999999910593,"connectEnd":355.8999999910593,"connectStart":355.8999999910593,"domainLookupEnd":355.8999999910593,"domainLookupStart":355.8999999910593,"fetchStart":355.8999999910593,"redirectEnd":0,"redirectStart":0,"requestStart":355.8999999910593,"responseEnd":488.5,"responseStart":488.5,"secureConnectionStart":355.8999999910593},{"duration":136.29999999701977,"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":356.09999999403954,"connectEnd":356.09999999403954,"connectStart":356.09999999403954,"domainLookupEnd":356.09999999403954,"domainLookupStart":356.09999999403954,"fetchStart":356.09999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":356.09999999403954,"responseEnd":492.3999999910593,"responseStart":492.3999999910593,"secureConnectionStart":356.09999999403954},{"duration":137.09999999403954,"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":356.29999999701977,"connectEnd":356.29999999701977,"connectStart":356.29999999701977,"domainLookupEnd":356.29999999701977,"domainLookupStart":356.29999999701977,"fetchStart":356.29999999701977,"redirectEnd":0,"redirectStart":0,"requestStart":356.29999999701977,"responseEnd":493.3999999910593,"responseStart":493.3999999910593,"secureConnectionStart":356.29999999701977},{"duration":137.59999999403954,"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":356.5,"connectEnd":356.5,"connectStart":356.5,"domainLookupEnd":356.5,"domainLookupStart":356.5,"fetchStart":356.5,"redirectEnd":0,"redirectStart":0,"requestStart":356.5,"responseEnd":494.09999999403954,"responseStart":494.09999999403954,"secureConnectionStart":356.5},{"duration":211.80000001192093,"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":356.69999998807907,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":356.69999998807907,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":568.5,"responseStart":0,"secureConnectionStart":0},{"duration":138,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":356.79999999701977,"connectEnd":356.79999999701977,"connectStart":356.79999999701977,"domainLookupEnd":356.79999999701977,"domainLookupStart":356.79999999701977,"fetchStart":356.79999999701977,"redirectEnd":0,"redirectStart":0,"requestStart":356.79999999701977,"responseEnd":494.79999999701977,"responseStart":494.79999999701977,"secureConnectionStart":356.79999999701977},{"duration":211.79999999701977,"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":357,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":357,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":568.7999999970198,"responseStart":0,"secureConnectionStart":0},{"duration":138.40000000596046,"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":357.09999999403954,"connectEnd":357.09999999403954,"connectStart":357.09999999403954,"domainLookupEnd":357.09999999403954,"domainLookupStart":357.09999999403954,"fetchStart":357.09999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":357.09999999403954,"responseEnd":495.5,"responseStart":495.5,"secureConnectionStart":357.09999999403954},{"duration":514,"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":358,"connectEnd":358,"connectStart":358,"domainLookupEnd":358,"domainLookupStart":358,"fetchStart":358,"redirectEnd":0,"redirectStart":0,"requestStart":358,"responseEnd":872,"responseStart":872,"secureConnectionStart":358},{"duration":527.7999999970198,"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":362.59999999403954,"connectEnd":362.59999999403954,"connectStart":362.59999999403954,"domainLookupEnd":362.59999999403954,"domainLookupStart":362.59999999403954,"fetchStart":362.59999999403954,"redirectEnd":0,"redirectStart":0,"requestStart":362.59999999403954,"responseEnd":890.3999999910593,"responseStart":890.3999999910593,"secureConnectionStart":362.59999999403954},{"duration":292.6000000089407,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":580.1999999880791,"connectEnd":580.1999999880791,"connectStart":580.1999999880791,"domainLookupEnd":580.1999999880791,"domainLookupStart":580.1999999880791,"fetchStart":580.1999999880791,"redirectEnd":0,"redirectStart":0,"requestStart":580.1999999880791,"responseEnd":872.7999999970198,"responseStart":872.7999999970198,"secureConnectionStart":580.1999999880791},{"duration":180,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":876,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":876,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1056,"responseStart":0,"secureConnectionStart":0},{"duration":53.20000000298023,"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&whisper-enabled=true","startTime":899.3999999910593,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":899.3999999910593,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":952.5999999940395,"responseStart":0,"secureConnectionStart":0},{"duration":52.79999999701977,"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&whisper-enabled=true","startTime":900,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":900,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":952.7999999970198,"responseStart":0,"secureConnectionStart":0},{"duration":30.299999997019768,"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&whisper-enabled=true","startTime":900.8999999910593,"connectEnd":900.8999999910593,"connectStart":900.8999999910593,"domainLookupEnd":900.8999999910593,"domainLookupStart":900.8999999910593,"fetchStart":900.8999999910593,"redirectEnd":0,"redirectStart":0,"requestStart":900.8999999910593,"responseEnd":931.1999999880791,"responseStart":931.1999999880791,"secureConnectionStart":900.8999999910593},{"duration":38.1000000089407,"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&whisper-enabled=true","startTime":901.3999999910593,"connectEnd":901.3999999910593,"connectStart":901.3999999910593,"domainLookupEnd":901.3999999910593,"domainLookupStart":901.3999999910593,"fetchStart":901.3999999910593,"redirectEnd":0,"redirectStart":0,"requestStart":901.3999999910593,"responseEnd":939.5,"responseStart":939.5,"secureConnectionStart":901.3999999910593},{"duration":38.79999999701977,"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&whisper-enabled=true","startTime":902,"connectEnd":902,"connectStart":902,"domainLookupEnd":902,"domainLookupStart":902,"fetchStart":902,"redirectEnd":0,"redirectStart":0,"requestStart":902,"responseEnd":940.7999999970198,"responseStart":940.7999999970198,"secureConnectionStart":902}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":177,"responseStart":350,"responseEnd":358,"domLoading":353,"domInteractive":1105,"domContentLoadedEventStart":1105,"domContentLoadedEventEnd":1164,"domComplete":1610,"loadEventStart":1610,"loadEventEnd":1612,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1067.2999999970198},{"name":"bigPipe.sidebar-id.end","time":1068.199999988079},{"name":"bigPipe.activity-panel-pipe-id.start","time":1068.3999999910593},{"name":"bigPipe.activity-panel-pipe-id.end","time":1070.0999999940395},{"name":"activityTabFullyLoaded","time":1182.0999999940395}],"measures":[],"correlationId":"5e5313a9929931","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":100,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
For UPDATE and during change_refs_to_tmp_fields, the select_lex->ref_pointer_array is mutated, then replaced by set_items_ref_array which causes the ORDER BY to reference different fields. Are the ORDER BY objects (ORDER*) also updated to point to the correct Items in the new ref array? No, they are not, and we can see that the ORDER* object's item pointers point someplace in the ref array and that's not updated after change_refs_to_tmp_fields. If we note the ORDER* addresses in setup_order (for example, at the call to find_order_in_list), we can see that they correctly reference their respective Item objects before the call to change_refs_to_tmp_fields in make_aggr_tables_info() and then, when the new ref array is installed, the same Item** pointers now, when dereferenced, point to different ORDER BY columns (that is, different Item instances, namely the ORDER* for t1.id now references t2.id and vice-versa).