How to force oracle to use index range scan?

前端 未结 5 1604
执笔经年
执笔经年 2021-02-04 08:10

I have a series of extremely similar queries that I run against a table of 1.4 billion records (with indexes), the only problem is that at least 10% of those queries take > 100x

5条回答
  •  攒了一身酷
    2021-02-04 08:43

    If you want to know why the optimizer takes the decisions it does you need to use the 10053 trace.

    SQL> alter session set events '10053 trace name context forever, level 1';
    

    Then run explain plans for a sample fast query and a sample slow query. In the user dump directory you will get trace files detailing the decision trees which the CBO goes through. Somewhere in those files you will find the reasons why it chooses a full index scan over an index range scan.

    I'm not saying the trace files are an easy read. The best resource for understanding them is Wolfgang Breitling's excellent whitepaper "A look under the hood of CBO" (PDF)

提交回复
热议问题