Sergei Petrunia
added a comment - Review notes:
The idea behind the new function equality_propagation_for_order_items doesn't look good to me.
The effect of the function is similar (but exactly the same) as propagate_equal_fields call followed by substitute_for_best_equal_field call.
Here is an alternative variant of the fix that uses those two calls: https://gist.github.com/spetrunia/f48251cc87f07cc8e4a8fa9910bbe6c7
Before the patch, the optimizer only handles "ORDER BY table.col".
The code in remove_const() checks if it can be substituted with other_table.col, and whether that will allow to get rid of "Using temporary". No substitution is performed here. The substitution is done in Filesort::make_sortorder():
/*
It is possible that the query plan is to read table t1, while the
sort criteria actually has "ORDER BY t2.col" and the WHERE clause has
a multi-equality(t1.col, t2.col, ...).
The optimizer detects such cases (grep for
UseMultipleEqualitiesToRemoveTempTable to see where), but doesn't
perform equality substitution in the order->item. We need to do the
substitution here ourselves.
*/
9 table_map item_map= first->used_tables();
if (join && (item_map & ~join->const_table_map) &&
(item->get_item_equal() returns non-NULL only for Item_field and Item_direct_view_ref. )
Let's call the above "Late substitution".
The patch for this MDEv adds "early substitution": if the Item_field that we need to replace is not at the top level of the ORDER BY clause, it will be replaced in remove_const().
Can we switch the code to do the substitution in only one place and do it "early"?
I've tried to do that and got an assertion failure in create_tmp_table, not sure why.
Sergei Petrunia
added a comment - Another interesting observation:
Before the patch, the optimizer only handles "ORDER BY table.col".
The code in remove_const() checks if it can be substituted with other_table.col, and whether that will allow to get rid of "Using temporary". No substitution is performed here. The substitution is done in Filesort::make_sortorder():
/*
It is possible that the query plan is to read table t1, while the
sort criteria actually has "ORDER BY t2.col" and the WHERE clause has
a multi-equality(t1.col, t2.col, ...).
The optimizer detects such cases (grep for
UseMultipleEqualitiesToRemoveTempTable to see where), but doesn't
perform equality substitution in the order->item. We need to do the
substitution here ourselves.
*/
9 table_map item_map= first->used_tables();
if (join && (item_map & ~join->const_table_map) &&
!(item_map & first_table_bit) && join->cond_equal &&
first->get_item_equal())
{
(item->get_item_equal() returns non-NULL only for Item_field and Item_direct_view_ref. )
Let's call the above "Late substitution".
The patch for this MDEv adds "early substitution": if the Item_field that we need to replace is not at the top level of the ORDER BY clause, it will be replaced in remove_const() .
Can we switch the code to do the substitution in only one place and do it "early"?
I've tried to do that and got an assertion failure in create_tmp_table, not sure why.
People
Sergei Petrunia
Varun Gupta (Inactive)
Votes:
0Vote for this issue
Watchers:
5Start watching this issue
Dates
Created:
Updated:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1465.2000002861023,"ttfb":289.90000009536743,"pageVisibility":"visible","entityId":77732,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"e5b9f928-108f-4c4c-ad0a-3da18aae4910","navigationType":0,"readyForUser":1586.3000001907349,"redirectCount":0,"resourceLoadedEnd":1859.3000001907349,"resourceLoadedStart":297.30000019073486,"resourceTiming":[{"duration":454.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":297.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":297.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":751.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":454.1000003814697,"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":297.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":297.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":751.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":545.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":297.7000002861023,"connectEnd":297.7000002861023,"connectStart":297.7000002861023,"domainLookupEnd":297.7000002861023,"domainLookupStart":297.7000002861023,"fetchStart":297.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":297.7000002861023,"responseEnd":843.0999999046326,"responseStart":843.0999999046326,"secureConnectionStart":297.7000002861023},{"duration":675.9000000953674,"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":297.80000019073486,"connectEnd":297.80000019073486,"connectStart":297.80000019073486,"domainLookupEnd":297.80000019073486,"domainLookupStart":297.80000019073486,"fetchStart":297.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":297.80000019073486,"responseEnd":973.7000002861023,"responseStart":973.7000002861023,"secureConnectionStart":297.80000019073486},{"duration":707.2000002861023,"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":298,"connectEnd":298,"connectStart":298,"domainLookupEnd":298,"domainLookupStart":298,"fetchStart":298,"redirectEnd":0,"redirectStart":0,"requestStart":298,"responseEnd":1005.2000002861023,"responseStart":1005.2000002861023,"secureConnectionStart":298},{"duration":707.4000000953674,"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":298.30000019073486,"connectEnd":298.30000019073486,"connectStart":298.30000019073486,"domainLookupEnd":298.30000019073486,"domainLookupStart":298.30000019073486,"fetchStart":298.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":298.30000019073486,"responseEnd":1005.7000002861023,"responseStart":1005.7000002861023,"secureConnectionStart":298.30000019073486},{"duration":707.7000002861023,"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":298.5,"connectEnd":298.5,"connectStart":298.5,"domainLookupEnd":298.5,"domainLookupStart":298.5,"fetchStart":298.5,"redirectEnd":0,"redirectStart":0,"requestStart":298.5,"responseEnd":1006.2000002861023,"responseStart":1006.2000002861023,"secureConnectionStart":298.5},{"duration":737.6999998092651,"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":298.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":298.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1036.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":708.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":298.90000009536743,"connectEnd":298.90000009536743,"connectStart":298.90000009536743,"domainLookupEnd":298.90000009536743,"domainLookupStart":298.90000009536743,"fetchStart":298.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":298.90000009536743,"responseEnd":1007,"responseStart":1007,"secureConnectionStart":298.90000009536743},{"duration":737.8000001907349,"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":299,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":299,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1036.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":709.7999997138977,"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":299.2000002861023,"connectEnd":299.2000002861023,"connectStart":299.2000002861023,"domainLookupEnd":299.2000002861023,"domainLookupStart":299.2000002861023,"fetchStart":299.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":299.2000002861023,"responseEnd":1009,"responseStart":1009,"secureConnectionStart":299.2000002861023},{"duration":863.9000000953674,"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":300.09999990463257,"connectEnd":300.09999990463257,"connectStart":300.09999990463257,"domainLookupEnd":300.09999990463257,"domainLookupStart":300.09999990463257,"fetchStart":300.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":300.09999990463257,"responseEnd":1164,"responseStart":1164,"secureConnectionStart":300.09999990463257},{"duration":1540.2000002861023,"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":300.09999990463257,"connectEnd":300.09999990463257,"connectStart":300.09999990463257,"domainLookupEnd":300.09999990463257,"domainLookupStart":300.09999990463257,"fetchStart":300.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":300.09999990463257,"responseEnd":1840.3000001907349,"responseStart":1840.3000001907349,"secureConnectionStart":300.09999990463257},{"duration":128.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1053.5999999046326,"connectEnd":1053.5999999046326,"connectStart":1053.5999999046326,"domainLookupEnd":1053.5999999046326,"domainLookupStart":1053.5999999046326,"fetchStart":1053.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1053.5999999046326,"responseEnd":1182.0999999046326,"responseStart":1182.0999999046326,"secureConnectionStart":1053.5999999046326},{"duration":467.40000009536743,"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":1391.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1391.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1859.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":481.2000002861023,"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":1393,"connectEnd":1393,"connectStart":1393,"domainLookupEnd":1393,"domainLookupStart":1393,"fetchStart":1393,"redirectEnd":0,"redirectStart":0,"requestStart":1393,"responseEnd":1874.2000002861023,"responseStart":1874.2000002861023,"secureConnectionStart":1393},{"duration":486.30000019073486,"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":1393.4000000953674,"connectEnd":1393.4000000953674,"connectStart":1393.4000000953674,"domainLookupEnd":1393.4000000953674,"domainLookupStart":1393.4000000953674,"fetchStart":1393.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1393.4000000953674,"responseEnd":1879.7000002861023,"responseStart":1879.7000002861023,"secureConnectionStart":1393.4000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":127,"responseStart":290,"responseEnd":295,"domLoading":295,"domInteractive":1873,"domContentLoadedEventStart":1873,"domContentLoadedEventEnd":1929,"domComplete":2870,"loadEventStart":2871,"loadEventEnd":2871,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1842.5},{"name":"bigPipe.sidebar-id.end","time":1843.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1843.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1845.7000002861023},{"name":"activityTabFullyLoaded","time":1947.8000001907349}],"measures":[],"correlationId":"37e0dc278b2b14","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":104,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Patch
http://lists.askmonty.org/pipermail/commits/2019-July/013914.html