Skip to content

Conversation

@freestream
Copy link
Contributor

@freestream freestream commented Sep 17, 2016

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.

Mage::getResourceModel('catalog/category_collection')
    ->addUrlRewriteToResult();

@freestream
Copy link
Contributor Author

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'
);

@albertdahlin
Copy link
Member

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 12344_3182748373 which will be excluded when using the LIKE 'category/%' filter.

The updated where part will include all redirects since they have category_id.

@freestream
Copy link
Contributor Author

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.

@albertdahlin
Copy link
Member

albertdahlin commented Sep 19, 2016

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.

@freestream
Copy link
Contributor Author

How have your testing with the other projects gone with this issue @albertdahlin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants