CTOCIO IT专家网

天极传媒 比特网 | 天极网 | IT专家网 | IT商网 | 52PK游戏网 | 手机天极 | IT分众 |
IT专家网搜索

数据库 | Oracle | DB2 | SQL Server | MySQL | 商业智能 | BI | DBA | Sybase| SQL Server 2008

您现在的位置: IT专家网 > 数据库子站 > 数据库技巧

避免在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%。

共4页。 9 1 2 3 4 :

网友评论

笔名 
请您注意:遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。    IT专家网友拥有管理笔名和留言的一切权利。
  • 周排行榜
  • 月排行榜

邮件订阅


    
天极服务 | 关于我们 | 网站律师 | 加入我们 | 联系我们 | 广告业务 | 友情链接 | 我要挑错
All Rights Reserved, Copyright 2004-2008, Ctocio.com.cn
渝ICP证B2-20030003号 如有意见请与我们联系 powered by 天极内容管理平台CMS4i