非常慢的性能处理40M +记录MySQL表

时间:2016-04-09 05:59:40

标签: mysql database performance

我在MySQL数据库上处理超过40M的记录。方案如下:

鉴于2个具有相同结构的表包含超过40M的价格信息记录:

表1

product_id  price    date
101         5.7      2016/1/1
102         11.6     2016/1/1
104         8        2016/1/1
…           …         …

表2

product_id  price    date
101         5.9      2016/1/2
103         20.3     2016/1/2
104         8        2016/1/2
…           …         …

我希望了解两个表格中存在多少product_id,并且我使用以下查询进行搜索:

SELECT count(*) FROM t1 a,t2 b where a.product_id=b.product_id ;

SELECT count(*) FROM t1 a,t2 b on a.product_id=b.product_id ;

获得结果需要半个多小时,有没有办法改善性能?

1 个答案:

答案 0 :(得分:2)

最好的办法是在<% if @profile_info.present? %> <%= @profile_info.region.try(:name) %> <% else %> <%= @user.try(:email)%> <% end %> 上创建一个索引。

要做到这一点,请阅读create index,即

product_id