woothemes/woocommerce — pull request #4901 by sdrori (2014-02-22 00:12:44+00:00)
Title: Update to class-wc-admin-cpt-shop_order.php

There was a particular query I kept seeing in our slow query log, I tracked it down to the function shop_order_search_custom_fields() in includes/admin/post-types/class-wc-admin-cpt-shop_order.php. The function actually fires off 3 separate queries (it was the middle query that tries to match against billing & shipping first & last names that was particularly slow).

The attached improves that query (cutting the number of rows checked in half) and joins all three queries into a single SQL query eliminating two DB connections and allowing MySQL to filter the order#'s for uniqueness.