首页 > 解决方案 > 尽管有提示,Oracle 不使用不可见索引

问题描述

我似乎弄乱了索引提示语法,但我已经尝试了我能想到的每一个模式/表/索引组合。

表和索引与 SYS 用户(我正在测试索引提示的用户)处于不同的架构中

这是没有提示的语句

select id from car.event where dat < sysdate and type != 0

这些是我尝试为架构dat_type中的索引实现索引提示的方法car

select /*+ index(car.event car.dat_type) */ id from car.event where dat < sysdate and type != 0
select /*+ index(event car.dat_type) */ id from car.event where dat < sysdate and type != 0
select /*+ index(car.event dat_type) */ id from car.event where dat < sysdate and type != 0
select /*+ index(event dat_type) */ id from car.event where dat < sysdate and type != 0
select /*+ index(event (dat, type)) */ id from car.event where dat < sysdate and type != 0

所以对于这五个语句,我查找了我的五个不同的 sql_id 并查看了执行计划,如下所示

select * from table(dbms_xplan.display_awr([sql_id]));

但是它们都没有显示索引的使用情况。它们都使用 20 的 DoP。我是否必须明确禁用并行性才能使用索引?或者有人可以更正我的索引提示的语法吗?

这是dat_type索引的定义

create index car.dat_type on car.event(dat, type) online;

编辑:索引设置为不可见,因此其他语句无法使用索引,但我想通过索引提示显式使用它。据我了解,索引提示的不可见性应该不是问题。如果我错了,请纠正我。

标签: oracleindexingoracle12chint

解决方案


我偶然发现了这篇文章,它表明实际上不应该只使用索引提示就可以使用不可见索引。但是,不可见索引可以与附加提示一起使用USE_INVISIBLE_INDEXES

所以这就是我让它工作的方式:

select /*+ use_invisible_indexes index(car dat_type) */ id from car.event where dat < sysdate and type != 0

推荐阅读