index(col_name,0)是不是有个Bug

[复制链接]
查看11 | 回复4 | 2006-10-13 01:01:52 | 显示全部楼层 |阅读模式
index(,constant_value)
使用上面的格式创建的索引可以存储NULL,
但是在使用中,如果应用Rownum = 1 则返回空,这是不是个Bug?
如下:
[php]
create table test(id int,name varchar2(20));
create index idx on test(id,1);
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE10.2.0.1.0Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> create table test(id int,name varchar2(20));
Table created.
SQL> create index idx on test(id,1);
Index created.
SQL> insert into test values(14,'abc');
1 row created.
SQL> insert into test values(null,'Oracle');
1 row created.
SQL> insert into test values(3,'Microsoft');
1 row created.
SQL> insert into test values(null,null);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from test;
ID NAME
---------- --------------------
14 abc
Oracle
3 Microsoft

SQL> select count(*) from test;
COUNT(*)
----------
4
SQL> analyze table test compute statistics;
Table analyzed.
SQL> analyze index idx compute statistics;
Index analyzed.
SQL> set feedback on
SQL> set autotrace on
SQL> select /*+ index(test idx) */ *
2from test where id is null;
ID NAME
---------- --------------------
Oracle

2 rows selected.

Execution Plan
----------------------------------------------------------
Plan hash value: 4092295894
------------------------------------------------------------------------------------
| Id| Operation
| Name | Rows| Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT
|| 2 |14 | 2 (0)| 00:00:01 |
| 1 |TABLE ACCESS BY INDEX ROWID| TEST | 2 |14 | 2 (0)| 00:00:01 |
|*2 | INDEX RANGE SCAN
| IDX| 2 | | 1 (0)| 00:00:01 |
------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("ID" IS NULL)

Statistics
----------------------------------------------------------

0recursive calls

0db block gets

4consistent gets

0physical reads

0redo size
501bytes sent via SQL*Net to client
385bytes received via SQL*Net from client

2SQL*Net roundtrips to/from client

0sorts (memory)

0sorts (disk)

2rows processed
---这里应用了索引,并返回两条记录
SQL> select /*+ index(test idx) */ * from test
2where id is null and rownum = 1;
no rows selected

Execution Plan
----------------------------------------------------------
Plan hash value: 2182711683
-------------------------------------------------------------------------------------
| Id| Operation
| Name | Rows| Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT
|| 1 | 7 | 2 (0)| 00:00:01 |
|*1 |COUNT STOPKEY
|| | |
|
|
| 2 | TABLE ACCESS BY INDEX ROWID| TEST | 1 | 7 | 2 (0)| 00:00:01 |
|*3 |INDEX RANGE SCAN
| IDX| 1 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
3 - access("ID" IS NULL AND ROWNUM=1)
filter(ROWNUM=1)

Statistics
----------------------------------------------------------

1recursive calls

0db block gets

1consistent gets

0physical reads

0redo size
325bytes sent via SQL*Net to client
374bytes received via SQL*Net from client

1SQL*Net roundtrips to/from client

0sorts (memory)

0sorts (disk)

0rows processed
---这里应用了索引但是返回null.
SQL> select /*+ index(test idx) */ * from test
2where id is null and rownum
[/php]

有metalink的同志,可以帮忙看看以下网址,方便的话把内容copy过来看看!
https://metalink.oracle.com/meta ... 98234::::P20_TARUNM,P20_CTKYCODE:6701767.922
回复

使用道具 举报

千问 | 2006-10-13 01:01:52 | 显示全部楼层
试了一下我这儿没有问题!
环境:
Red Hat 3.4.3-9.EL4 + Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
[php]
train@HUIYI(192.168.1.100)> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
PL/SQL Release 10.2.0.2.0 - Production
CORE10.2.0.2.0Production
TNS for Linux: Version 10.2.0.2.0 - Production
NLSRTL Version 10.2.0.2.0 - Production
5 rows selected.
Elapsed: 00:00:00.06
train@HUIYI(192.168.1.100)> insert into t01
2values('');
1 row created.
Elapsed: 00:00:00.03
train@HUIYI(192.168.1.100)> insert into t01
2values(1);
1 row created.
Elapsed: 00:00:00.03
train@HUIYI(192.168.1.100)> commit;
Commit complete.
Elapsed: 00:00:00.02
train@HUIYI(192.168.1.100)> create index t01_01 on t01(col01,-999);
Index created.
Elapsed: 00:00:00.11
train@HUIYI(192.168.1.100)> analyze table t01
2compute statistics
3for table
4for all indexed columns
5for all indexes
6/
Table analyzed.
Elapsed: 00:00:00.09
train@HUIYI(192.168.1.100)> set autot trace
train@HUIYI(192.168.1.100)> select * from t01
2 where col01 is null
3 and rownum = 1;
1 row selected.
Elapsed: 00:00:00.07
Execution Plan
----------------------------------------------------------
Plan hash value: 2823524914
----------------------------------------------------------------------------
| Id| Operation | Name | Rows| Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT|| 1 | 1 | 1 (0)| 00:00:01 |
|*1 |COUNT STOPKEY|| | |
|
|
|*2 | INDEX RANGE SCAN| T01_01 | 1 | 1 | 1 (0)| 00:00:01 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(ROWNUM=1)
2 - access("COL01" IS NULL)

Statistics
----------------------------------------------------------

1recursive calls

0db block gets

1consistent gets

0physical reads

0redo size
406bytes sent via SQL*Net to client
385bytes received via SQL*Net from client

2SQL*Net roundtrips to/from client

0sorts (memory)

0sorts (disk)

1rows processed
[/php]
回复

使用道具 举报

千问 | 2006-10-13 01:01:52 | 显示全部楼层
不是吧,哪位兄台再帮忙测试一下。。。
回复

使用道具 举报

千问 | 2006-10-13 01:01:52 | 显示全部楼层
问一下你这个语法是哪儿看到的,在文档上没有看到相应的语法,不太清楚原理,相当于函数索引吗?
还有如果创建create index idx on test(id,1);这样的索引,查询时id=1是不走索引的!
回复

使用道具 举报

千问 | 2006-10-13 01:01:52 | 显示全部楼层
原帖由 HuiYiSky 于 2008-1-23 09:41 发表
问一下你这个语法是哪儿看到的,在文档上没有看到相应的语法,不太清楚原理,相当于函数索引吗?
还有如果创建create index idx on test(id,1);这样的索引,查询时id=1是不走索引的!

你查一下all_index表,它的确是函数索引。
为什么不走索引咧,会走的啊,是你设计测试的数据太少的缘故吧
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行