在SQL2k降序索引上使用中bug
2024-07-21 02:10:54
供稿:網友
解決sql2k降序索引上使用對比條件更新或刪除的bug我在sql server 2000 enterprise 和 personal 都試過了, 每次都這樣。:(
詳細情況看我的回貼:
sql server 7.0 中的確沒有問題, sql 2000 中(enterprise 和 personal版本都可以),
表要有聚簇索引,并且索引的順序是降序,
例如 按下列ddl sql 建立的表
create table [atype] (
[aid] [int] not null ,
[name] [varchar(20)] not null ,
constraint [pk_datetype] primary key clustered
([aid] desc) on [primary] ,
) on [primary]
添一些數據后, aid 分別分布在1-100之間
insert into [atype] values(1,'a')
insert into [atype] values(50,'b')
insert into [atype] values(100,'c')
做
select from atype where aid < 50
go
delete from atype where aid < 50
go
select from atype where aid < 50
最后一句查詢仍然有記錄輸出. :(
by 怡紅公子
報告已經發送給mssql開發小組,他們承認這一錯誤。
在沒有新的補丁出來之前,給出以下建議:
不要在單列上使用降序索引,因為這并沒有在性能上帶來好處,僅僅是省略了order by field desc幾個字而已,用qa的show plan看一下就知道了,不管有沒有order by或者不管是asc還是desc,都沒有這項開銷的(在聚簇索引上)。
降序索引一般是用于復合索引的,這可能是這個bug出現的原因。
原文:
note that there is no need to create a descending index on a single column because sql server can traverse
an ascending index backwards when appropriate. descending is normally used only in composite indexes.
this is probably why the bug surfaces here