Description
Upon upgrading our site to 2.3, we saw a sudden increase in database CPU load. By looking at the processlist we saw a frequent query that took a lot of time:
SELECT DISTINCT COUNT(*) FROM
search_queryAS
main_table WHERE (main_table.store_id = 1) AND (num_results > 0)
We found that this is part of the 2.3.0 update where they added Popular Search Term Cache (This pull request) The larger the search_query table is, the longer the query takes to complete.
Preconditions (*)
- Magento Commerce 2.3.4
- ElasticSearch 6.7.0
Steps to reproduce (*)
- Make a query in the main search bar.
Expected result (*)
- The query is expected to finish within a reasonable amount of time.
Actual result (*)
- The query takes a long time to finish, depending on the size of the search_query table.
On our live site we have about 2,7 million search terms, so when doing queries this puts a lot of strain on the database and the queries are very slow. The main part that takes time is the num_results > 0 part - when we tested without this in our local testing environment we got a query duration of 0,7 sec., while if we included it it takes approx. 23 sec.