Optimize Post_Link_Indexing_Action queries (replace LEFT JOIN + OR with EXISTS)#23000
Closed
adconecto wants to merge 1 commit intoYoast:trunkfrom
Closed
Optimize Post_Link_Indexing_Action queries (replace LEFT JOIN + OR with EXISTS)#23000adconecto wants to merge 1 commit intoYoast:trunkfrom
adconecto wants to merge 1 commit intoYoast:trunkfrom
Conversation
11 tasks
Contributor
|
Hi @adconecto . I have create a new PR. With your suggestion and added some unit tests to the PR. I'm closing this PR in favor of that one, so we can keep track of the task at hand. Thanks for your contribution! |
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.
Replace LEFT JOIN with EXISTS in Post_Link_Indexing_Action queries
Context
The queries in Post_Link_Indexing_Action::get_count_query() and
Post_Link_Indexing_Action::get_select_query() use a LEFT JOIN + OR pattern:
On medium-sized datasets (~25k posts / ~33k seo_links rows), this structure results in very slow execution times (60+ seconds).
The issue is not dataset scale but query structure.
The LEFT JOIN + OR combination prevents efficient index usage and can lead to suboptimal execution plans and table scans.
This PR rewrites the queries using EXISTS / NOT EXISTS, which allows MySQL/MariaDB to:
Summary
This PR can be summarized in the following changelog entry:
Improves performance of internal link indexing by replacing a LEFT JOIN + OR query pattern with EXISTS / NOT EXISTS in Post_Link_Indexing_Action.
Label: changelog: enhancement
Relevant technical choices:
Original problematic pattern:
New pattern:
This allows the database optimizer to:
Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
Expected result:
Relevant test scenarios
Test instructions for QA when the code is in the RC
Impact check
This PR affects:
Internal link indexing logic
Database query performance for:
No UI components or front-end rendering are affected.
Other environments
[shopify-seo], added test instructions for Shopify and attached theShopifylabel to this PR.[yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached theGoogle Docs Add-onlabel to this PR.Documentation
Quality assurance
grunt build:imagesand commited the results, if my PR introduces new images or SVGs.Innovation
innovationlabel.See also #22997