Adding URL rewrite to category collection causes unnecessary long query#17
Adding URL rewrite to category collection causes unnecessary long query#17freestream wants to merge 3 commits intowebbhuset:masterfrom freestream:feat/catalog-url-rewite-join
Conversation
|
The fix i wrote is pants down the quickest query but it could potentially cause unexpected duplicate results depending on how broken the core_url_table is for the Magento project. I created here an alternative method of gettings the same result and mimicking more of the default query behaviour which still will give an highly improved query time speed. $collection->joinTable(
'core/url_rewrite',
'category_id=entity_id',
array('request_path'),
"{{table}}.is_system=1 AND " .
"{{table}}.store_id='{$storeId}' AND " .
"LEFT({{table}}.id_path, 9) = 'category/'",
'left'
); |
|
We have seen this query running very slow on MySql 5.7 servers. It sometimes takes like 200 sek to complete. However, changing this "{{table}}.id_path LIKE 'category/%'",to "{{table}}.category_id IS NOT NULL AND " .
"{{table}}.product_id IS NULL",will cause duplicate rows when you have redirects. Redirects are created with an id_path like The updated where part will include all redirects since they have category_id. |
|
If you are referring to custom rewrites they are not set to is_system=1 and therefore that fix should still be safe. But I can agree that it is still not the safes way to do it. Therefore I submitted an alternative method in my last comment that is more as the original method but still faster. |
|
You're right. Didn't think about that. I will test this on some projects to make sure we don't missed any corner cases. |
|
How have your testing with the other projects gone with this issue @albertdahlin? |
By replacing the LIKE search in request_path the query time speed is insanely improved.
This is a way if triggering/verifying the speed improvement.