WordPress / WordPress-Coding-Standards

PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions
MIT License
2.55k stars 485 forks source link

Improving the meta_query sniff #1871

Open rmccue opened 4 years ago

rmccue commented 4 years ago

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

jrfnl commented 4 years ago

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

rmccue commented 4 years ago

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

jrfnl commented 4 years ago

@rmccue Excellent! I look forward to your PR.

jrfnl commented 4 years ago

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 commented 4 years ago

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

rmccue commented 4 years ago

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

jrfnl commented 4 years ago

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

lukecarbis commented 2 years ago

Any update? @rmccue