MySQL Query Optimisation - JOIN?

前端 未结 4 1697
清酒与你
清酒与你 2021-01-24 06:20

One for all you MySQL experts :-)

I have the following query:

SELECT o.*, p.name, p.amount, p.quantity 
FROM orders o, products p 
WHERE o.id = p.order_i         


        
4条回答
  •  广开言路
    2021-01-24 06:54

    1. Use Explain to indicate how to optimise the query. I'd suggest starting with indices on Total and TimeStamp

    2. You may find removing the date function improves performance.

    3. You should use modern syntax.

    eg.

    SELECT o.*, p.name, p.amount, p.quantity  
    FROM orders o
         inner join products p  
         on o.id = p.order_id 
    WHERE o.total != '0.00' 
    AND o.timestamp BETWEEN '2012-01-01' AND '2012-01-31 23:59'  
    ORDER BY o.timestamp ASC 
    

提交回复
热议问题