问题:Oracle 在查询的where子句中,索引的索引列/前导列是否作为单个表谓词提供列才可以走该索引?
第一 如果是,那么数据库要求在查询中使用索引,谓词列表中至少需要索引的第一列。
例如:基础信息

如果想使用索引ind_test_01或者ind_test_03,查询语句where 谓词 必须有object_id 列,如:

第二 如果不是
1.CBO可以使用索引快速全扫描( Index Fast Full Scan INDEX_FFS),只要索引包含所有的列查询需要,并且索引键中至少有一列具有NOT NULL约束。使用索引不需要谓词中包含索引的首列。注意,使用INDEX_FFS不一定返回已排序的行。排序取决于读取索引块的顺序,并且只有在使用'order by'子句时才能保证以排序的顺序返回行。
如:
2.CBO可以使用索引跳过扫描( Index Skip Scan INDEX_SS)。对象不需要索引的首列要执行的INDEX_SS。
针对 INDEX_SS ,MOS 解释如下可以增加理解:
Index
skip scans improve index scans against non-prefix columns since it is
often faster to scan index blocks than scanning table data blocks. A
non-prefix index is an index which does not contain a key column as its
first column.
This concept is easier to understand if one
imagines a prefix index to be similar to a partitioned table. In a
partitioned object the partition key (in this case the leading column)
defines which partition data is stored within. In the index case every
row underneath each key (the prefix column) would be ordered under that
key. Thus in a skip scan of a prefixed index, the prefixed value is
skipped and the non-prefix columns are accessed as logical sub-indexes.
The trailing columns are ordered within the prefix column and so a
'normal' index access can be done ignoring the prefix.
In this
case a composite index is split logically into smaller subindexes. The
number of logical subindexes depends on the cardinality of the initial
column. Hence it is now possible to use the index even if the leading
column is not used in a where clause.
如:



3.CBO可以选择使用索引来避免排序。索引的列需要按by的顺序排列发生这种情况的条款。
如:select object_id,owner,object_name from test where object_id=2 order by 1;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26342786/viewspace-2982095/ ,如需转载,请注明出处,否则将追究法律责任。