關於Oracle降序索引的定意及回溯

itpremier發表於2010-09-19

 降序索引本質上是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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章