Skip to content

Improving the meta_query sniff #1871

@rmccue

Description

@rmccue

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Focus: Code analysisSniffs to prevent common mistakes and improve code in general

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions