Skip to content

Adds indices to the SEO Links table for the URL field and target_indexable_id_index field.#22861

Merged
leonidasmi merged 3 commits intotrunkfrom
try/add-indexes
Jan 14, 2026
Merged

Adds indices to the SEO Links table for the URL field and target_indexable_id_index field.#22861
leonidasmi merged 3 commits intotrunkfrom
try/add-indexes

Conversation

@thijsoo
Copy link
Copy Markdown
Contributor

@thijsoo thijsoo commented Jan 5, 2026

Context

This is done to speed up at least two queries where theses fields are used in a single where statement. This way the where can use the index always and speed up the query for very large sites. Small sites should not notice any impact.

Summary

This PR can be summarized in the following changelog entry:

  • Improves performance in large sites with lots of inbound links by adding appropriate database indices.

Relevant technical choices:

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

  • Open your DB and check that the SEO_Links table does not have indexes for the url and target_indexable_id field.
  • Run the following queries and take note of the result:
    explain SELECT target_post_id FROM wp_yoast_seo_links WHERE url = '{an url from your tables content}';
    explain SELECT COUNT( id ) AS incoming, target_indexable_id FROM wp_yoast_seo_links WHERE target_indexable_id IN ('1', '2', '231755', '3') GROUP BY target_indexable_id;
  • Make sure they are not using a key.
  • Go to the yoast helper and click Reset Indexables tables & migrations
  • Make sure the indices are now there.
  • Run the queries again and make sure they use the new index now. Also make sure that they give the same results

Regression tests:

  • Find the indexable for a post and take a note of its incoming_link_count column
    • Find a different post and add a link to the first post and save
    • Find the initial indexable again and check that the incoming_link_count column has now been incremented by one
  • Create a post and add an image in the post content and dont add a feature image and publish it
    • Go to the frontend and confirm that the #primaryimage node in the schema is as expected.

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.
  • However, instead of going to the yoast helper and resetting the indexables from there, just upgrade the Yoast plugin with this current RC
    • Which means that you just have to check whether the query uses the new indexes

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.
  • This PR also affects Yoast SEO for Google Docs. I have added a changelog entry starting with [yoast-doc-extension], added test instructions for Yoast SEO for Google Docs and attached the Google Docs Add-on label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.
  • I have run grunt build:images and commited the results, if my PR introduces new images or SVGs.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #

…xable_id_index field.

This is done to speed up at least two queries where theses fields are used in a single where statement. This way the where can use the index always and speed up the query for very large sites. Small sites should not notice any impact.
@thijsoo thijsoo added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Jan 5, 2026
@coveralls
Copy link
Copy Markdown

coveralls commented Jan 5, 2026

Pull Request Test Coverage Report for Build 1adb8f28cc693bf02bd6a0493c78e9a21e223320

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 34 (0.0%) changed or added relevant lines in 1 file are covered.
  • 22 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.5%) to 52.804%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/config/migrations/20260105111111_AddSeoLinksIndex.php 0 34 0.0%
Files with Coverage Reduction New Missed Lines %
inc/options/class-wpseo-option-tracking-only.php 10 0.0%
src/schema/application/configuration/schema-configuration.php 12 0.0%
Totals Coverage Status
Change from base Build b02bddd11cd155f6703e6a5b838c9d434fa06b2f: -0.5%
Covered Lines: 32312
Relevant Lines: 61242

💛 - Coveralls

@leonidasmi leonidasmi requested a review from Copilot January 9, 2026 10:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds database indices to the SEO_Links table to optimize query performance on the url and target_indexable_id columns. This improvement targets large sites where these fields are frequently used in WHERE clauses, though small sites should see minimal impact.

  • Adds an index on the url column with name url_index
  • Adds an index on the target_indexable_id column with name target_indexable_id_index

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/config/migrations/20260105111111_AddSeoLinksIndex.php Outdated
Comment thread src/config/migrations/20260105111111_AddSeoLinksIndex.php
Copy link
Copy Markdown
Contributor

@leonidasmi leonidasmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: 🟠 minor feedback that shouldn't bring regressions if applied
Acceptance: ✅

@thijsoo If you agree with the feedback and you address it, I can do a quick smoke test again and merge

Comment thread src/config/migrations/20260105111111_AddSeoLinksIndex.php Outdated
Comment thread src/config/migrations/20260105111111_AddSeoLinksIndex.php
@leonidasmi leonidasmi added changelog: other Needs to be included in the 'Other' category in the changelog and removed changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog labels Jan 13, 2026
@thijsoo thijsoo assigned leonidasmi and unassigned thijsoo Jan 14, 2026
Copy link
Copy Markdown
Contributor

@leonidasmi leonidasmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR of latest changes is ✅

After another smoke test, I'm merging this.

@leonidasmi leonidasmi merged commit 40e7e13 into trunk Jan 14, 2026
26 checks passed
@leonidasmi leonidasmi deleted the try/add-indexes branch January 14, 2026 13:05
@leonidasmi leonidasmi added this to the 26.9 milestone Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: other Needs to be included in the 'Other' category in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants