sql优化 两个表连接 怎么优化?

select a.id, a.wlbm, a.wlpm, a.jb, b.gysmc, b.mdm, b.ly
from gwdc_wgzx_wldwz a,
(select t.gysmc, t.mdm, t.ly, t.wlz || '%' as wlzwhere
from gwdc_wgzx_query t
where t.wlz is not null
and t.wlbm is null
and t.ly != '市场准入'
and nvl(t.qyxq, 0) <= '20121017'
and nvl(t.zyxq, 0) >= '20121017') b
where a.wlpm like b.wlzwhere

1、is null / is not null 在有些情况即使建索引 也是不能走索引的 可以通过一些技术解决这个

1) 不保存null 2)建伪符合索引 如(wlz, '0')

2、 t.ly != '市场准入' 也是不走索引的

3、只能靠如下:
and nvl(t.qyxq, 0) <= '20121017'
and nvl(t.zyxq, 0) >= '20121017'
但是你在需要处理的列上使用了函数 如果没有函数索引也是不走索引的。

可以考虑直接(此处建议存数字 而不是字符串) 不用考虑null(走索引时 默认null是不建索引的)
t.qyxq <='20121017'
and t.zyxq>= '20121017'

把 select t.gysmc, t.mdm, t.ly, t.wlz || '%' as wlzwhere
from gwdc_wgzx_query t
where t.wlz is not null
and t.wlbm is null
and t.ly != '市场准入'
and nvl(t.qyxq, 0) <= '20121017'
and nvl(t.zyxq, 0) >= '20121017')
独立一个查询视图 针对对这个sql优化 where部分优化
where t.ly <> '市场准入' t.wlz is not null and t.wlbm is null
and nvl(t.qyxq, 0) <= '20121017'
and nvl(t.zyxq, 0) >= '20121017'
and t.wlz is not null
and t.wlbm is null

完全是表设计问题... 出啥主意都白搭.. 关联用like..