避免在SQL Server表中产生冗余索引
作者: Echo, 出处:IT专家网, 责任编辑: 李书琴,
2008-03-14 11:10
我们可以看到比较有趣的现象。第一个和第二个查询使用了索引ix_customer_lastname_activesw。第三个查询使用了索引ix_customer_lastname_firstname。进行最后一个查询的时候,优化器同样选择使用了索引ix_customer_lastname_firstname,并且查找了activesw值。你应该已经注意到,优化器并没有选用索引index ix_customer_lastname来进行上述任何查询。这个索引根本没有被利用,又占用磁盘空间。
现在我们来删除上面这些索引,添加一个单独的索引来满足上述四个查询。
| drop index dbo.Customer.ix_customer_lastname drop index dbo.Customer.ix_customer_lastname_firstname drop index dbo.Customer.ix_customer_lastname_activesw create index ix_customer_lastname on dbo.Customer(lastname, firstname, activesw) |
如果我们重新运行sp_spaceused命令,我们会看到表占用的空间已经减少了超过100%。
- 本文关键词:

