码迷,mamicode.com
首页 > 数据库 > 详细

Oracle_Pl、Sql_Nested loop

时间:2018-05-06 17:28:16      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:access   sum   check   cost   list   index   xpl   sql   char   

1.SQL

select /*+ index(T1 XPK_TRAN_HIST_TOPIC)*/
SUM(T1.LOCAL_AMOUNT) AS TOTALLOCALAMOUNT,
SUM(T1.USD_AMOUNT) AS TOTALUSDAMOUNT
FROM TRAN_HIST_TOPIC T1, MDL_CHECK_RESULT T2
WHERE T2.TRS_SEQNO = T1.SEQNO
AND T2.CASE_ID = :1
AND t1.SOC_NO = to_char(:2)

SQL>select count(*) from MDL_CHECK_RESULT where case_id=‘DK2018050300000003620000000002‘; T2

COUNT(*)
----------
3

SQL>select count(*) from TRAN_HIST_TOPIC where SOC_NO=‘123‘; T1

COUNT(*)

----------
229194

2.

SQL>explain plan for select /*+ index(T1 XPK_TRAN_HIST_TOPIC) use_nl(T1,T2) leading(T1) */
  2  SUM(T1.LOCAL_AMOUNT) AS TOTALLOCALAMOUNT,
  3  SUM(T1.USD_AMOUNT) AS TOTALUSDAMOUNT             FROM TRAN_HIST_TOPIC
  4  T1 , MDL_CHECK_RESULT T2          WHERE T2.TRS_SEQNO = T1.SEQNO
  5  AND T2.CASE_ID = ‘DK2018050300000003620000000002‘     AND t1.SOC_NO = to_char(123);
SQL>select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3321045997

-----------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                            | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
-----------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                     |                      |     1 |   158 |   575K  (1)| 01:55:08 |       |       |
|   1 |  SORT AGGREGATE                      |                      |     1 |   158 |            |          |       |       |
|   2 |   NESTED LOOPS                       |                      |    57 |  9006 |   575K  (1)| 01:55:08 |       |       |
|   3 |    PARTITION LIST SINGLE             |                      |   229K|    12M|   116K  (1)| 00:23:16 |   KEY |   KEY |
|   4 |     TABLE ACCESS BY LOCAL INDEX ROWID| TRAN_HIST_TOPIC      |   229K|    12M|   116K  (1)| 00:23:16 |    40 |    40 |
|*  5 |      INDEX RANGE SCAN                | XPK_TRAN_HIST_TOPIC  |   437 |       |  2318   (1)| 00:00:28 |    40 |    40 |
|*  6 |    INDEX UNIQUE SCAN                 | XPK_MDL_CHECK_RESULT |     1 |   102 |     2   (0)| 00:00:01 |       |       |
-----------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   5 - access("T1"."SOC_NO"=‘123‘)
   6 - access("T2"."CASE_ID"=U‘DK2018050300000003620000000002‘ AND "T2"."TRS_SEQNO"="T1"."SEQNO")

3.

SQL>explain plan for select /*+ index(T1 XPK_TRAN_HIST_TOPIC) use_nl(T1,T2) leading(T2) */
  2  SUM(T1.LOCAL_AMOUNT) AS TOTALLOCALAMOUNT,
  3  SUM(T1.USD_AMOUNT) AS TOTALUSDAMOUNT             FROM TRAN_HIST_TOPIC
T1 , MDL_CHECK_RESULT T2          WHERE T2.TRS_SEQNO = T1.SEQNO
  4    5  AND T2.CASE_ID = ‘DK2018050300000003620000000002‘     AND t1.SOC_NO = to_char(123);
SQL>select * from table(dbms_xplan.display);

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3118427468

----------------------------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                 | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
----------------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                      |     1 |   158 |   119   (0)| 00:00:02 |       |       |
|   1 |  SORT AGGREGATE                     |                      |     1 |   158 |            |          |       |       |
|   2 |   NESTED LOOPS                      |                      |    57 |  9006 |   119   (0)| 00:00:02 |       |       |
|   3 |    NESTED LOOPS                     |                      |    57 |  9006 |   119   (0)| 00:00:02 |       |       |
|*  4 |     INDEX RANGE SCAN                | XPK_MDL_CHECK_RESULT |    57 |  5814 |     5   (0)| 00:00:01 |       |       |
|   5 |     PARTITION LIST SINGLE           |                      |     1 |       |     1   (0)| 00:00:01 |   KEY |   KEY |
|*  6 |      INDEX UNIQUE SCAN              | XPK_TRAN_HIST_TOPIC  |     1 |       |     1   (0)| 00:00:01 |    40 |    40 |
|   7 |    TABLE ACCESS BY LOCAL INDEX ROWID| TRAN_HIST_TOPIC      |     1 |    56 |     2   (0)| 00:00:01 |    40 |    40 |
----------------------------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   4 - access("T2"."CASE_ID"=U‘DK2018050300000003620000000002‘)
   6 - access("T1"."SOC_NO"=‘123‘ AND "T2"."TRS_SEQNO"="T1"."SEQNO")

 

Oracle_Pl、Sql_Nested loop

标签:access   sum   check   cost   list   index   xpl   sql   char   

原文地址:https://www.cnblogs.com/dayu-liu/p/8998806.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!