有一 t_mer_info表,其中某列 bms_apply_type 为0、1和空单表查询时速度很快
select * from t_mer_info tmi where  tmi.bms_apply_type = '0' and tmi.profit_status ='5'但是当多表联合查询时 如果加上 bms_apply_type的约束条件,查询速度变得极其慢,去掉bms_apply_type 的约束条件 查询速度又很快。select t.mer_no,
       t.mer_name,
       t.mer_address,
       t.mer_contactor,
       t.mer_mobile,
       t.mer_tel,
       t.mer_email,
       t.mer_source,
       t.profit_status,
       t.bms_apply_type,
       t.bms_mer_no,
       hx.inst_no,
       hx.supinstno,
       hx.inst_name,
       to_char(mp.CREATE_TIME, 'yyyy-MM-dd HH24:mi:ss') as create_time,
       pa.ACCOUNT_NO,
       pa.ACCOUNT_NAME
  from t_mer_info t
 inner join account.t_inst hx
    on t.org_no = hx.inst_no
 inner join t_mer_profitact mp
    on t.id = mp.mer_id
 inner join T_PROFIT_ACCOUNT pa
    on mp.id = pa.PROFITACT_ID
 where  pa.DEFAULT_ACCOUNT = '1'
   and t.bms_apply_type = '0'
   and t.profit_status ='5'
请问各位大大 要怎么解决这个问题? 因为业务的需要,bms_apply_type 也必须要加上

解决方案 »

  1.   

    在bms_apply_type 列上加上索引
      

  2.   


    这一列 的数据  有的为空
    不影响你建索引但是当我查询 为空的数据时 就有影响吧我查了下 oracle 空值与空值不等的
      

  3.   

    空值比较是用is null 和 is not null,这不影响建索引,只是可能查询null的时候不走索引而已
      

  4.   

    你这是访问远程数据库的表啊? 用dblink会有影响的
      

  5.   


    是的各个环境用的数据库不同修改功能时发现这个sql 效率特表慢  然后想优化下,但测试好多方法 还是不行
      

  6.   

    用dblink就是这点不好,我之前也遇到过这种情况,也没有什么好的办法解决
    看其他大神有没有好的方法