- 最后登录
- 2015-3-31
- 在线时间
- 10 小时
- 威望
- 15
- 金钱
- 215
- 注册时间
- 2013-8-23
- 阅读权限
- 10
- 帖子
- 16
- 精华
- 0
- 积分
- 15
- UID
- 1198
|
1#
发表于 2014-6-24 19:06:43
|
查看: 4996 |
回复: 8
联合索引id在前,name在后,物理读为72,CPU cost也不高
SQL> create index ind_name_id on t(object_id,object_name);
Index created.
Elapsed: 00:00:01.19
SQL> select object_id,object_name from t where object_id < 5;
OBJECT_ID OBJECT_NAME
---------- --------------------------------------------------------------------------------------------------------------------------------
2 C_OBJ#
3 I_OBJ#
4 TAB$
Elapsed: 00:00:00.01
Execution Plan
----------------------------------------------------------
Plan hash value: 2897093046
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 237 | 2 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IND_NAME_ID | 3 | 237 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("OBJECT_ID"<5)
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
11 recursive calls
0 db block gets
72 consistent gets
1 physical reads
0 redo size
681 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
3 rows processed
联合索引name在前,id在后,当我这样设置时,物理读变得特别高573
SQL> create index ind_ob_name_and_id on t(object_name,object_id);
Index created.
SQL> select object_name,object_id from t where object_id < 5;
OBJECT_NAME OBJECT_ID
-------------------------------------------------------------------------------------------------------------------------------- ----------
C_OBJ# 2
I_OBJ# 3
TAB$ 4
Elapsed: 00:00:00.04
Execution Plan
----------------------------------------------------------
Plan hash value: 374587637
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 14 | 1106 | 136 (1)| 00:00:02 |
|* 1 | INDEX FAST FULL SCAN| IND_OB_NAME_AND_ID | 14 | 1106 | 136 (1)| 00:00:02 |
-------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID"<5)
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
55 recursive calls
0 db block gets
573 consistent gets
475 physical reads
0 redo size
681 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
3 rows processed
当只有object_id作为索引时,这样和第一种情况差别不是很大
SQL> create index IDX_OBJECTS_ID idx_objects_id on t(object_id);
Index created.
SQL> select object_name,object_id from t where object_id < 5;
OBJECT_NAME OBJECT_ID
-------------------------------------------------------------------------------------------------------------------------------- ----------
C_OBJ# 2
I_OBJ# 3
TAB$ 4
Elapsed: 00:00:00.02
Execution Plan
----------------------------------------------------------
Plan hash value: 1638157718
----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 3 | 237 | 3 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T | 3 | 237 | 3 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | IDX_OBJECTS_ID | 3 | | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"<5)
Note
-----
- dynamic sampling used for this statement (level=2)
Statistics
----------------------------------------------------------
9 recursive calls
0 db block gets
71 consistent gets
0 physical reads
0 redo size
681 bytes sent via SQL*Net to client
519 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
3 rows processed
这是为什么?希望大家能给我普及下!谢谢! |
|