Improving the meta_query sniff
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 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.
👍 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 Excellent! I look forward to your PR.
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 ?
@rmccue Just checking in to see how you're getting on with this... ?
My apologies, I've been dealing with some unrelated world events 😬 Hoping to get back to this ASAP!
@rmccue No worries and no rush. Just wanted to check in with you.
Any update? @rmccue