這裏是SQL查詢:慢左連接問題用mysql
select * from company1
left join company2 on company2.model
LIKE CONCAT(company1.model,'%')
where company1.manufacturer = company2.manufacturer
公司1包含2000行,而Company2的包含9000行。
該查詢大約需要25秒才能完成。
我有company1.model和company2.model編入索引。
任何想法如何加快這一點?謝謝!
+----+-------------+-----------+------+---------------+------+---------+------+------+--------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------+------+---------------+------+---------+------+------+--------------------------------+
| 1 | SIMPLE | company1 | ALL | NULL | NULL | NULL | NULL | 2853 | |
| 1 | SIMPLE | company2 | ALL | NULL | NULL | NULL | NULL | 8986 | Using where; Using join buffer |
+----+-------------+-------+---+------+---------------+------+---------+------+------+--------------------------------+
您可以發佈EXPLAIN的結果呢?可能做一個沒有索引的搜索。 – AllInOne
更新了原帖! –