Chinaunix

标题: 如何提高查询语句的效率 [打印本页]

作者: congfu    时间: 2015-03-18 16:53
标题: 如何提高查询语句的效率
select * from (
select a.*
  from v_zyjz a
where a.dfyxx09 >= &adt_start
   AND a.dfyxx09 < &adt_end
   and a.sjflb01 like 'BD01%'
  and  ( exists
    (select * from V_ZYYPMX b
   where  a.SZYBH01 = b.szybh01
   and a.SYZXH01 = b.SYZXH01
   and a.IFYXH01 = b.ifyxh01
   and (( b.LX in ('A','F','G','H') and ( b.dfysj01 <&adt_start  or b.dfysj01 >= &adt_end ) )
   or  b.LX in ('B','C','D','E')
    )))
or ( ( not exists
    (select * from V_ZYYPMX b
   where  a.SZYBH01 = b.szybh01
   and a.SYZXH01 = b.SYZXH01
   and a.IFYXH01 = b.ifyxh01 )
    or a.szxbz01 = '0' )
) )

如何提高这个查询语句的效率,特别是如何改写NOT EXISTS
作者: congfu    时间: 2015-03-18 16:54
V_ZYYPMX 的 基表的dfysj01字段已做好索引
作者: jackson198574    时间: 2015-03-20 10:05
需要看一下执行计划。
作者: congfu    时间: 2015-03-21 09:20
执行计划在下面
目前是想办法写成联合查询,不采用EXISTS。

QQ图片20150321091728.png (53.41 KB, 下载次数: 48)

执行计划一

执行计划一

QQ图片20150321091759.png (53.3 KB, 下载次数: 48)

执行计划二

执行计划二





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2