调整Oracle查询

时间:2018-04-19 12:59:45

标签: sql oracle query-performance

我需要提高此查询的效果:

 select t.*
        ,(select max(1)
          from schema1.table_a t1
          where  1=1
                    to_date(t.misdate, 'YYYYMMDD') between t1.startdateref and t1.enddateref
                     and sysdate between t1.startdatevalue and t1.enddatevalue
                     and t1.idpma = t.idpm)
     from schema2.table_b t

任何想法? 感谢

1 个答案:

答案 0 :(得分:1)

嗯,你table_b没有任何过滤条件。这意味着最佳计划包括table_b上的全表扫描。这将是最佳的。

话虽如此,现在你需要关注table_a。应使用索引范围扫描访问该文件:

  • idpma,然后是startdateref
  • idpma,然后按startdateref

是的,它是一个或另一个。对于Oracle基于成本的优化程序(CBO)选择最佳计划,您需要添加以下索引:

create index ix1 on schema1.table_a (idpma, startdateref);

create index ix2 on schema1.table_a (idpma, startdatevalue);

尝试使用这些,看看它是如何工作的。

相关问题