2012-04-19 61 views
0

我有一个查询:使用Filesort和Query的MySQL非常慢?

SELECT listings.*, listingagents.agentid 
FROM listings 
LEFT JOIN listingagents ON (listingagents.id = listings.listingagentid) 
LEFT JOIN ignore ON (ignore.system_key = listings.listingid) 
WHERE ignore.id IS NULL 
ORDER BY listings.id ASC 

我试图改善查询的性能,因为它是非常缓慢的,它是把MySQL服务器上一个沉重的负担。

当我做了MySQL的解释,输出显示:

 
+--------+-------------+---------------+--------+---------------+------------+---------+----------------------------+--------+-------------------------+ 
|  id | select_type |  table  | type | possible_keys | key  | key_len |   ref    | rows |   Extra   | 
+--------+-------------+---------------+--------+---------------+------------+---------+----------------------------+--------+-------------------------+ 
|  1 | SIMPLE  | listings  | ALL | NULL   | NULL  | NULL | NULL      | 383360 | Using filesort   | 
|  1 | SIMPLE  | listingagents | eq_ref | PRIMARY  | PRIMARY | 4  | db.listings.listingagen... |  1 |       | 
|  1 | SIMPLE  | ignore  | ref | system_key | system_key | 1  | const      | 404 | Using where; Not exists | 
+--------+-------------+---------------+--------+---------------+------------+---------+----------------------------+--------+-------------------------+ 

我试图做一个简单的查询:

SELECT listings.* 
FROM listings 
ORDER BY listings.id ASC 

而且该查询也有 “使用文件排序;”。

“listing.id”,“listingagents.id”和“ignore.id”是主键 “listingagents.id”和“ignore.system_key”字段有索引。

我能做些什么来改善第一个查询?

+0

如果你对'select * from list order by id asc'做'desc'会发生什么? – ethrbunny 2012-04-19 17:00:46

回答

0

尝试通过添加一些条件来减少列表范围(目前为383360行)。例如id> x或限制。