MySQL Query Optimisation - JOIN?

前端 未结 4 1698
清酒与你
清酒与你 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:46

    I'm not MySQL expert (more SQL Server) by I think you'd better have index on o.timestamp and you need to rewrite your query like this

    o.timestamp >= '2012-01-01' and o.timestamp <= '2012-01-31' + INTERVAL 1 DAY
    

    The logic is - index will not work if you compare some expression on column and constants. You need to compare column and constants

提交回复
热议问题