博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
添加 index_combine hint的索引
阅读量:7255 次
发布时间:2019-06-29

本文共 3486 字,大约阅读时间需要 11 分钟。

想试验一下 index_combine这个hint,于是做了如下试验。1.创建一个具有若干index的表SQL>  create table test as select object_id,object_type,status from dba_objects;Table created.SQL> create index tobject_id on test(object_id);Index created.SQL>  create index tobject_type on test(object_type);Index created.2.加 index_combin hint 来看执行计划SQL> explain plan for select /*+ index_combine(test tobject_id tobject_type) */ * from test where object_id>5000 and object_type='INDEX';Explained.在看执行计划之前,我以为index_combine会这样处理这条语句1.把object_id>500 用索引范围扫描,然后用bitmap convert to rowid 转化成位图索引2.把object_type=index 也用bitmap convert to rowid 转化成位图索引3.combine 上面的两个结果但没想到查询优化器采用的方式居然是全表扫描,如下:--------------------------------------------------------------------------| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |--------------------------------------------------------------------------|   0 | SELECT STATEMENT  |      |  4071 |   115K|    48  (11)| 00:00:01 ||*  1 |  TABLE ACCESS FULL| TEST |  4071 |   115K|    48  (11)| 00:00:01 |--------------------------------------------------------------------------根据官网对index_combine的说法The INDEX_COMBINE hint instructs the optimizer to use a bitmap access path for the table. If indexspec is omitted from the INDEX_COMBINE hint, then the optimizer uses whatever Boolean combination of indexes has the best cost estimate for the table. If you specify indexspec, then the optimizer tries to use some Boolean combination of the specified indexes. 我指定了 indexspec,那么查询优化器应该在我指定的索引 列表中选取合适的组合啊,怎么变成全表扫描了3.我试着把object_type这列的索引由B-tree索引改成了位图索引,hint立马就生效了。 难道说这个hint要求指定的索引列表中必须有位图索引吗? 不应该吧?SQL> drop index tobject_type;Index dropped.SQL> create bitmap index tobject_type on test(object_type);Index created.SQL> explain plan for select /*+ index_combine(test tobject_id tobject_type) */ * from test where object_id>5000 and object_type='INDEX';Explained.SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT------------------------------------------------------------------------------------------------------------------------------------------------------Plan hash value: 1817610418-------------------------------------------------------------------------------------------------| Id  | Operation                        | Name         | Rows  | Bytes | Cost (%CPU)| Time     |-------------------------------------------------------------------------------------------------|   0 | SELECT STATEMENT                 |              |  4071 |   115K|   157   (4)| 00:00:02 ||   1 |  TABLE ACCESS BY INDEX ROWID     | TEST         |  4071 |   115K|   157   (4)| 00:00:02 ||   2 |   BITMAP CONVERSION TO ROWIDS    |              |       |       |            |          ||   3 |    BITMAP AND                    |              |       |       |            |          ||*  4 |     BITMAP INDEX SINGLE VALUE    | TOBJECT_TYPE |       |       |            |          ||   5 |     BITMAP CONVERSION FROM ROWIDS|              |       |       |            |          |PLAN_TABLE_OUTPUT------------------------------------------------------------------------------------------------------------------------------------------------------|   6 |      SORT ORDER BY               |              |       |       |            |          ||*  7 |       INDEX RANGE SCAN           | TOBJECT_ID   |       |       |   122   (4)| 00:00:02 |-------------------------------------------------------------------------------------------------

  

转载于:https://www.cnblogs.com/myjoan/p/5683875.html

你可能感兴趣的文章
气泡框箭头制作
查看>>
android studio 中的编码问题
查看>>
WinForm实现简单的拖拽文件到出题的功能(C#)(3)
查看>>
8.tomcat认证访问
查看>>
android通过BitmapFactory.decodeFile获取图片bitmap报内存溢出的解决办法
查看>>
getcwd()和dirname(__FILE__)的区别
查看>>
黑马公社学习
查看>>
zabbix如何监控WEB应用性能
查看>>
mysql awr v1.0.1发布
查看>>
发布ASP.NET Core程序到Linux生产环境
查看>>
Java总结第一次//有些图片未显示,文章包含基础java语言及各种语句
查看>>
CString转换成char*
查看>>
Java中windows路径转换成linux路径等工具类
查看>>
Android 对listview中每个item高度的设置
查看>>
Vs 2015 调试ASP.NET Core修改监听端口
查看>>
Angular2学习笔记——NgModule
查看>>
linux i2c 设备节点读写
查看>>
Deep Residual Learning for Image Recognition(MSRA-深度残差学习)
查看>>
SSH的各个配置文件:
查看>>
tomcat端口被占用
查看>>