什么决定了SKIP索引扫描的出现
2013-09-09 11:47
316 查看
建表:
SQL> create table test as select 1 v_num,emp.* from emp;
Table created.
SQL> create index index_n_e on test(v_num,empno);
Index created.
索引所涉及到列的基数情况:
SQL> select count(distinct v_num),count(distinct empno) from test;
COUNT(DISTINCTV_NUM) COUNT(DISTINCTEMPNO)
-------------------- --------------------
2 14
查询语句和执行计划:
1.
SQL> select ename from test where empno = 7369;
Execution Plan
----------------------------------------------------------
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 20 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------2.
SQL> analyze table test compute statistics; Table analyzed.
SQL> drop index index_n_e;
Index dropped.
SQL> select ename from test where empno = 7369;
Execution Plan
----------------------------------------------------------
Plan hash value: 2333580441
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 8 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | INDEX_E_N | 1 | | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------4.
如果想要组合索引走跳跃索引扫描(INDEX SKIP SCAN)需要满足的条件有:
1.复合索引的引导列基数较低,而其他列基数高
2.对表进行分析
-------------------------------------------------------------------------
同时在做试验的时候也遇到了这样的情况,当表上有索引处于unusable的时候,是不能对这个表进行分析的。
SQL> alter index index_e_n unusable;
Index altered.
SQL> create table test as select 1 v_num,emp.* from emp;
Table created.
SQL> update test set v_num = 2 where empno = 7369; 1 row updated.建索引:
SQL> create index index_n_e on test(v_num,empno);
Index created.
索引所涉及到列的基数情况:
SQL> select count(distinct v_num),count(distinct empno) from test;
COUNT(DISTINCTV_NUM) COUNT(DISTINCTEMPNO)
-------------------- --------------------
2 14
查询语句和执行计划:
1.
SQL> select ename from test where empno = 7369;
Execution Plan
----------------------------------------------------------
Plan hash value: 1357081020
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 20 | 3 (0)| 00:00:01 |
|* 1 | TABLE ACCESS FULL| TEST | 1 | 20 | 3 (0)| 00:00:01 |
--------------------------------------------------------------------------2.
SQL> analyze table test compute statistics; Table analyzed.
SQL> select ename from test where empno = 7369; Execution Plan ---------------------------------------------------------- Plan hash value: 3656150759 ----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 1 | 8 | 3 (0)| 00:00:01 | | 1 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 8 | 3 (0)| 00:00:01 | |* 2 | INDEX SKIP SCAN | INDEX_N_E | 1 | | 2 (0)| 00:00:01 | -----------------------------------------------------------------------------------------3.
SQL> drop index index_n_e;
Index dropped.
SQL> create index index_e_n on test(empno,v_num); Index created.
SQL> select ename from test where empno = 7369;
Execution Plan
----------------------------------------------------------
Plan hash value: 2333580441
-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 8 | 2 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 8 | 2 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | INDEX_E_N | 1 | | 1 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------4.
SQL> select ename from test where v_num = 2; Execution Plan ---------------------------------------------------------- Plan hash value: 1357081020 -------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 7 | 49 | 3 (0)| 00:00:01 | |* 1 | TABLE ACCESS FULL| TEST | 7 | 49 | 3 (0)| 00:00:01 | --------------------------------------------------------------------------经过上面的两组对照(1,2;3,4)可以得出以下结论:
如果想要组合索引走跳跃索引扫描(INDEX SKIP SCAN)需要满足的条件有:
1.复合索引的引导列基数较低,而其他列基数高
2.对表进行分析
-------------------------------------------------------------------------
同时在做试验的时候也遇到了这样的情况,当表上有索引处于unusable的时候,是不能对这个表进行分析的。
SQL> alter index index_e_n unusable;
Index altered.
SQL> analyze table test compute statistics; analyze table test compute statistics * ERROR at line 1: ORA-01502: index 'SCOTT.INDEX_E_N' or partition of such index is in unusable state
SQL> alter index index_e_n rebuild; Index altered.
SQL> analyze table test compute statistics; Table analyzed.
相关文章推荐
- SQL SERVER中什么情况会导致索引查找变成索引扫描
- oracle 性能优化操作十八: 决定使用全表扫描还是使用索引
- SQL SERVER中什么情况会导致索引查找变成索引扫描
- SQL Server [索引查找/扫描] -- 什么情况会导致索引查找变成索引扫描
- 什么情况导致全表扫描,而不是用索引
- oracle 性能优化操作十八: 决定使用全表扫描还是使用索引
- 什么情况导致全表扫描,而不是用索引
- 什么情况导致全表扫描,而不是用索引 收藏
- mysql创建索引以及进程过程中出现的问题
- VS2010/VS2005/VS频繁出现爆掉是什么原因呢?
- mysql数据库二进制初始化出现:170425 17:47:04 [ERROR] /application/mysql//bin/mysqld: unknown option '--skip-locking' 170425 17:47:04 [ERROR] Aborting 解决办法
- MySQL 5.6 root密码丢失,使用mysqld --skip-grant-tables出现错误提示
- 什么是索引以及索引的好处
- MySQL使用什么函数可以将出现的NULL改为一个默认值?
- Java的Class类提供了许多的getDeclaredxxx和getxxx方法,例如getDeclaredMethod和getMethod成对出现,那它们有什么区别呢?
- 不知道小程序能做什么?图片转文字的扫描不再限制
- socket链接的关闭close和shutdown的区别,TIME_WAIT和CLOSE_WAIT什么时刻出现,如何处理
- 是什么决定着seo的成败?
- MySQL优化GROUP BY-松散索引扫描与紧凑索引扫描
- ORA FAQ 性能调整系列之——当索引第一列由序列产生,一个逆序索引有什么用?