Do not add hint in disorder

Source: Internet
Author: 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_1__mis_flag is null or Si. imp_1__mis_flag = 'n') and (Si. type! = 'Ap _ invoice'
4 or Si. batch_number is not null) and BS. current_status = '2017 _ 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

Capture an SQL statement from AWR and find that there is a hint. After removing the hint, it is fast.
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_1__mis_flag is null or Si. imp_1__mis_flag = 'n') and (Si. type! = 'Gl _ voucher'
4 or Si. batch_number is not null) and BS. current_status = '2017 _ 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.