暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 语言索引

askTom 2014-11-25
222

问题描述

汤姆,

你能在这里解释什么是需要“表的访问,通过rowid”吗?为什么这里的索引不像是表的精简版呢?
rajesh@ORA11G> create table t
  2  as
  3  select a.*, object_name x
  4  from all_objects a;

Table created.

rajesh@ORA11G>
rajesh@ORA11G> insert into t
  2  select a.*,
  3     decode(rownum,1,'Ziggy',2,'ZIGGY',3,'ziggy') x
  4  from all_objects a
  5  where rownum <=3;

3 rows created.

rajesh@ORA11G> commit;

Commit complete.

rajesh@ORA11G> create index t_ind on t( nlssort(x,'nls_sort=binary_ci'));

Index created.

rajesh@ORA11G> exec dbms_stats.gather_table_stats(user,'T');

PL/SQL procedure successfully completed.

rajesh@ORA11G>
rajesh@ORA11G> alter session set nls_sort='binary_ci';

Session altered.

rajesh@ORA11G> alter session set nls_comp='linguistic';

Session altered.

rajesh@ORA11G> set autotrace on explain
rajesh@ORA11G> select x from t
  2  where x = 'ziggy';

X
------------------------------
Ziggy
ZIGGY
ziggy

3 rows selected.


Execution Plan
----------------------------------------------------------
Plan hash value: 1376202287

-------------------------------------------------------------------------------------
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
-------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT            |       |     2 |   102 |     4   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| T     |     2 |   102 |     4   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | T_IND |     2 |       |     3   (0)| 00:00:01 |
-------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   2 - access(NLSSORT("X",'nls_sort=''BINARY_CI''')=HEXTORAW('7A6967677900')
              )

rajesh@ORA11G> set autotrace off

专家解答

因为索引中包含nlssort(x) ,而不是X。您选择了X,X仅驻留在表格中


ops$tkyte%ORA11GR2> select x, nlssort( x, 'nls_sort=''BINARY_CI''')
  2    from (select 'ziggy' x from dual
  3          union all
  4          select 'ZIGGY' x from dual)
  5  /

X
-----
NLSSORT(X,'NLS_SORT=''BINARY_CI''')
-------------------------------------------------------------------------------
ziggy
7A6967677900

ZIGGY
7A6967677900


「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论