select  a.uid,a.seat seat,a.id as bid,a.cid,b.customer,b.type,b.initTime,b.duration,b.record,b.ilk, 
b.missedStatus,f.desc,a.acceptTime as a_acceptTime,a.bizQuality as 
a_bizQuality,c.name as c_name,a.salesType as a_salesType,a.bizType as 
a_bizType,a.acceptNote as a_acceptNote,c.sex as c_sex,c.customerType as 
c_customerType,c.customerSource as c_customerSource,c.type as 
c_type,c.callArea as c_callArea,c.zipcode as c_zipcode,c.email as 
c_email,c.company as c_company,c.seat as c_seat,c.createTime as 
c_createTime,c.note as c_note,c.property1 as c_property1,c.property3 as 
c_property3,c.property2 as c_property2 from (select * from  
phone_accept_log201307 where uid=2557  and acceptTime between 1372608000 and 
1373990399 ) as a  left join phone_log201307 as b on a.id = b.id  left join 
new_vcccallcenter.customer_info as c on a.cid=c.id  left join grade_log e on 
a.id = e.id left  join desc_code_grade f on e.grade=f.code  where c.id>0  and 
c.seat='21203377'   order by acceptTime desc  limit 740,20;索引:
  PRIMARY KEY  (`id`),
  KEY `cid_uid_atime` (`cid`,`uid`,`acceptTime`),
  KEY `id` USING BTREE (`id`)explain:
+----+-------------+------------------------+--------+---------------+---------+---------+--------------------+------+---------------------+
| id | select_type | table                  | type   | possible_keys | key     | key_len | ref                | rows | Extra               |
+----+-------------+------------------------+--------+---------------+---------+---------+--------------------+------+---------------------+
|  1 | PRIMARY     | <derived2>             | system | NULL          | NULL    | NULL    | NULL               |    0 | const row not found |
|  1 | PRIMARY     | e                      | eq_ref | PRIMARY       | PRIMARY | 98      | const              |    1 |                     |
|  1 | PRIMARY     | f                      | eq_ref | PRIMARY       | PRIMARY | 4       | new_vcclog.e.grade |    1 |                     |
|  1 | PRIMARY     | b                      | eq_ref | PRIMARY       | PRIMARY | 98      | const              |    1 |                     |
|  1 | PRIMARY     | c                      | eq_ref | PRIMARY       | PRIMARY | 8       | const              |    1 | Using where         |
|  2 | DERIVED     | phone_accept_log201307 | ALL    | NULL          | NULL    | NULL    | NULL               |    4 | Using where         |
+----+-------------+------------------------+--------+---------------+---------+---------+--------------------+------+---------------------+*查询很慢 2秒多 10W条数据 而且翻页的时候 越后面越慢 

解决方案 »

  1.   

    order by acceptTime desc  limit 740,20; 
    有order by 和limit速度就很慢 请问下 这怎么优化
      

  2.   

    如果acceptTime 和主键同增长的  那用order by id desc替换
      

  3.   

    1. c.id > 0 移到a表条件中
    2.SELECT * 改为所查询需要的字段
    3.
    LEFT JOIN phone_log201307 AS b ON a.id = b.id
    LEFT JOIN new_vcccallcenter.customer_info AS c ON a.cid = c.id
    LEFT JOIN grade_log e ON a.id = e.id
    LEFT JOIN desc_code_grade f ON e.grade = f. CODE
    关联的都建索引  (外加acceptTime、seat)