首先要创建这个视图:create or replace view v_mapping as
select  b.code as code,a."AGENT_CODE",a.no,a."IS_POp"
from (
select
mod(b.NO1,1000000) as agent_code,
 'Y' as IS_POp
from basic_info b,status s where  b.no = s.no  and s.pol_sts = 'A' and b.NO1 is not null
union all
select
mod(b.NO2,1000000) as agent_code,
'Y' as IS_POp
from basic_info b,status s where  b.no = s.no  and s.pol_sts = 'A' and b.NO2 is not nulland mod(b.NO2,1000000)<>mod(b.NO1,1000000)
union all
select
mod(b.NO,1000000) as agent_code,
'Y' as is_pol
from basic_info b,status s where  b.no = s.no  and s.pol_sts = 'A' and b.NO is not null
and mod(b.NO,1000000)<>mod(b.NO1,1000000) and mod(b.NO,1000000)<>mod(b.NO2,1000000)
union all
select
mod(d.NO,1000000) as agent_code,
'N' as is_pol
from life_info d, life_sts l where  d.sts_code = l.code and not exists (select 1 from basic_info a where d.no = a.no)
union all
select
mod(d.NO1,1000000) as agent_code,
'N' as is_pol
from life_info d, life_sts l where  d.sts_code = l.code and d.NO1 is not null
and (mod(d.NO2,1000000)<>mod(d.NO1,1000000)
and not exists (select 1 from basic_info a where d.no = a.no)
) a, mapping b, agent_info where a.no = b.no and to_char(a.agent_code) = b.agent_code and c.agent_code = b.agent_code问题如下:1.basic_info 信息表里面有三个agent字段---no1,no,no2要取出来no1,no,no2不一样的时候的信息,且在视图中要合成一个字段agent_code.
2.life_info 和上面的相似,有两个字段.
3.索引已经建立,所有的表里面均有数据100万左右
4.请高手出招!!!

解决方案 »

  1.   

    每个union all 分拆测试,看看都用到索引没
      

  2.   

    1、继续SQL优化,检查在那个语句上的逻辑读快多,进行优化。
    2、参数调优:另外,就是检查IO 多块读数参数的配置,db_file_mutiblock_read_count
      

  3.   

    建议如下,
    1.basic_info 信息表里面有三个agent字段---no1,no,no2要取出来no1,no,no2不一样的时候的信息,且在视图中要合成一个字段agent_code. 
    ---------------------
    select case m.i when 1 then mod(b.NO1,1000000) when 2 then mod(b.NO2,1000000) when 3 then mod(b.NO,1000000) as agent_code,'Y' as IS_POp 
    from basic_info b,status s, (select 1 as i union all select 2 union all select 3) m 
    where b.no = s.no and s.pol_sts = 'A' and ((b.NO1 is not null and m.i = 1)
    or (b.NO2 is not null and mod(b.NO2,1000000) <>mod(b.NO1,1000000) and m.i = 2)
    or (b.NO is not null and mod(b.NO,1000000) <>mod(b.NO1,1000000) and mod(b.NO,1000000) <>mod(b.NO2,1000000) and m.i = 3))2.life_info 和上面的相似,有两个字段. 
    ---------------------
    参照上例重写。
      

  4.   

    还是老话,分段测试,继续对各分段的SQL进行分析!