WordPress / WordPress/WordPress-Coding-Standards

Improving the meta_query sniff

Open
#1,871 8 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Focus: Code analysis
Dominant language
PHP
Stars
2.8k
Forks
521
Avg merge
5d 20h
Merged PRs (30d)
1

Description

Currently, meta_query is flagged by WordPress.DB.SlowDBQuery as being a "possible slow query".

The reality of this is more complex, as the slow part of meta queries really only kicks in when querying by the (unindexed) value column. That means that some meta queries are not slow queries, and we can detect those.

Specifically, using EXISTS or NOT EXISTS as the comparison function only hits the key column, and hence has good performance. (We often recommend developers move unique IDs into key names and query by this to improve performance; .com VIP similarly notes the issue is with meta_value rather than meta generally.)

I'm working on a replacement for SlowDBQuerySniff which checks the query more in-depth; would this be of interest to PR back to WPCS?

(I'm also looking at the same for tax_query as not all taxonomy queries are expensive.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the WordPress.DB.SlowDBQuery sniff and review the issue's distinction between meta_value queries and EXISTS or NOT EXISTS comparisons. Confirm the intended scope with maintainers before coding, including whether tax_query is included. Done should mean an agreed deeper analysis with tests covering the query cases described.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.