降序索引本质上是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.
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/350519/viewspace-1038606/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/350519/viewspace-1038606/