本SQL是公司显示屏报表SQL,每2min更新一次
SQL> explain plan for select distinct id_card
from (select t.id_card
from clspuser.crf_p2p_account_info t
where t.loan_amount <= 200000 and t.pay_date <= '2016-11-14'
union
select t.id_card
from clspuser.zh_crf_p2p_account_info t
where t.loan_amount <= 200000 and t.pay_date <= '2016-11-14');
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 398117206
--------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 168K| 2800K| | 4009 (2)| 00:00:49 |
| 1 | VIEW | | 168K| 2800K| | 4009 (2)| 00:00:49 |
| 2 | SORT UNIQUE | | 168K| 6093K| 15M| 4009 (2)| 00:00:49 |
| 3 | UNION-ALL | | | | | | |
|* 4 | TABLE ACCESS FULL| CRF_P2P_ACCOUNT_INFO | 167K| 6067K| | 2357 (2)| 00:00:29 |
|* 5 | TABLE ACCESS FULL| ZH_CRF_P2P_ACCOUNT_INFO | 759 | 27324 | | 12 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("T"."LOAN_AMOUNT"<=200000 AND "T"."PAY_DATE"<='2016-11-14')
5 - filter("T"."LOAN_AMOUNT"<=200000 AND "T"."PAY_DATE"<='2016-11-14')
18 rows selected.
SQL>
SQL> select distinct id_card
from (select t.id_card
from clspuser.crf_p2p_account_info t
where t.loan_amount <= 200000
union
select t.id_card
from clspuser.zh_crf_p2p_account_info t
where t.loan_amount <= 200000 );
159471 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 398117206
--------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 168K| 2800K| | 3608 (1)| 00:00:44 |
| 1 | VIEW | | 168K| 2800K| | 3608 (1)| 00:00:44 |
| 2 | SORT UNIQUE | | 168K| 4281K| 11M| 3608 (2)| 00:00:44 |
| 3 | UNION-ALL | | | | | | |
|* 4 | TABLE ACCESS FULL| CRF_P2P_ACCOUNT_INFO | 167K| 4263K| | 2339 (1)| 00:00:29 |
|* 5 | TABLE ACCESS FULL| ZH_CRF_P2P_ACCOUNT_INFO | 759 | 18975 | | 12 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("T"."LOAN_AMOUNT"<=200000)
5 - filter("T"."LOAN_AMOUNT"<=200000)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
10591 consistent gets
0 physical reads
0 redo size
5167400 bytes sent via SQL*Net to client
117410 bytes received via SQL*Net from client
10633 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
159471 rows processed
SQL>
SQL> create index clspuser.crf_p2p_loan_amount_idx on crf_p2p_account_info(loan_amount);
Index created.
SQL>
索引没用,删了
SQL> drop index crf_p2p_loan_amount_idx ;
Index dropped.
SQL>
create index clspuser.crf_p2p_loan_amount_uidx on clspuser.crf_p2p_account_info (loan_amount, id_card) online;
SQL> explain plan for select distinct id_card
from (select t.id_card
from clspuser.crf_p2p_account_info t
where t.loan_amount <= 200000
union
select t.id_card
from clspuser.zh_crf_p2p_account_info t
where t.loan_amount <= 200000 );
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1932924644
------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 168K| 2800K| | 1459 (2)| 00:00:18 |
| 1 | VIEW | | 168K| 2800K| | 1459 (2)| 00:00:18 |
| 2 | SORT UNIQUE | | 168K| 4281K| 11M| 1459 (3)| 00:00:18 |
| 3 | UNION-ALL | | | | | | |
|* 4 | INDEX FAST FULL SCAN| CRF_P2P_LOAN_AMOUNT_UIDX | 167K| 4263K| | 189 (3)| 00:00:03 |
|* 5 | TABLE ACCESS FULL | ZH_CRF_P2P_ACCOUNT_INFO | 759 | 18975 | | 12 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("T"."LOAN_AMOUNT"<=200000)
5 - filter("T"."LOAN_AMOUNT"<=200000)
18 rows selected.
SQL>
SQL> explain plan for select id_card
from (select t.id_card
from clspuser.crf_p2p_account_info t
where t.loan_amount <= 200000
union
select t.id_card
from clspuser.zh_crf_p2p_account_info t
where t.loan_amount <= 200000 );
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1932924644
------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 168K| 2800K| | 1459 (2)| 00:00:18 |
| 1 | VIEW | | 168K| 2800K| | 1459 (2)| 00:00:18 |
| 2 | SORT UNIQUE | | 168K| 4281K| 11M| 1459 (3)| 00:00:18 |
| 3 | UNION-ALL | | | | | | |
|* 4 | INDEX FAST FULL SCAN| CRF_P2P_LOAN_AMOUNT_UIDX | 167K| 4263K| | 189 (3)| 00:00:03 |
|* 5 | TABLE ACCESS FULL | ZH_CRF_P2P_ACCOUNT_INFO | 759 | 18975 | | 12 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("T"."LOAN_AMOUNT"<=200000)
5 - filter("T"."LOAN_AMOUNT"<=200000)
18 rows selected.
SQL>
SQL> explain plan for select distinct t.id_card
from clspuser.crf_p2p_account_info t
where t.loan_amount <= 200000
union
select t.id_card
from clspuser.zh_crf_p2p_account_info t
where t.loan_amount <= 200000;
Explained.
SQL>
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 2415738997
-----------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 159K| 4041K| | 1414 (3)| 00:00:17 |
| 1 | SORT UNIQUE | | 159K| 4041K| 11M| 1414 (3)| 00:00:17 |
| 2 | UNION-ALL | | | | | | |
|* 3 | INDEX FAST FULL SCAN| CRF_P2P_LOAN_AMOUNT_UIDX | 167K| 4263K| | 189 (3)| 00:00:03 |
|* 4 | TABLE ACCESS FULL | ZH_CRF_P2P_ACCOUNT_INFO | 759 | 18975 | | 12 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter("T"."LOAN_AMOUNT"<=200000)
4 - filter("T"."LOAN_AMOUNT"<=200000)
17 rows selected.
SQL>
SQL> explain plan for select distinct id_card
from (select t.id_card
from clspuser.crf_p2p_account_info t
where t.loan_amount <= 200000
union all
select t.id_card
from clspuser.zh_crf_p2p_account_info t
where t.loan_amount <= 200000 );
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1571881081
------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 168K| 2800K| | 1144 (2)| 00:00:14 |
| 1 | HASH UNIQUE | | 168K| 2800K| 7960K| 1144 (2)| 00:00:14 |
| 2 | VIEW | | 168K| 2800K| | 201 (2)| 00:00:03 |
| 3 | UNION-ALL | | | | | | |
|* 4 | INDEX FAST FULL SCAN| CRF_P2P_LOAN_AMOUNT_UIDX | 167K| 4263K| | 189 (3)| 00:00:03 |
|* 5 | TABLE ACCESS FULL | ZH_CRF_P2P_ACCOUNT_INFO | 759 | 18975 | | 12 (0)| 00:00:01 |
------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("T"."LOAN_AMOUNT"<=200000)
5 - filter("T"."LOAN_AMOUNT"<=200000)
18 rows selected.
SQL>
SQL> explain plan for select id_card
from (select t.id_card
from clspuser.crf_p2p_account_info t
where t.loan_amount <= 200000
union all
select t.id_card
from clspuser.zh_crf_p2p_account_info t
where t.loan_amount <= 200000 ) a group by a.id_card;
Explained.
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1930908435
----------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 168K| 2800K| 218 (10)| 00:00:03 |
| 1 | HASH GROUP BY | | 168K| 2800K| 218 (10)| 00:00:03 |
| 2 | VIEW | | 168K| 2800K| 201 (2)| 00:00:03 |
| 3 | UNION-ALL | | | | | |
|* 4 | INDEX FAST FULL SCAN| CRF_P2P_LOAN_AMOUNT_UIDX | 167K| 4263K| 189 (3)| 00:00:03 |
|* 5 | TABLE ACCESS FULL | ZH_CRF_P2P_ACCOUNT_INFO | 759 | 18975 | 12 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
4 - filter("T"."LOAN_AMOUNT"<=200000)
5 - filter("T"."LOAN_AMOUNT"<=200000)
18 rows selected.
SQL>