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":1019.0999999046326,"ttfb":304.30000019073486,"pageVisibility":"visible","entityId":77732,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"babb9e14-a20a-4d3a-b671-0d616eb8380d","navigationType":0,"readyForUser":1145.4000000953674,"redirectCount":0,"resourceLoadedEnd":1176.3000001907349,"resourceLoadedStart":308.90000009536743,"resourceTiming":[{"duration":203.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":308.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":308.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":512.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":203.19999980926514,"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":309.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":309.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":512.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":212.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":309.40000009536743,"connectEnd":309.40000009536743,"connectStart":309.40000009536743,"domainLookupEnd":309.40000009536743,"domainLookupStart":309.40000009536743,"fetchStart":309.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":309.40000009536743,"responseEnd":521.7000002861023,"responseStart":521.7000002861023,"secureConnectionStart":309.40000009536743},{"duration":294,"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":309.59999990463257,"connectEnd":309.59999990463257,"connectStart":309.59999990463257,"domainLookupEnd":309.59999990463257,"domainLookupStart":309.59999990463257,"fetchStart":309.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":309.59999990463257,"responseEnd":603.5999999046326,"responseStart":603.5999999046326,"secureConnectionStart":309.59999990463257},{"duration":297.69999980926514,"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":309.80000019073486,"connectEnd":309.80000019073486,"connectStart":309.80000019073486,"domainLookupEnd":309.80000019073486,"domainLookupStart":309.80000019073486,"fetchStart":309.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":309.80000019073486,"responseEnd":607.5,"responseStart":607.5,"secureConnectionStart":309.80000019073486},{"duration":298.09999990463257,"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":309.90000009536743,"connectEnd":309.90000009536743,"connectStart":309.90000009536743,"domainLookupEnd":309.90000009536743,"domainLookupStart":309.90000009536743,"fetchStart":309.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":309.90000009536743,"responseEnd":608,"responseStart":608,"secureConnectionStart":309.90000009536743},{"duration":298.5,"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":310.09999990463257,"connectEnd":310.09999990463257,"connectStart":310.09999990463257,"domainLookupEnd":310.09999990463257,"domainLookupStart":310.09999990463257,"fetchStart":310.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":310.09999990463257,"responseEnd":608.5999999046326,"responseStart":608.5999999046326,"secureConnectionStart":310.09999990463257},{"duration":350.40000009536743,"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":314.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":314.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":665,"responseStart":0,"secureConnectionStart":0},{"duration":294.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":314.90000009536743,"connectEnd":314.90000009536743,"connectStart":314.90000009536743,"domainLookupEnd":314.90000009536743,"domainLookupStart":314.90000009536743,"fetchStart":314.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":314.90000009536743,"responseEnd":609.0999999046326,"responseStart":609.0999999046326,"secureConnectionStart":314.90000009536743},{"duration":350,"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":315.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":315.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":665.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":294.7000002861023,"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":315.09999990463257,"connectEnd":315.09999990463257,"connectStart":315.09999990463257,"domainLookupEnd":315.09999990463257,"domainLookupStart":315.09999990463257,"fetchStart":315.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":315.09999990463257,"responseEnd":609.8000001907349,"responseStart":609.8000001907349,"secureConnectionStart":315.09999990463257},{"duration":469.5,"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":316.80000019073486,"connectEnd":316.80000019073486,"connectStart":316.80000019073486,"domainLookupEnd":316.80000019073486,"domainLookupStart":316.80000019073486,"fetchStart":316.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":316.80000019073486,"responseEnd":786.3000001907349,"responseStart":786.3000001907349,"secureConnectionStart":316.80000019073486},{"duration":855.8000001907349,"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":320.5,"connectEnd":320.5,"connectStart":320.5,"domainLookupEnd":320.5,"domainLookupStart":320.5,"fetchStart":320.5,"redirectEnd":0,"redirectStart":0,"requestStart":320.5,"responseEnd":1176.3000001907349,"responseStart":1176.3000001907349,"secureConnectionStart":320.5},{"duration":109.7000002861023,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":677.0999999046326,"connectEnd":677.0999999046326,"connectStart":677.0999999046326,"domainLookupEnd":677.0999999046326,"domainLookupStart":677.0999999046326,"fetchStart":677.0999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":677.0999999046326,"responseEnd":786.8000001907349,"responseStart":786.8000001907349,"secureConnectionStart":677.0999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":142,"responseStart":304,"responseEnd":320,"domLoading":307,"domInteractive":1209,"domContentLoadedEventStart":1209,"domContentLoadedEventEnd":1259,"domComplete":1559,"loadEventStart":1559,"loadEventEnd":1559,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1192.4000000953674},{"name":"bigPipe.sidebar-id.end","time":1193.2000002861023},{"name":"bigPipe.activity-panel-pipe-id.start","time":1193.3000001907349},{"name":"bigPipe.activity-panel-pipe-id.end","time":1195.0999999046326},{"name":"activityTabFullyLoaded","time":1284.4000000953674}],"measures":[],"correlationId":"a9be7c2735d0a2","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":99,"dbReadsTimeInMs":11,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Patch
http://lists.askmonty.org/pipermail/commits/2019-July/013914.html