oracle查询执行计划想要转换为提示

时间:2013-09-03 08:49:32

标签: oracle sql-execution-plan

我想将以下计划转换为提示。我可以这样做。

enter image description here

这是一个需要更长时间的查询,请为我们提供相同的解决方案

SELECT AIA.INVOICE_ID,
           AIA.INVOICE_NUM,
           AIA.INVOICE_TYPE_LOOKUP_CODE,
           AIA.BATCH_ID,
           AIA.LAST_UPDATED_BY,
           AIA.INVOICE_DATE,
           AIA.ORG_ID,
           AIA.VENDOR_ID,
           AIA.INVOICE_CURRENCY_CODE,
           AIA.SET_OF_BOOKS_ID,
           AIA.VENDOR_SITE_ID,
           AIA.INVOICE_AMOUNT,
           AIA.BASE_AMOUNT
      FROM AP_INVOICES_ALL AIA
     WHERE  AIA.INVOICE_AMOUNT = 0

         AND   AIA.SET_OF_BOOKS_ID = 1

         AND AIA.CANCELLED_DATE  is null 
         AND EXISTS
     (SELECT  1          
              FROM AP_INVOICE_DISTRIBUTIONS_ALL AIDA,
                   GL_CODE_COMBINATIONS         GCC,
                   FND_LOOKUP_VALUES_VL  FLVC

             WHERE AIDA.INVOICE_id=AIA.INVOICE_id

               AND AIDA.ACCOUNTING_DATE BETWEEN '01-apr-2006' AND
                   sysdate
               AND GCC.CODE_COMBINATION_ID= AIDA.DIST_CODE_COMBINATION_ID  
               AND  FLVC.LOOKUP_CODE=GCC.SEGMENT7
               AND  FLVC.LOOKUP_TYPE = 'NATURAL_ACCT_SERVICE_TAX'
              AND  FLVC.DESCRIPTION IN
                         ('Service Tax', 'Secondary High Edu',
                       'Education Cess'));

这是计划

SELECT STATEMENT, GOAL = ALL_ROWS           Cost=43 Cardinality=1   Bytes=83    
 FILTER                     Parent id=0
  TABLE ACCESS BY INDEX ROWID   Object owner=AP Object name=AP_INVOICES_ALL Cost=31 Cardinality=1   Bytes=83    Parent id=1
   INDEX RANGE SCAN Object owner=AP Object name=AP_INVOICES_N4  Cost=3  Cardinality=31      Parent id=2
  FILTER                        Parent id=1
   NESTED LOOPS         Cost=12 Cardinality=1   Bytes=80    Parent id=4
    MERGE JOIN CARTESIAN            Cost=10 Cardinality=1   Bytes=68    Parent id=5
     TABLE ACCESS BY INDEX ROWID    Object owner=APPLSYS    Object name=FND_LOOKUP_VALUES   Cost=6  Cardinality=1   Bytes=48    Parent id=6
      INDEX RANGE SCAN  Object owner=APPLSYS    Object name=FND_LOOKUP_VALUES_U1    Cost=3  Cardinality=16      Parent id=7
     BUFFER SORT            Cost=4  Cardinality=4   Bytes=80    Parent id=6
      TABLE ACCESS BY INDEX ROWID   Object owner=AP Object name=AP_INVOICE_DISTRIBUTIONS_ALL    Cost=4  Cardinality=4   Bytes=80    Parent id=9
       INDEX RANGE SCAN Object owner=AP Object name=AP_INVOICE_DISTRIBUTIONS_U1 Cost=2  Cardinality=8       Parent id=10
    TABLE ACCESS BY INDEX ROWID Object owner=GL Object name=GL_CODE_COMBINATIONS    Cost=2  Cardinality=1   Bytes=12    Parent id=5
     INDEX UNIQUE SCAN  Object owner=GL Object name=GL_CODE_COMBINATIONS_U1 Cost=1  Cardinality=1       Parent id=12

正在进行

1 个答案:

答案 0 :(得分:4)

您可以使用format => 'outline'为特定计划生成一整套提示。例如:

create table test1(a number);
create index test1_idx on test1(a);
explain plan for select count(*) from test1;
select * from table(dbms_xplan.display(format => 'outline'));

Plan hash value: 3896847026


--------------------------------------------------------------------
| Id  | Operation          | Name  | Rows  | Cost (%CPU)| Time     |
--------------------------------------------------------------------
|   0 | SELECT STATEMENT   |       |     1 |     2   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |       |     1 |            |          |
|   2 |   TABLE ACCESS FULL| TEST1 |     1 |     2   (0)| 00:00:01 |
--------------------------------------------------------------------

Outline Data
-------------

  /*+
      BEGIN_OUTLINE_DATA
      FULL(@"SEL$1" "TEST1"@"SEL$1")
      OUTLINE_LEAF(@"SEL$1")
      ALL_ROWS
      OPT_PARAM('star_transformation_enabled' 'true')
      DB_VERSION('11.2.0.3')
      OPTIMIZER_FEATURES_ENABLE('11.2.0.3')
      IGNORE_OPTIM_EMBEDDED_HINTS
      END_OUTLINE_DATA
  */

Note
-----
   - dynamic sampling used for this statement (level=2)

这直接回答了您的问题,但一般情况下, 是解决性能问题的最佳方法。如果数据发生重大变化,计划应该能够随之改变。此外,如果暗示特定索引,则查询将在该索引变得不可用时生成错误。

通常情况下,最好使用优化器,而不是使用几十个这样的类型提示将其短路。这通常意味着使用统计数据;确保在所有对象上收集统计数据,添加直方图,使用配置文件,使用动态采样,添加表达式统计信息,使用正确的数据类型等。