如何提高mysql连接查询速度?

时间:2022-06-01 21:58:07

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

该查询耗费近60秒加载,任何机构都知道如何优化此查询

2 个解决方案

#1


2  

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:

您可能还想使用ANALYZE语句来优化从这些表中检索数据,您可以从此站点阅读有关此语句的更多信息:

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

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

#2


1  

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.

正确设置索引(您可能做了哪些?)或创建视图。你也可以考虑临时表,但大多数时候同步使它不值得。

#1


2  

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:

您可能还想使用ANALYZE语句来优化从这些表中检索数据,您可以从此站点阅读有关此语句的更多信息:

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

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

#2


1  

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.

正确设置索引(您可能做了哪些?)或创建视图。你也可以考虑临时表,但大多数时候同步使它不值得。