[Task]: for very large sites, XML sitemap index build results in `lastmod` query sort inside a temp table, every time the index is built
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 42/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- mariadb, mysql, php
- Domain
- backend, databases, performance
Research direction
Start in inc/sitemaps/class-post-type-sitemap-provider.php around lines 722-738 and inspect the shown sitemap index query and its USE INDEX hint. Compare the available approaches for avoiding the repeated full sort, then confirm that the chosen behavior reduces large-site build cost while preserving the intended lastmod results or clearly documenting the trade-off.
Written by the indexing model from the issue text.
Description
Context - Why was this issue created?
Every time the sitemap index is built, the post type sitemap provider runs one query per post type to find the lastmod date for each sitemap page.
That query numbers every published post of the type with ROW_NUMBER() OVER (ORDER BY post_modified_gmt), and a USE INDEX ( type_status_date ) hint stops MySQL from using an index ordered by post_modified_gmt.
So MySQL sorts the whole post set in an internal temporary table on every build. On a site with about 500k+ published posts, this one query causes about 500k+ temporary-table row updates each time the index is built.
The query doesn't modify any data, but its cost grows linearly with post count and is paid every time the index is built. We stumbled across this issue because the query ends up looking like a write storm in our database monitoring systems.
This is the query in question:
WITH `ordering` AS (
SELECT ROW_NUMBER() OVER (ORDER BY `post_modified_gmt`) AS n, post_modified_gmt
FROM `wp_posts` USE INDEX ( `type_status_date` )
WHERE `post_status` IN ('publish') AND `post_type` = 'post'
ORDER BY `post_modified_gmt`
)
SELECT `post_modified_gmt` FROM `ordering` WHERE MOD(n, 4000) = 0
The site this runs on modified sitemap links per sitemap to 4000.
It comes from the post type sitemap provider's index-link code, here. Older versions used the same approach with @rownum user variables.
Why it's expensive
- Every published post is materialized and sorted just to pick out every 4,000th date. At 4,000 per page, 500k+ posts produces 125 boundary dates.
USE INDEX ( type_status_date )blocks the fix a site owner would try. That index can't providepost_modified_gmtorder. The hint also keeps the optimizer from using a site-added index such as(post_type, post_status, post_modified_gmt), which could otherwise give an ordered index scan.- The sitemap transient cache doesn't help here.
wpseo_enable_xml_sitemap_transient_cachingdefaults to false, and even when enabled it doesn't make the index-building query itself cheaper.
What is the goal of this issue?
The goal of this issue is to ask for the team to consider making the changes detailed below, so that sitemap generation runs more efficiently on especially large sites.
What needs to be done to achieve the goal?
Any one of these would help, and they don't depend on each other:
- Reconsider the
USE INDEXhint for this query. Without it, a site can add an index that serves thepost_modified_gmtordering, so the query doesn't have to sort in a temporary table. - Add a filter to skip or simplify per-page lastmod in the index. For example, fall back to the post type's overall latest modified date for every page. Large sites may prefer a cheaper, less precise lastmod over a full sort on every build.
- Cache the page-boundary dates between index builds. They only change as posts are published or modified, which could invalidate the cache the same way the existing sitemap cache is invalidated.
Does the issue still need UX or research?
No
If available, what are the tips for fixing the problem or possible solutions?
See above.
What is the expected result/behavior?
Without USE INDEX hint, MySQL/MariaDB is able to get the boundary dates dramatically sooner (in our case, we've added a wp_posts index on post_modified_gmt, which is why this is the case).
Should documentation be added or updated for this change? And if so, where?
No response
- Dominant language
- JavaScript
- Stars
- 2k
- Forks
- 988
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 66
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Yoast/wordpress-seo
-
[Feature]: Add Crawl Optimization setting to disable WordPress random content redirect (WP 7.2)Openenhancement featurerequest
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Yoast/wordpress-seo#23888 ·
Maintainers usually reply within 4 days
-
[Bug]: languages/pl.js breaks SEO Optimization Tool when object property name appears in analyzed textPossibly taken @MrDezzan claimed this 9 days ago. Openbug Can't reproduce needs-more-info
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Yoast/wordpress-seo#23840 · 1 comment ·
Maintainers usually reply within 4 days
-
[Bug]: PHP 8.6: bundled guzzlehttp/promises loads class `Is` → "Using "is" as a class name is deprecated"Possibly taken @nadeem-khan claimed this 31 days ago. Openbug patch welcome php 8.6
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
Yoast/wordpress-seo#23747 · 2 comments ·
Maintainers usually reply within 4 days
-
bulk editor access check calls current_user_can( edit_post ) without object ID, triggers PHP warnings in BuddyBoss/bbPressPossibly taken @alizamani1616 claimed this 60 days ago. Openbug component: bulk editor support
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Yoast/wordpress-seo#23669 ·
Maintainers usually reply within 4 days
-
Sitemap pagination silently drops pages when `post_modified` is not unique (`ORDER BY post_modified ASC` + OFFSET)Possibly taken @faisalahammad claimed this 49 days ago. Opencomponent: xml sitemap has patch
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Yoast/wordpress-seo#23658 · 3 comments ·
Maintainers usually reply within 4 days
All issues in Yoast/wordpress-seo
Similar issues
-
check:passed feeds:remove
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
githubnext/gh-aw-workshop#6428 ·
Maintainers usually reply within 1 day
-
docs
Difficulty 2/5 1-3 hours Newbie friendliness 61/100
idean3885/claude-ops-agent#1346 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
linagora/twake-drive#4681 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Autokey cipher decode corrupts text that contains lowercase lettersPossibly taken @hakarrr claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 79/100