MySQL LEFT JOIN很慢,占用27.82秒

时间:2015-01-08 08:07:11

标签: mysql sql left-join

这是我的MySQL查询,执行时间为27秒。

SELECT company_info.industry
     , company_info.name
     , company_aliases.name 
FROM searcher_db.company_info 
LEFT OUTER JOIN searcher_db.company_aliases ON company_info.id = company_aliases.id;

company_aliases有1883条记录,company_info有71179条记录,图像上显示索引。

enter image description here enter image description here

请有人帮我这个吗?为什么要花费这么多时间以及如何改进查询?

1 个答案:

答案 0 :(得分:1)

在company_info.id和company_aliases.id上添加索引,别名

CREATE INDEX index_name
ON table_name (column_name)

然后,不是设置PRIMARY KEY(name),而是在table.id上设置它。在后台MySQL将文本转换为ASCII然后处理它因此需要时间,所以避免这样做。搜索和其他操作在Number上更快,而不是字符串。看看是否有帮助。

相关问题