Description
Having a database with approx 4K categories (anchors) and 16K products spread throughout the tree, making a url_key change on a root category causes significant delays (in hours) to update children products and re-generate URL rewrites.
In specific:
When changing the URL key of a root category (say level 1) it will trigger a cascading regeneration of all url rewrites for all products within. This is expected behavior. However, the process increasingly slows down as the size of catalog_url_rewrite_product_category
increases. I have seen this process take over 5 hours!
To replicate, and test, I moved to using Oleg's extension (here: https://github.com/olegkoval/magento2-regenerate_url_rewrites) which in essence does the same thing.
Regenerating url rewrites took over 8 hours for two stores.
Further investigation with slow_query enabled showed that DELETE sql calls on https://github.com/olegkoval/magento2-regenerate_url_rewrites
before inserts are causing full table scans. Example:
DELETE FROM `catalog_url_rewrite_product_category`
WHERE
(url_rewrite_id IN ((SELECT
`url_rewrite`.`url_rewrite_id`
FROM
`url_rewrite`
WHERE
(`entity_id` IN ('13614' , '13615', '13617'))
AND (`store_id` IN (2))
AND (`entity_type` IN ('product')))));
The above took over 2 seconds to execute and causes a full table scan on catalog_url_rewrite_product_category
:
I tried adding a key on url_rewrite_id
(there is none) but had no speed changes and a full table scan is still preferred by MySQL.
Assuming, Magento 2.x correctly produces the multiple url rewrites (creating a huge url_rewrites table) then this behavior renders Magento completely unusable for large datasets.
Preconditions
- Magento 2.2
- MySQL 5.6.35
- MAC OSX (behavior is not relevant to OS)
Steps to reproduce
- Have a large dataset (above 12K products and 3K categories all anchors)
- Try changing the URL key on a root category
Expected result
- Better performance
- Usage of indexes
- Progress report
Actual result
- Considerable delays, timeouts and eventual server death