Improve SQL query performance in Indexable_Post_Indexation_Action#20215
Improve SQL query performance in Indexable_Post_Indexation_Action#20215av3nger wants to merge 1 commit intoYoast:trunkfrom av3nger:feature/improve-sql-query-performance
Conversation
|
@av3nger We have created internally a task to assess this and added it on our board. As per our processes, we will open a separate PR (that will link to this one) in order to tweak your solution and potentially merge that instead, but if we do we will give you props in our changelog. |
|
I've also added a fix regarding using the new order of placeholders because otherwise the resulting queries would get malformed :) |
|
@av3nger I have been investigating your PR and I'm actually not seeing any noticeable improvements when benchmarking both solutions 🤔 In most setups I actually see a tiny regression even, in terms of average time for the new query to complete, compared to the production one. This is my methodology for benchmarking the queries btw:
If you try the same methodology and get opposite results, I'd be interested to look further on any potential differences our setups might have. (you do have to apply this fix on your PR as well first though 🙂 ) |
|
@leonidasmi, what is the |
|
@av3nger I'm getting this for the original query: and that is on a website with ~48k posts. And when I compare it with this PR's query: I'm noticing that the original query is slightly more performant in that site too. And that can be explained by the |


Context
Improve performance of Yoast on wp-admin dashboard, when working with indexables, on sites with large number of posts.
Summary
The following query in
get_select_query()method in theIndexable_Post_Indexation_Actionclass can be improved:When running
EXPLAINon the query, the subquery goes over all the rows, which makes this significantly slower on larger data sets:If the query is changed to:
we can simplify the query and get rid of the scan across the whole table:
This PR can be summarized in the following changelog entry:
Test instructions for QA when the code is in the RC
Make sure that the output results from old and new queries match.
Impact check
This PR affects how unindexed posts are selected.
Quality assurance
Innovation
innovationlabel and noted the work hours.