2

我想将以下计划转换为提示。我该怎么做。

在此处输入图像描述

这是需要较长时间的实际查询,请向我们建议相同的解决方案

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

它正在服用

4

1 回答 1

5

您可以使用 为特定计划生成一整套提示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)

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

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

于 2013-09-03T22:45:53.283 回答