Automattic / Automattic/zoninator
Slow queries generated by Zoninator
- Dominant language
- PHP
- Stars
- 86
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
We have seen slow queries being generated by Zoninator, in particular a query that looks like this:
```
SELECT wp_posts.ID FROM wp_posts WHERE ?=? AND ( wp_posts.post_date > ?) AND wp_posts.ID NOT IN (?, ?, ?, ?, ?, ?, ?, ?) AND (((wp_posts.post_title LIKE ?) OR (wp_posts.post_excerpt LIKE ?) OR (wp_posts.post_content LIKE ?))) AND wp_posts.post_type = ? AND ((wp_posts.post_status = ? OR wp_posts.post_status = ?)) ORDER BY wp_posts.post_date DESC LIMIT ?, ?
```
It is in particular the `NOT IN` part that causes issues, as when data grows in `wp_posts`, there is more to exclude when processing the query. This can lead the database to overload, causing sites to have performance issues.
Is there any way to rewrite this without the `NOT IN`?
***
This issue originated as a VIP Request.
Contributor guide
Research direction
The issue names no source files, tests, or entry points; start by locating the Zoninator code that generates the shown wp_posts query and reproduce it with representative data. Done means an equivalent query no longer relies on the problematic NOT IN exclusion and the database performance impact is measured on growing data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, sql
- Domain
- backend, databases, performance
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100