Open Jinksi opened 2 years ago
@Jinksi can you open an issue for this on WCPay and WC Subscriptions so we can track and prioritise against products?
One of our merchants reported this as well 7126887-zen
Merchant reported both queries here could be limited to shop_subscription
post_type:
Example:
SELECT DISTINCT p1.post_id
FROM wp_postmeta p1
JOIN wp_posts posts ON posts.ID = p1.post_id
WHERE p1.meta_value LIKE '%standard%'
AND p1.meta_key IN ('_billing_email')
AND posts.post_type = 'shop_subscription'
The root performance problem is, of course, the unanchored meta_value LIKE '%searchterm%'
SQL predicate. It can't exploit an index, and it searches the meta_value
CLOB, so it is necessarily slow -- forcing the DBMS to scan many rows -- when there are lots of subscriptions. Switching to an anchored meta_value LIKE 'searchterm%'
search without the leading %
wildcard greatly improves performance at the cost of the ability to search for as many substrings.
Describe the bug
The Subscriptions search in wp-admin → WooCommerce → Subscriptions is very slow for merchants who have a large number of subscriptions. For example, searching through ~30,000 subscriptions can take as much as 30 seconds.
To Reproduce
WCS_Subscription_Data_Store_CPT::search_subscriptions()
.Expected behavior
The search query that is called by
WCS_Subscription_Data_Store_CPT::search_subscriptions()
should take as little time as is reasonably possible.Actual behavior
The search query that is called by
WCS_Subscription_Data_Store_CPT::search_subscriptions()
takes longer than is reasonably possible.Product impact
Additional context
More info provided by @foliovision in PR #182: