关于Oracle降序索引的定意及回溯

 降序索引本质上是FBI,其具体定义可以通过 user_ind_expressions 或dba_ind_expressions 查询。
那么同样的,降序索引只有在CBO下才能被使用。

Connected to Oracle9i Enterprise Edition Release 9.2.0.4.0
Connected as eygle

SQL> create table t as select * from dba_users;

Table created

SQL> create index idx_username_desc on t(username desc);

Index created

SQL> select index_name,table_name,INDEX_TYPE from user_indexes where table_name=@#T@#;

INDEX_NAME TABLE_NAME INDEX_TYPE
------------------------------ ------------------------------ ---------------------------
IDX_USERNAME_DESC T FUNCTION-BASED NORMAL

SQL> select column_name,column_position,descend from user_ind_columns
2 where table_name=@#T@#;

COLUMN_NAME COLUMN_POSITION DESCEND
------------------------------ --------------- -------
SYS_NC00013$ 1 DESC

SQL>

SQL> select * from user_ind_expressions where table_name=@#T@#;

INDEX_NAME TABLE_NAME COLUMN_EXPRESSION COLUMN_POSITION
------------------------------ ------------------------------ ------------------------------ ---------------
IDX_USERNAME_DESC T "USERNAME" 1

总结:

1,oracle use expression instead of column on desc order index, and implement as a function-based index (FBI).

2, because of this mechanism, we can create more indexes on the same column . To achieve the smart index design to developer and DBA.

sample code for think the essensial of FBI index of oracle:

1, create index idx_sal on emp(sal desc ) ;
2, create index idx_sal_all on emp(sal desc, comm desc ) ;
3, create index idx_sal_all2 on emp(sal desc, comm asc ) ; -- It's OK.
4, create index idx_sal_sum on emp(sal+comm desc ) ;
5, create index idx_sal_sum2 on emp(sal+comm asc ) ; -- It's OK.

In fact , we almost do not want to create 2 with 3 in the same system.

and will not to create 4 with 5 in the same system. Because we can (or oracle implicitly) use index_desc hint on the SQL.


[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/350519/viewspace-1038606/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/350519/viewspace-1038606/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值