select * from (select a,* from recordings a,(select recording_id from provisions where channel_name='cmcc') b where a.pid=b.recording_id ) as tb1 
,(select distinct pid from recordings where kit like '%aa%') b 
where a.pid=b.pid 
这条语句还有
select * from (select a.* from recordings a inner join provisions b 
on a.pid=b.recording_id 
where b.cannel_name=’cmcc’)) as tb1 
inner join recordings c on tb1.pid=c.pid 
where c.kit like ‘%aa%’ 
都比优化前
select * from (select * from recordings where pid in (select recording_id from provisions where channel_name=’cmcc’)) as tb1 where pid in (select pid from recordings where kit like ‘%aa%’)
用时更长,这是什么原因呢

解决方案 »

  1.   

    在什么字段上建立的索引?如果都没有索引,内连接速度>IN
      

  2.   

    recording_id,channel_name,pid,kit都建有索引,优化后按说速度应该会减少,但是实际情况却不是这样,很奇怪
      

  3.   

    select * from (select a,* from recordings a,(select recording_id from provisions where channel_name='cmcc') b where a.pid=b.recording_id ) as tb1 
    ,(select distinct pid from recordings where kit like '%aa%') b 
    where a.pid=b.pid 上面这条SQL找不到字段aselect * from (select a.* from recordings a inner join provisions b 
    on a.pid=b.recording_id 
    where b.cannel_name=’cmcc’)) as tb1 
    inner join recordings c on tb1.pid=c.pid 
    where c.kit like ‘%aa%’ 这条又括号不匹配。所以没什么可比的,永远跑不出记录集。建议楼主能贴个实际的例子,否则没办法帮你分析。提问反而变成考试大家的语法。