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":799.2000002861023,"ttfb":245.80000019073486,"pageVisibility":"visible","entityId":132577,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"a11f5850-7e0a-42ce-9560-e366b9f70f0a","navigationType":0,"readyForUser":871.7000002861023,"redirectCount":0,"resourceLoadedEnd":489.5,"resourceLoadedStart":251.09999990463257,"resourceTiming":[{"duration":36.700000286102295,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":251.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":251.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":287.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":36.90000009536743,"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":251.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":251.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":288.30000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":89,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":251.59999990463257,"connectEnd":251.59999990463257,"connectStart":251.59999990463257,"domainLookupEnd":251.59999990463257,"domainLookupStart":251.59999990463257,"fetchStart":251.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":292.90000009536743,"responseEnd":340.59999990463257,"responseStart":306.2000002861023,"secureConnectionStart":251.59999990463257},{"duration":117.39999961853027,"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":251.7000002861023,"connectEnd":251.7000002861023,"connectStart":251.7000002861023,"domainLookupEnd":251.7000002861023,"domainLookupStart":251.7000002861023,"fetchStart":251.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":293.2000002861023,"responseEnd":369.09999990463257,"responseStart":306.90000009536743,"secureConnectionStart":251.7000002861023},{"duration":52.80000019073486,"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":252,"connectEnd":252,"connectStart":252,"domainLookupEnd":252,"domainLookupStart":252,"fetchStart":252,"redirectEnd":0,"redirectStart":0,"requestStart":293.40000009536743,"responseEnd":304.80000019073486,"responseStart":304,"secureConnectionStart":252},{"duration":59.39999961853027,"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":252.2000002861023,"connectEnd":252.2000002861023,"connectStart":252.2000002861023,"domainLookupEnd":252.2000002861023,"domainLookupStart":252.2000002861023,"fetchStart":252.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":295.40000009536743,"responseEnd":311.59999990463257,"responseStart":311.09999990463257,"secureConnectionStart":252.2000002861023},{"duration":60.19999980926514,"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":252.30000019073486,"connectEnd":252.30000019073486,"connectStart":252.30000019073486,"domainLookupEnd":252.30000019073486,"domainLookupStart":252.30000019073486,"fetchStart":252.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":296.2000002861023,"responseEnd":312.5,"responseStart":311.7000002861023,"secureConnectionStart":252.30000019073486},{"duration":42.09999990463257,"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":252.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":252.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":294.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":44,"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":252.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":252.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":296.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":66.2999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":252.7000002861023,"connectEnd":252.7000002861023,"connectStart":252.7000002861023,"domainLookupEnd":252.7000002861023,"domainLookupStart":252.7000002861023,"fetchStart":252.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":297.5,"responseEnd":319,"responseStart":318.2000002861023,"secureConnectionStart":252.7000002861023},{"duration":64.5,"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":252.90000009536743,"connectEnd":252.90000009536743,"connectStart":252.90000009536743,"domainLookupEnd":252.90000009536743,"domainLookupStart":252.90000009536743,"fetchStart":252.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":301,"responseEnd":317.40000009536743,"responseStart":316.5,"secureConnectionStart":252.90000009536743},{"duration":202,"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":278.09999990463257,"connectEnd":278.09999990463257,"connectStart":278.09999990463257,"domainLookupEnd":278.09999990463257,"domainLookupStart":278.09999990463257,"fetchStart":278.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":337.80000019073486,"responseEnd":480.09999990463257,"responseStart":478.59999990463257,"secureConnectionStart":278.09999990463257},{"duration":207.5,"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":282,"connectEnd":282,"connectStart":282,"domainLookupEnd":282,"domainLookupStart":282,"fetchStart":282,"redirectEnd":0,"redirectStart":0,"requestStart":380.7000002861023,"responseEnd":489.5,"responseStart":485.09999990463257,"secureConnectionStart":282},{"duration":204.60000038146973,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":548.0999999046326,"connectEnd":548.0999999046326,"connectStart":548.0999999046326,"domainLookupEnd":548.0999999046326,"domainLookupStart":548.0999999046326,"fetchStart":548.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":713.9000000953674,"responseEnd":752.7000002861023,"responseStart":751.7000002861023,"secureConnectionStart":548.0999999046326},{"duration":127.60000038146973,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":778.0999999046326,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":778.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":905.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":85,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":800.0999999046326,"connectEnd":800.0999999046326,"connectStart":800.0999999046326,"domainLookupEnd":800.0999999046326,"domainLookupStart":800.0999999046326,"fetchStart":800.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":849.3000001907349,"responseEnd":885.0999999046326,"responseStart":883.9000000953674,"secureConnectionStart":800.0999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":80,"responseStart":246,"responseEnd":282,"domLoading":250,"domInteractive":934,"domContentLoadedEventStart":934,"domContentLoadedEventEnd":975,"domComplete":1123,"loadEventStart":1123,"loadEventEnd":1124,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":910.7000002861023},{"name":"bigPipe.sidebar-id.end","time":911.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":911.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":913.3000001907349},{"name":"activityTabFullyLoaded","time":994}],"measures":[],"correlationId":"604cd295da93df","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":98,"dbReadsTimeInMs":11,"dbConnsTimeInMs":20,"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).