Speed up ‘Order history’ query by 50%-75%
0I noticed that following query takes long time to execute:
FROM orders o, orders_products op, products p
WHERE o.customers_id = ’2345′
AND o.orders_id = op.orders_id
AND op.products_id = p.products_id
AND p.products_status = ’1′
GROUP BY products_id
ORDER BY o.date_purchased DESC
LIMIT 6
I noticed that there’s no index on orders table on customers_id field. Without it MySQL has to scan whole table to find orders by customers_id (in this case ’2345′). If orders table is small there’s no problem, but when it has 10 000 or more entries it can noticably slow down Zen Cart. So, let’s add index on that table
I included date_purchased in index, because some pages in admin area will use it for searching all orders of given customer.
In my case it decreased query time from 0.3 sec to 0.08 sec. It’s still too much, but it’s better then nothing.
