Add database index to fix slow post editing on large sites#22979
Open
ewimsatt wants to merge 1 commit intoYoast:trunkfrom
Open
Add database index to fix slow post editing on large sites#22979ewimsatt wants to merge 1 commit intoYoast:trunkfrom
ewimsatt wants to merge 1 commit intoYoast:trunkfrom
Conversation
Adds composite index on (primary_focus_keyword, object_type, post_status, object_id) to optimize duplicate focus keyword detection queries. Performance impact on sites with 800K+ indexables: - Before: 1.557 seconds - After: 0.001 seconds (1500x improvement) The query is executed on every post edit via WPSEO_Meta::keyword_usage() to check if the focus keyword is already used elsewhere. Fixes Yoast#22933
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a composite database index to dramatically improve performance of duplicate focus keyword lookups on large sites.
Problem
On sites with 800K+ indexables, the query in
WPSEO_Meta::keyword_usage()takes 1.5+ seconds, making post editing extremely slow. This query runs on every post edit to check if the primary focus keyword is already in use.Solution
Add a composite index on:
primary_focus_keywordobject_typepost_statusobject_idThis matches the exact WHERE clause pattern used in the query.
Performance Impact
Before index:
After index:
Implementation
CreateIndexableSubpagesIndex)up()anddown()for safe rollbackTesting
The migration can be tested by:
SHOW INDEX FROM wp_yoast_indexableFixes #22933