Type:
Bug
Priority:
Minor
Resolution:
Fixed
Affects Version/s:
10.5
Take the DBT-3 dataset, make sure you have these indexes:
CREATE INDEX i_o_orderdate ON orders (o_orderdate);
CREATE INDEX i_o_custkey ON orders (o_custkey);
Run these two queries. The queries are the same, except for the ORDER BY list.
However this difference causes different join orders to be picked:
MariaDB [dbt3]> explain select * from orders,customer where o_custkey=c_custkey order by o_orderdate limit 10;
+------+-------------+----------+--------+---------------+---------------+---------+-----------------------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+----------+--------+---------------+---------------+---------+-----------------------+------+-------------+
| 1 | SIMPLE | orders | index | i_o_custkey | i_o_orderdate | 4 | NULL | 10 | Using where |
| 1 | SIMPLE | customer | eq_ref | PRIMARY | PRIMARY | 4 | dbt3.orders.o_custkey | 1 | |
+------+-------------+----------+--------+---------------+---------------+---------+-----------------------+------+-------------+
MariaDB [dbt3]> explain select * from orders,customer where o_custkey=c_custkey order by c_acctbal limit 10;
+------+-------------+----------+-------+---------------+-------------+---------+-------------------------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+----------+-------+---------------+-------------+---------+-------------------------+------+-------+
| 1 | SIMPLE | customer | index | PRIMARY | c_acctbal | 9 | NULL | 1 | |
| 1 | SIMPLE | orders | ref | i_o_custkey | i_o_custkey | 5 | dbt3.customer.c_custkey | 15 | |
+------+-------------+----------+-------+---------------+-------------+---------+-------------------------+------+-------+
However, looking at the optimizer trace, one can see that the join optimization parts are identical:
MariaDB [dbt3]> select * from information_schema.optimizer_trace\G
*************************** 1. row ***************************
- QUERY: explain select * from orders,customer where o_custkey=c_custkey order by o_orderdate limit 10
+ QUERY: explain select * from orders,customer where o_custkey=c_custkey order by c_acctbal limit 10
TRACE: {
"steps": [
{
@@ -18,7 +17,7 @@
"select_id": 1,
"steps": [
{
- "expanded_query": ...
+ "expanded_query": ...
}
]
}
@@ -177,15 +176,15 @@
},
{
"attaching_conditions_to_tables": {
- "original_condition": "customer.c_custkey = orders.o_custkey",
+ "original_condition": "orders.o_custkey = customer.c_custkey",
"attached_conditions_computation": [],
"attached_conditions_summary": [
{
- "table": "orders",
- "attached": "orders.o_custkey is not null"
+ "table": "customer",
+ "attached": null
},
The first difference is in "attaching_conditions_to_tables" ?
{"report":{"fcp":1322.0999999046326,"ttfb":269.89999985694885,"pageVisibility":"visible","entityId":82871,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"7575eb26-72c5-4ee6-b056-fdea5a919fee","navigationType":0,"readyForUser":1367.7000000476837,"redirectCount":0,"resourceLoadedEnd":855,"resourceLoadedStart":276,"resourceTiming":[{"duration":31.700000047683716,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":276,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":276,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":307.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":32,"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":276.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":276.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":308.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":257.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":276.5,"connectEnd":276.5,"connectStart":276.5,"domainLookupEnd":276.5,"domainLookupStart":276.5,"fetchStart":276.5,"redirectEnd":0,"redirectStart":0,"requestStart":312.2999999523163,"responseEnd":533.5999999046326,"responseStart":335,"secureConnectionStart":276.5},{"duration":521.3999998569489,"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":276.7000000476837,"connectEnd":276.7000000476837,"connectStart":276.7000000476837,"domainLookupEnd":276.7000000476837,"domainLookupStart":276.7000000476837,"fetchStart":276.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":313.09999990463257,"responseEnd":798.0999999046326,"responseStart":354.89999985694885,"secureConnectionStart":276.7000000476837},{"duration":65.40000009536743,"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":276.7999999523163,"connectEnd":276.7999999523163,"connectStart":276.7999999523163,"domainLookupEnd":276.7999999523163,"domainLookupStart":276.7999999523163,"fetchStart":276.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":313.59999990463257,"responseEnd":342.2000000476837,"responseStart":337.09999990463257,"secureConnectionStart":276.7999999523163},{"duration":65.89999985694885,"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":277,"connectEnd":277,"connectStart":277,"domainLookupEnd":277,"domainLookupStart":277,"fetchStart":277,"redirectEnd":0,"redirectStart":0,"requestStart":314.89999985694885,"responseEnd":342.89999985694885,"responseStart":337.89999985694885,"secureConnectionStart":277},{"duration":66,"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":277.2000000476837,"connectEnd":277.2000000476837,"connectStart":277.2000000476837,"domainLookupEnd":277.2000000476837,"domainLookupStart":277.2000000476837,"fetchStart":277.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":316,"responseEnd":343.2000000476837,"responseStart":338.7000000476837,"secureConnectionStart":277.2000000476837},{"duration":37.90000009536743,"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":277.39999985694885,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":277.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":315.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":114.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":277.59999990463257,"connectEnd":277.59999990463257,"connectStart":277.59999990463257,"domainLookupEnd":277.59999990463257,"domainLookupStart":277.59999990463257,"fetchStart":277.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":319.7999999523163,"responseEnd":391.7000000476837,"responseStart":390.39999985694885,"secureConnectionStart":277.59999990463257},{"duration":38.799999952316284,"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":277.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":277.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":316.59999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":86.29999995231628,"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":278,"connectEnd":278,"connectStart":278,"domainLookupEnd":278,"domainLookupStart":278,"fetchStart":278,"redirectEnd":0,"redirectStart":0,"requestStart":332.2999999523163,"responseEnd":364.2999999523163,"responseStart":362.5,"secureConnectionStart":278},{"duration":547.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":306.7000000476837,"connectEnd":306.7000000476837,"connectStart":306.7000000476837,"domainLookupEnd":306.7000000476837,"domainLookupStart":306.7000000476837,"fetchStart":306.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":369.5,"responseEnd":854.2000000476837,"responseStart":813.7999999523163,"secureConnectionStart":306.7000000476837},{"duration":548.2000000476837,"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":306.7999999523163,"connectEnd":306.7999999523163,"connectStart":306.7999999523163,"domainLookupEnd":306.7999999523163,"domainLookupStart":306.7999999523163,"fetchStart":306.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":400.7000000476837,"responseEnd":855,"responseStart":820,"secureConnectionStart":306.7999999523163},{"duration":276,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":691.2000000476837,"connectEnd":691.2000000476837,"connectStart":691.2000000476837,"domainLookupEnd":691.2000000476837,"domainLookupStart":691.2000000476837,"fetchStart":691.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":933.7999999523163,"responseEnd":967.2000000476837,"responseStart":966.5,"secureConnectionStart":691.2000000476837}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":82,"responseStart":269,"responseEnd":305,"domLoading":273,"domInteractive":1477,"domContentLoadedEventStart":1477,"domContentLoadedEventEnd":1526,"domComplete":3250,"loadEventStart":3250,"loadEventEnd":3250,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1440.7000000476837},{"name":"bigPipe.sidebar-id.end","time":1441.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1441.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1443.5999999046326},{"name":"activityTabFullyLoaded","time":1542.7000000476837}],"measures":[],"correlationId":"720eb2d6fe9c45","effectiveType":"4g","downlink":9,"rtt":0,"serverDuration":109,"dbReadsTimeInMs":12,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The test was done on the mdev8306-orig branch... were there any improvements to the trace since then?