不要亂加hint

來源:互聯網
上載者:User

SQL> SELECT   id FROM (SELECT  /*+ INDEX(si SIE_INVOICES_N3) */  si.id FROM binbin1 si,
  2    binbin2 bs where si.id = bs.id and si.type ='AR_INVOICE' AND
  3     si.import_failed_reason is null AND (si.imp_into_mis_flag is NULL OR si.imp_into_mis_flag = 'N') AND (si.type != 'AP_INVOICE'
  4     OR si.batch_number IS NOT NULL) AND bs.current_status = '300_HAS_APPROVED') WHERE rownum < 6 ;

no rows selected

Elapsed: 00:00:01.76

Execution Plan

----------------------------------------------------------Plan hash value: 1985019629-----------------------------------------------------------------------------------------------------| Id  | Operation                      | Name               | Rows  | Bytes | Cost (%CPU)| Time     |-----------------------------------------------------------------------------------------------------|   0 | SELECT STATEMENT               |                    |     5 |   235 |   276K  (1)| 00:55:23 ||*  1 |  COUNT STOPKEY                 |                    |       |       |            |          ||*  2 |   TABLE ACCESS BY INDEX ROWID  | SIE_INVOICES       |     1 |    24 |     3   (0)| 00:00:01 ||   3 |    NESTED LOOPS                |                    |     5 |   235 |   276K  (1)| 00:55:23 ||   4 |     TABLE ACCESS BY INDEX ROWID| WFR_BILL_STATUS    | 99261 |  2229K|  8743   (1)| 00:01:45 ||*  5 |      INDEX RANGE SCAN          | WFR_BILL_STATUS_N4 | 99261 |       |   679   (1)| 00:00:09 ||*  6 |     INDEX RANGE SCAN           | SIE_INVOICES_N3    |     1 |       |     2   (0)| 00:00:01 |-----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------   1 - filter(ROWNUM<6)   2 - filter("SI"."type"='AR_INVOICE' AND              ("SI"."type"<>'AP_INVOICE' OR "SI"."BATCH_NUMBER" IS NOT NULL) AND              ("SI"."IMP_INTO_MIS_FLAG"='N' OR "SI"."IMP_INTO_MIS_FLAG" IS NULL) AND              "SI"."IMPORT_FAILED_REASON" IS NULL)   5 - access("BS"."CURRENT_STATUS"='300_HAS_APPROVED')   6 - access("SI"."id"="BS"."id")Statistics----------------------------------------------------------          1  recursive calls          0  db block gets     234682  consistent gets          0  physical reads          0  redo size        330  bytes sent via SQL*Net to client        481  bytes received via SQL*Net from client          1  SQL*Net roundtrips to/from client          0  sorts (memory)          0  sorts (disk)          0  rows processed

從awr裡抓出一個sql,發現有hint,去掉hint後飛速。
SQL>
SQL>   SELECT   id FROM (SELECT  si.id FROM binbin1 si,
  2    binbin2 bs where si.id = bs.id and si.type ='AR_INVOICE' AND
  3     si.import_failed_reason is null AND (si.imp_into_mis_flag is NULL OR si.imp_into_mis_flag = 'N') AND (si.type != 'GL_VOUCHER'
  4     OR si.batch_number IS NOT NULL) AND bs.current_status = '300_HAS_APPROVED') WHERE rownum < 6 ;

no rows selected

Elapsed: 00:00:00.06

Execution Plan----------------------------------------------------------Plan hash value: 144640525-----------------------------------------------------------------------------------------------------| Id  | Operation                      | Name               | Rows  | Bytes | Cost (%CPU)| Time     |-----------------------------------------------------------------------------------------------------|   0 | SELECT STATEMENT               |                    |     5 |   235 |    23   (0)| 00:00:01 ||*  1 |  COUNT STOPKEY                 |                    |       |       |            |          ||*  2 |   TABLE ACCESS BY INDEX ROWID  | WFR_BILL_STATUS    |     1 |    23 |     3   (0)| 00:00:01 ||   3 |    NESTED LOOPS                |                    |     5 |   235 |    23   (0)| 00:00:01 ||*  4 |     TABLE ACCESS BY INDEX ROWID| SIE_INVOICES       |    26 |   624 |     5   (0)| 00:00:01 ||*  5 |      INDEX RANGE SCAN          | SIE_INVOICES_N8    |   107 |       |     3   (0)| 00:00:01 ||*  6 |     INDEX RANGE SCAN           | WFR_BILL_STATUS_N2 |     1 |       |     2   (0)| 00:00:01 |-----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------   1 - filter(ROWNUM<6)   2 - filter("BS"."CURRENT_STATUS"='300_HAS_APPROVED')   4 - filter(("SI"."IMP_INTO_MIS_FLAG"='N' OR "SI"."IMP_INTO_MIS_FLAG" IS NULL) AND              ("SI"."type"<>'GL_VOUCHER' OR "SI"."BATCH_NUMBER" IS NOT NULL) AND              "SI"."IMPORT_FAILED_REASON" IS NULL)   5 - access("SI"."type"='AR_INVOICE')   6 - access("SI"."id"="BS"."id")Statistics----------------------------------------------------------          1  recursive calls          0  db block gets         33  consistent gets          8  physical reads          0  redo size        330  bytes sent via SQL*Net to client        481  bytes received via SQL*Net from client          1  SQL*Net roundtrips to/from client          0  sorts (memory)          0  sorts (disk)          0  rows processed

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.