简体   繁体   中英

How can i improve mysql join query speed?

I have two tables lets say employees and order, both table have millions of records.

Select orders.* 
from orders
   INNER JOIN employees 
     on Employees.id = orders.employeeid
WHERE orders.type='daily' 
  and orders.date > Employees.registerDate 
  and orders.date < Employees.regiserDate + Interval 60 Days

The above query is rough query, there may be syntax error, but is just considerations.

The query consuming almost 60 seconds to load, any body know how can i optimize this query

The indexing is one of the best options mentioned, you could also use stored procedure to optimize its performance on retrieving data.

you may would also like to use the ANALYZE statement to optimize the retrieval of data from those tables you may read more about this statement from this site:

http://dev.mysql.com/doc/refman/5.0/en/analyze-table.html

Set your indexes right (which you probably did?) or create views. You could also consider a temp table, but most of the time the sync makes it not worth it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM