hint指定index的深入理解
http://czmmiao.iteye.com/blog/1480247创建一个表,含有位图index和b-tree index
SQL> create table t as select object_id id ,object_name from dba_objects;
Table created.
SQL> create index b_tree_ind on t(id);
Index created.
SQL> create bitmap index b_bm_name on t(object_name);
Index created.
SQL> exec dbms_stats.gather_table_stats('HR','T',cascade=> true);
SELE
PL/SQL procedure successfully completed.
SQL> set autotrace trace exp stat
SQL> select id from t;
50365 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1601196873
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 47448 | 602K| 57 (2)| 00:00:01 |
| 1 | TABLE ACCESS FULL| T | 47448 | 602K| 57 (2)| 00:00:01 |
--------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
28 recursive calls
0 db block gets
3646 consistent gets
0 physical reads
0 redo size
728900 bytes sent via SQL*Net to client
37312 bytes received via SQL*Net from client
3359 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
50365 rows processed
这里因为object_id列可能有null值,所以不会使用b_tree_t_xifenfei索引,预料之中事件
SQL> select /*+ index(t b_tree_ind) */ id from t
50365 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3465251059
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 47448 | 602K| 805 (1)| 00:00:10 |
| 1 | TABLE ACCESS BY INDEX ROWID | T | 47448 | 602K| 805 (1)| 00:00:10 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
| 3 | BITMAP INDEX FULL SCAN | B_BM_NAME | | | | |
------------------------------------------------------------------------------------------
Note
-----
- dynamic sampling used for this statement
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
27318 consistent gets
0 physical reads
0 redo size
2147500 bytes sent via SQL*Net to client
37312 bytes received via SQL*Net from client
3359 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
50365 rows processed
这里因为object_id列可能有null值,所以不会使用b_tree_t_xifenfei索引,这里的疑惑是:
就算不会使用b_tree_t_xifenfei index也不应该会使用BITMAP_T_XIFENFEI index,因为使用这个的cost会大于全表扫描
SQL> select /*+ index(t aaa) */ id from t;
50365 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3465251059
------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 50365 | 245K| 805 (1)| 00:00:10 |
| 1 | TABLE ACCESS BY INDEX ROWID | T | 50365 | 245K| 805 (1)| 00:00:10 |
| 2 | BITMAP CONVERSION TO ROWIDS| | | | | |
| 3 | BITMAP INDEX FULL SCAN | B_BM_NAME | | | | |
------------------------------------------------------------------------------------------
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
27318 consistent gets
0 physical reads
0 redo size
2147500 bytes sent via SQL*Net to client
37312 bytes received via SQL*Net from client
3359 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
50365 rows processed
这里使用了一个无效的index,也使用了BITMAP_T_XIFENFEI,让人更加的感觉奇怪。
官方文档上有如下解释
If the INDEX hint specifies a single available index, then the database performs a scan on this index. The optimizer does not consider a full table scan or a scan of another index on the table.
For a hint on a combination of multiple indexes, Oracle recommends using INDEX_COMBINE rather than INDEX, because it is a more versatile hint. If the INDEX hint specifies a list of available indexes, then the optimizer considers the cost of a scan on each index in the list and then performs the index scan with the lowest cost. The database can also choose to scan multiple indexes from this list and merge the results, if such an access path has the lowest cost. The database does not consider a full table scan or a scan on an index not listed in the hint.
If the INDEX hint specifies no indexes, then the optimizer considers the cost of a scan on each available index on the table and then performs the index scan with the lowest cost. The database can also choose to scan multiple indexes and merge the results, if such an access path has the lowest cost. The optimizer does not consider a full table scan.
如果我们使用hint指定了一个无效的index,优化器会扫描表中所有可以使用的index,然后选择cost最小的index或者index组合,而不会选择全表扫描。
因为我们hint指定b_tree_t_xifenfei index的时候,因为object_id可能有值为空(列没定义为not null),所以不能使用该index,从而也就是相当于一个无效的index,从而扫描该表的其他可以使用的index,导致使用了位图索引(该类型index不排除null),而不是全表扫描.在9i和10g上有上述现象,11g时Oracle对上述现象有所改进
注意:使用hint指定index的时候需要慎重,如果不合适或者无效,可能导致程序效率更低
hint指定index的深入理解的更多相关文章
- Could not resolve matching constructor (hint: specify index/type/name arguments for simple parameter 标签: 构造器注入Spring
问题:要么是因为构造方法改变了,要么就是构造方法入参实例化失败(比如没有实现) 问题 在练习spring构造器注入方式的小程序的时候报错: Exception in thread “main” org ...
- redis删除list中指定index的值
Redis的List删除命令: lrem : lrem mylist 0 "value" //从mylist中删除全部等值value的元素 0为全部,负值为从尾部开始. ...
- mysql index hint 在index不存在时的处理
关于index_hint 在mysql查询语句中可以通过指定index_hint来告诉优化器如何使用索引,详细可以参考这里 index_hint: USE {INDEX|KEY} [FOR {JOIN ...
- mysql explain 的extra中using index ,using where,using index condition,using index & using where理解
using index :查找使用了索引,查询结果覆盖了索引 using where:查找使用了索引,不需要回表去查询所需的数据,查询结果是索引的一部分 using index condition:查 ...
- 【Elasticsearch】清空指定index/type下的数据
1.postman请求接口 http://ip:端口/index/type/_delete_by_query?conflicts=proceed body为: { "query": ...
- ElasticSearch(十一)Elasticsearch清空指定Index/Type数据
POST /index_name/type_name/_delete_by_query?conflicts=proceed { "query": { "match_all ...
- vue 重塑数组之 修改数组指定index的值
vm.items[indexOfItem] = newValue vue不能检测数组的变动 想要实现可以使用vue的set方法 this.$set(this.items,indexOfItem,new ...
- [转]Oracle中Hint深入理解
原文地址:http://czmmiao.iteye.com/blog/1478465 Hint概述 基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担.但有时它也聪明 ...
- Oracle中Hint深入理解(原创)
http://czmmiao.iteye.com/blog/1478465 Hint概述 基于代价的优化器是很聪明的,在绝大多数情况下它会选择正确的优化器,减轻了DBA的负担.但有时它也聪明反被聪明 ...
随机推荐
- caffe+Ubuntu14.04.10 +cuda7.0/7.5+CuDNNv4 安装
特别说明: Caffe 官网地址:http://caffe.berkeleyvision.org/ 本文为作者亲自实验完成,但仅限用于学术交流使用,使用本指南造成的任何不良后果由使用者自行承担,与本文 ...
- apache 列目录修复
描述 :Apache默认配置时允许目录浏览.如果目录下没有索引文件,则会出现目录浏览,导致文件信息泄漏. 检测方法:直接访问目录,如果能看到目录下的文件信息,则说明存在目录浏览漏洞 加固方法: 1 ...
- JavaScript (JS)基础:BOM 浅析 (含window对象相关基本方法、属性解析)
① window对象(Math方法也属于window对象): window对象是JavaScript中的顶级对象,所有定义在全局作用域中的变量.函数都会变成window对象的属性和方法,window对 ...
- 提高Java开发效率,Idea必装的几款插件
1.codeMaker 重复代码生成工具 domian和dto两个类基本差不多,这个工具就可以通过一个类快速生成另一个类. 2.gsonFormat json转换成Java类 很多时候根据别人接口给的 ...
- wsl折腾记
参考1 wsl在哪 C:\Users\用户名\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu18.04onWindows_79rhkp1fndg ...
- 如何在Windows下开发Python:在cmd下运行Python脚本+如何使用Python Shell(command line模式和GUI模式)+如何使用Python IDE
http://www.crifan.com/how_to_do_python_development_under_windows_environment/ 本文目的 希望对于,如何在Windows下, ...
- PAT 天梯赛 L1-043 阅览室
L1-043. 阅览室 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 天梯图书阅览室请你编写一个简单的图书借阅统计程序.当读者 ...
- 洛谷P1965 转圈游戏 [NOIP2013]
题目描述 n 个小伙伴(编号从 0 到 n-1)围坐一圈玩游戏.按照顺时针方向给 n 个位置编号,从0 到 n-1.最初,第 0 号小伙伴在第 0 号位置,第 1 号小伙伴在第 1 号位置,……,依此 ...
- 【UVA11859】Division Game(SG函数,Nim游戏)
题意:给定一个n*m的矩阵,两个游戏者轮流操作. 每次可以选一行中的1个或多个大于1的整数,把它们中的每个数都变成它的某个真因子,不能操作的输. 问先手能否获胜 n,m<=50,2<=a[ ...
- luogu 3406 海底高铁 前缀和
题目链接 题意 给定一个数轴上的若干城市\(1,2,3,...,n\),在第\(i\)到\(i+1\)\((1\leq i\lt n)\)个城市间有铁路,通行方式可为 \(1.\)每次买票(花费\(a ...