覆盖索引

覆盖索引(covering indexex):一个索引包含了(或覆盖了)满足查询结果的数据

 

如:

create table <script src="http://hi.images.csdn.net/js/blog/tiny_mce/themes/advanced/langs/zh.js" type="text/javascript"></script> <script src="http://hi.images.csdn.net/js/blog/tiny_mce/plugins/syntaxhl/langs/zh.js" type="text/javascript"></script> orders
(
id int identity(1, 1),
customer_id int,
product_id int,
quantity int
primary key (id)
)
go
create table product
(
id int identity(1, 1),
product_name varchar(30)
)
go
--创建覆盖索引
create index idx on orders(id, customer_id, product_id, quantity)
go
insert into orders
select 2001, 1, 100
go
insert into product
select '机器'
go

set showplan_text on
go
select o.id, o.customer_id, o.product_id, o.quantity
from orders o
where o.id = 1
go
select o.id, p.product_name, o.quantity
from orders o
inner join product p on p.id = o.product_id
where o.id = 1
go
set showplan_text off

 

上列中因为访问orders使用所覆盖索引,所以不会再去访问orders的实际表,如果此时orders在其它进程中处于写入状态也不会对orders的覆盖索引访问产生阻塞,记住两点:

  1. 写操作时,不会对相关的索引加锁,而只会对相关的数据加锁。
  2. 读操作时,只会对其访问路径中发现和使用的对象加锁(例如索引、数据行等)。

相关细节参见:http://www.zxbc.cn/html/20080726/63700_6.html

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值