默认情况下,Oracle使用创建的索引。
当我更改为NLS_COMP =语言并且NLS_Sort = Binary_CI时,我得到了全表扫描。
我读过某处使用(nlssort(name,’NLS_SORT = BINARY_CI’))创建索引的地方; 会工作。
正如我下面的尝试所示,没有那么多。即使我强行执行,性能似乎也不是我所期望的。这是一个微不足道的示例,我想为具有数百万行的表解决此问题,因此全表扫描将很糟糕。
所以问题是如何建立索引以便使用索引。
谢谢
-设置X
create table x ( name varchar2(30)) ; insert into x select table_name from all_tables; create index x_ix on x (name); create index x_ic on x (nlssort(name, 'NLS_SORT=BINARY_CI')); /
ALTER SESSION SET NLS_COMP=BINARY; ALTER SESSION SET NLS_SORT=BINARY; / set autotrace on / select * from X where NAME like 'x%'; --0 rows selected -- --------------------------------------------------------------------------- --| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- --| 0 | SELECT STATEMENT | | 1 | 17 | 1 (0)| 00:00:01 | --|* 1 | INDEX RANGE SCAN| X_IX | 1 | 17 | 1 (0)| 00:00:01 | --------------------------------------------------------------------------- / set autotrace off /
-语言
ALTER SESSION SET NLS_COMP=LINGUISTIC; ALTER SESSION SET NLS_SORT=BINARY_CI; / set autotrace on / select * from X where NAME like 'x%'; --13 rows selected -- ---------------------------------------------------------------------------- --| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ---------------------------------------------------------------------------- --| 0 | SELECT STATEMENT | | 1 | 17 | 3 (0)| 00:00:01 | --|* 1 | TABLE ACCESS FULL| X | 1 | 17 | 3 (0)| 00:00:01 | ---------------------------------------------------------------------------- select /*+ INDEX( X X_IX ) */ * from X where NAME like 'x%'; --13 rows selected -- --------------------------------------------------------------------------- --| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------- --| 0 | SELECT STATEMENT | | 1 | 17 | 9 (0)| 00:00:01 | --|* 1 | INDEX FULL SCAN | X_IX | 1 | 17 | 9 (0)| 00:00:01 | --------------------------------------------------------------------------- select /*+ INDEX( X X_IC ) */ * from X where NAME like 'x%'; --13 rows selected -- -------------------------------------------------------------------------------------- --| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------------- --| 0 | SELECT STATEMENT | | 1 | 17 | 448 (1)| 00:00:06 | --|* 1 | TABLE ACCESS BY INDEX ROWID| X | 1 | 17 | 448 (1)| 00:00:06 | --| 2 | INDEX FULL SCAN | X_IC | 1629 | | 8 (0)| 00:00:01 | -------------------------------------------------------------------------------------- / set autotrace off /
由于的Oracle 11g -像CAN使用语言索引。该文档已修改为:
The SQL functions MAX( ) and MIN( ) cannot use linguistic indexes when NLS_COMP is set to LINGUISTIC
注意,他们删除了“以及LIKE运算符”部分。