Searching for orders that do not exist takes several minutes to finally show 0 results in admin backend
-
07-10-2020 - |
Question
We're running Magento 2.1.5 CE, and I have a very specific speed issue with the Admin Backend. My frontend responds very quickly, and MOST of the admin backend is very fast as well, but with one exception: If I search in Orders for something that cannot be found, the search takes several minutes to complete and show me that there are no matches. If I search for something that can be found, the results appear in just a second or 2.
I've made a video that shows exactly what I'm talking about, which can be viewed here: Video Demonstrating The Problem.
Can anyone offer some help for how to speed this up?
Solution
On my installation it works pretty fast although I do not have many orders yet. But the query in the db I see in my code looks like this
SELECT `main_table`.* FROM `sales_order_grid` AS `main_table` WHERE (MATCH(`main_table`.increment_id,`main_table`.billing_name,`main_table`.shipping_name,`main_table`.shipping_address,`main_table`.billing_address,`main_table`.customer_name,`main_table`.customer_email) AGAINST('fdsfdsfsdsdfsdfsddsfsdfd')) ORDER BY created_at DESC LIMIT 20
You can try to execute it directly in your database. If it takes a long time you know the problem is with the query and your database structure. In that case do
EXPLAIN SELECT `main_table`.* FROM `sales_order_grid` AS `main_table` WHERE (MATCH(`main_table`.increment_id,`main_table`.billing_name,`main_table`.shipping_name,`main_table`.shipping_address,`main_table`.billing_address,`main_table`.customer_name,`main_table`.customer_email) AGAINST('fdsfdsfsdsdfsdfsddsfsdfd')) ORDER BY created_at DESC LIMIT 20
And see what information you get.
But this might not be exactly your case. It looks like you have some adjustment in the grid which adds table of ordered products. The question is how they are added there. If the module you use for that is hooking into grid generation it may join this query with products table and this join may cause some problems. You can easily test this by disabling the module responsible for that functionality. If this is your bottleneck ask the developer to optimize it.