7. 索引唯一扫描(INDEX UNIQUE SCAN )create unique index ind_object_id on test_objects(object_id);
SQL> select object_id from test_objects where object_id=275257;
Execution Plan
----------------------------------------------------------
Plan hash value: 3714264582
------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 5 | 1 (0)| 00:00:01 |
|* 1 | INDEX UNIQUE SCAN| IND_OBJECT_ID | 1 | 5 | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("OBJECT_ID"=275257)
8. 索引范围扫描(INDEX RANGE SCAN)SQL> select object_id from test_objects where object_id>275200;
43 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2038338801
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 21 | 105 | 2 (0)| 00:00:01 |
|* 1 | INDEX RANGE SCAN| IND_OBJECT_ID | 21 | 105 | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("OBJECT_ID">275200)
9. 索引快速全扫描(INDEX FAST FULL SCAN)LEGEND:
SH=segment header
R=root block
B=branch block
L=leaf blockL...RBBLLLLLSHmultiblock readdb_file_multiblock_read_count = 4multiblock readSQL> select object_id from test_objects where object_id is not null;
101467 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 2799590446
--------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 101K| 495K| 59 (0)| 00:00:01 |
|* 1 | INDEX FAST FULL SCAN| IND_OBJECT_ID | 101K| 495K| 59 (0)| 00:00:01 |
--------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID" IS NOT NULL)
10. 索引快速全扫描(INDEX FAST FULL SCAN)SQL> select * from test_objects where object_id is not null;
101467 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3570092908
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 101K| 9413K| 398 (1)| 00:00:05 |
|* 1 | TABLE ACCESS FULL| TEST_OBJECTS | 101K| 9413K| 398 (1)| 00:00:05 |
----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID" IS NOT NULL)
11. 索引全扫描(INDEX FULL SCAN)SQL> select object_id from test_objects where object_id is not null order by 1;
101467 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3454935350
----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 101K| 495K| 213 (1)| 00:00:03 |
|* 1 | INDEX FULL SCAN | IND_OBJECT_ID | 101K| 495K| 213 (1)| 00:00:03 |
----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("OBJECT_ID" IS NOT NULL)
12. 索引跳跃扫描(INDEX SKIP SCAN)create index ind_com on city(country_id,city_id);
SQL> select * from city where city_id='1';
Execution Plan
----------------------------------------------------------
Plan hash value: 1118414011
---------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 21 | 13 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| CITY | 1 | 21 | 13 (0)| 00:00:01 |
|* 2 | INDEX SKIP SCAN | IND_COM | 1 | | 12 (0)| 00:00:01 |
---------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("CITY_ID"='1')
filter("CITY_ID"='1')
13. 索引跳跃扫描(INDEX SKIP SCAN)SQL> select /*+ no_index(city ind_com) */ * from city where city_id='1';
Elapsed: 00:00:00.03
Execution Plan
----------------------------------------------------------
Plan hash value: 3973142328
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 21 | 996 (1)| 00:00:12 |
|* 1 | TABLE ACCESS FULL| CITY | 1 | 21 | 996 (1)| 00:00:12 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("CITY_ID"='1')
15. 位图索引SELECT * FROM PERF_TEAM WHERE country in('FR','DE');ORSELECT * FROM EMEA_PERF_TEAM T WHERE country='FR' and gender='M';FR001111000000M111011010111AND
17. 使用索引如果程序或者一条SQL中只用到某个表的少量数据,应该尽量使用索引。
查看唯一值个数
Select count(*),count(distinct colname) from table_name;
查看数据分布
Select count(*), colname from table_name
Group by colname order by 1;