Skip to content

Root category url_key causes full table scans #30519

Open
@george-vlahakis

Description

@george-vlahakis

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:

image

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

  1. Magento 2.2
  2. MySQL 5.6.35
  3. MAC OSX (behavior is not relevant to OS)

Steps to reproduce

  1. Have a large dataset (above 12K products and 3K categories all anchors)
  2. Try changing the URL key on a root category

Expected result

  1. Better performance
  2. Usage of indexes
  3. Progress report

Actual result

  1. Considerable delays, timeouts and eventual server death

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: ProductComponent: UrlIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for devReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchRisk: highSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions