WordPress-Coding-Standards icon indicating copy to clipboard operation
WordPress-Coding-Standards copied to clipboard

Improving the meta_query sniff

Open rmccue opened this issue 5 years ago • 8 comments

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

rmccue avatar Mar 04 '20 14:03 rmccue

@rmccue I, for one, would definitely be interested in that. Please let me know if you want interim feedback while working on this from a sniff writing perspective or if we can help in any other way.

jrfnl avatar Mar 10 '20 18:03 jrfnl

👍 I've actually already written it: https://github.com/humanmade/coding-standards/blob/add-required-standard/HM/Sniffs/Performance/SlowMetaQuerySniff.php :)

I'll work on getting it ready for contribution back to WPCS.

rmccue avatar Mar 11 '20 10:03 rmccue

@rmccue Excellent! I look forward to your PR.

jrfnl avatar Mar 11 '20 11:03 jrfnl

Issues #471 and #661 look to be related. @rmccue Would you mind having a look to see if your improvements cover the issues described in those tickets ?

jrfnl avatar Mar 14 '20 05:03 jrfnl

@rmccue Just checking in to see how you're getting on with this... ?

jrfnl avatar Apr 01 '20 16:04 jrfnl

My apologies, I've been dealing with some unrelated world events 😬 Hoping to get back to this ASAP!

rmccue avatar Apr 01 '20 16:04 rmccue

@rmccue No worries and no rush. Just wanted to check in with you.

jrfnl avatar Apr 01 '20 16:04 jrfnl

Any update? @rmccue

lukecarbis avatar Jan 31 '22 03:01 lukecarbis