Using the attached mysqldump, the following query is very slow in MariaDB compared to MySQL 5.5 or MySQL 5.6:
SELECT 1 FROM `catalog_category_flat_store_1` AS `main_table`
|
LEFT JOIN `core_url_rewrite` AS `url_rewrite`
|
ON url_rewrite.category_id=main_table.entity_id
|
AND url_rewrite.is_system=1
|
AND url_rewrite.store_id = 1
|
AND url_rewrite.id_path LIKE 'category/%'
|
WHERE (main_table.include_in_menu = '1')
|
AND (main_table.is_active = '1')
|
AND (main_table.path like '1/2/%')
|
ORDER BY `main_table`.`position` ASC
|
The schema and query are part of Magento, but the attached dump has had FK, some unique indexes, and most of the columns dropped.
The query plan in MySQL, which executes quickly:
| 1 | SIMPLE | main_table | ALL | IDX_CATALOG_CATEGORY_FLAT_STORE_1_PATH | NULL | NULL | NULL | 124 | Using where; Using temporary; Using filesort |
|
| 1 | SIMPLE | url_rewrite | range | UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID,IDX_CORE_URL_REWRITE_ID_PATH,IDX_CORE_URL_REWRITE_STORE_ID,FK_CORE_URL_REWRITE_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID | UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID | 773 | NULL | 1138 | Using where |
|
5.6 has BNL and using Join buffer for the second table, and runs at a similar speed.
In MariaDB 5.5 and MariaDB 10, the following slow plan is used:
| 1 | SIMPLE | main_table | ALL | IDX_CATALOG_CATEGORY_FLAT_STORE_1_PATH | NULL | NULL | NULL | 149 | Using where; Using filesort |
|
| 1 | SIMPLE | url_rewrite | range | UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID,IDX_CORE_URL_REWRITE_ID_PATH,IDX_CORE_URL_REWRITE_STORE_ID,FK_CORE_URL_REWRITE_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID | UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID | 773 | NULL | 1138 | Range checked for each record (index map: 0x74) |
|
This can be made fast in MariaDB with ADD INDEX ix_foo (category_id, store_id) or IGNORE INDEX.
There also seems to be no optimizer_switch to turn off this strategy.
{"report":{"fcp":784.2999999523163,"ttfb":197.5,"pageVisibility":"visible","entityId":44431,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"84afe8d8-055d-4883-8765-f79f9343deef","navigationType":0,"readyForUser":865.9000000953674,"redirectCount":0,"resourceLoadedEnd":516.7999999523163,"resourceLoadedStart":205.90000009536743,"resourceTiming":[{"duration":2.8999998569488525,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":205.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":205.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":208.79999995231628,"responseStart":0,"secureConnectionStart":0},{"duration":3.700000047683716,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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","startTime":206.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":206.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":210.10000014305115,"responseStart":0,"secureConnectionStart":0},{"duration":196.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/b09d0d077992e4331b5f9ec0d3ec448c-CDN/lu2bsh/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":206.70000004768372,"connectEnd":206.70000004768372,"connectStart":206.70000004768372,"domainLookupEnd":206.70000004768372,"domainLookupStart":206.70000004768372,"fetchStart":206.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":212.40000009536743,"responseEnd":403.2999999523163,"responseStart":232,"secureConnectionStart":206.70000004768372},{"duration":309.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/b47ab3df14096803b180217eb8482517-CDN/lu2bsh/820016/12ta74/eb142f92e4bd16bd1ef8b08c1b9d5d56/_/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","startTime":207.20000004768372,"connectEnd":207.20000004768372,"connectStart":207.20000004768372,"domainLookupEnd":207.20000004768372,"domainLookupStart":207.20000004768372,"fetchStart":207.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":212.70000004768372,"responseEnd":516.7999999523163,"responseStart":234.60000014305115,"secureConnectionStart":207.20000004768372},{"duration":34.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/6c569cbf8087ab04e40d0bef98627457-CDN/lu2bsh/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":207.29999995231628,"connectEnd":207.29999995231628,"connectStart":207.29999995231628,"domainLookupEnd":207.29999995231628,"domainLookupStart":207.29999995231628,"fetchStart":207.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":215.90000009536743,"responseEnd":241.40000009536743,"responseStart":239.20000004768372,"secureConnectionStart":207.29999995231628},{"duration":37.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":207.29999995231628,"connectEnd":207.29999995231628,"connectStart":207.29999995231628,"domainLookupEnd":207.29999995231628,"domainLookupStart":207.29999995231628,"fetchStart":207.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":216.5,"responseEnd":244.70000004768372,"responseStart":241.90000009536743,"secureConnectionStart":207.29999995231628},{"duration":37.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":207.40000009536743,"connectEnd":207.40000009536743,"connectStart":207.40000009536743,"domainLookupEnd":207.40000009536743,"domainLookupStart":207.40000009536743,"fetchStart":207.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":216.60000014305115,"responseEnd":244.90000009536743,"responseStart":242.79999995231628,"secureConnectionStart":207.40000009536743},{"duration":7.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bsh/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":207.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":207.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":215,"responseStart":0,"secureConnectionStart":0},{"duration":8.099999904632568,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bsh/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":207.60000014305115,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":207.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":215.70000004768372,"responseStart":0,"secureConnectionStart":0},{"duration":37.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":207.60000014305115,"connectEnd":207.60000014305115,"connectStart":207.60000014305115,"domainLookupEnd":207.60000014305115,"domainLookupStart":207.60000014305115,"fetchStart":207.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":216.79999995231628,"responseEnd":245.20000004768372,"responseStart":243.60000014305115,"secureConnectionStart":207.60000014305115},{"duration":43.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/81b5d7c27af3ebc078cc4a36383678ba-CDN/lu2bsh/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":207.79999995231628,"connectEnd":207.79999995231628,"connectStart":207.79999995231628,"domainLookupEnd":207.79999995231628,"domainLookupStart":207.79999995231628,"fetchStart":207.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":224.5,"responseEnd":251.60000014305115,"responseStart":250,"secureConnectionStart":207.79999995231628},{"duration":275.60000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":215.79999995231628,"connectEnd":215.79999995231628,"connectStart":215.79999995231628,"domainLookupEnd":215.79999995231628,"domainLookupStart":215.79999995231628,"fetchStart":215.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":240.90000009536743,"responseEnd":491.40000009536743,"responseStart":484.40000009536743,"secureConnectionStart":215.79999995231628},{"duration":275.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bsh/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":216,"connectEnd":216,"connectStart":216,"domainLookupEnd":216,"domainLookupStart":216,"fetchStart":216,"redirectEnd":0,"redirectStart":0,"requestStart":241.10000014305115,"responseEnd":491.7999999523163,"responseStart":486.10000014305115,"secureConnectionStart":216},{"duration":106.90000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":547.7000000476837,"connectEnd":547.7000000476837,"connectStart":547.7000000476837,"domainLookupEnd":547.7000000476837,"domainLookupStart":547.7000000476837,"fetchStart":547.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":621.2999999523163,"responseEnd":654.6000001430511,"responseStart":653.7999999523163,"secureConnectionStart":547.7000000476837},{"duration":104.90000009536743,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":776.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":776.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":881.1000001430511,"responseStart":0,"secureConnectionStart":0},{"duration":133.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":782.7999999523163,"connectEnd":782.7999999523163,"connectStart":782.7999999523163,"domainLookupEnd":782.7999999523163,"domainLookupStart":782.7999999523163,"fetchStart":782.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":881.9000000953674,"responseEnd":916.2999999523163,"responseStart":914.9000000953674,"secureConnectionStart":782.7999999523163}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":39,"responseStart":198,"responseEnd":217,"domLoading":201,"domInteractive":968,"domContentLoadedEventStart":968,"domContentLoadedEventEnd":1014,"domComplete":1204,"loadEventStart":1204,"loadEventEnd":1205,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":943.1000001430511},{"name":"bigPipe.sidebar-id.end","time":943.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":943.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":945.5},{"name":"activityTabFullyLoaded","time":1035.7999999523163}],"measures":[],"correlationId":"ddad65cc1cf4c2","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":80,"dbReadsTimeInMs":15,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
With this patch on 5.5.42, I have gotten a few different plans depending on what table statistics happen to be, each not using "Range checked for each record (index map: 0x1E)" and several orders of magnitude faster than unpatched 5.5.42 which uses "Range checked for each record (index map: 0x1E)" for my sample data and query.