SQL Server数据库查询优化的常用方法总结(2)
作者:罗丽娜 出处:赛迪网 更新时间:2008-08-07 责任编辑:seward
 
 

以下是建立索引与不建立索引的一个查询效率分析:

 

Sqlserver索引与查询效率分析。

 

表 News

 

字段

Id:自动编号

Title:文章标题

Author:作者

Content:内容

Star:优先级

Addtime:时间

 

记录:100万条

测试机器:P4 2.8/1G内存/IDE硬盘

 

 

 

方案1:

主键Id,默认为聚集索引,不建立其它非聚集索引

 

select * from News where Title like '%"&abigale&"%' 
or Author like '%"&abigale&"%' order by Id desc

 

 

从字段Title和Author中模糊检索,按Id排序

查询时间:50秒

 

 

 

方案2:

主键Id,默认为聚集索引

在Title、Author、Star上建立非聚集索引

 

select * from News where Title like '"&abigale&"%' 
or Author like '"&abigale&"%' order by Id desc

 

 

 

从字段Title和Author中模糊检索,按Id排序

查询时间:2 - 2.5秒

 

 

方案3:

主键Id,默认为聚集索引

在Title、Author、Star上建立非聚集索引

 

select * from News where Title like '"&abigale&"%' 
or Author like '"&abigale&"%' order by Star desc

 

 

从字段Title和Author中模糊检索,按Star排序

查询时间:2 秒

 

 

 

方案4:

主键Id,默认为聚集索引

 

在Title、Author、Star上建立非聚集索引
select * from News where Title like '"&abigale&"%' or Author like '"&abigale&"%'

 

 

从字段Title和Author中模糊检索,不排序查询时间:1.8 - 2 秒

方案5:

主键Id,默认为聚集索引

在Title、Author、Star上建立非聚集索引

 

select * from News where Title like '"&abigale&"%'
或
select * from News where Author like '"&abigale&"%'

从字段Title 或 Author中检索,不排序查询时间:1秒

 
     
 
 
继续>>SQL Server
[第1页][第2页][下一页]
 
内容导航  
第1页SQL Server数据库查询.. 第2页SQL Server
上一篇 : SQL Server数据库查询优.. 下一篇扩展数据库系统选项实现..
 
  您要为所发表的言论的后果负责,请各位遵纪守法并注意文明用语
标题:  

[ 关于本站 ] [ 广告服务 ] [ 商务合作 ] [ 联系我们 ] [ 合作伙伴 ] [ 法律顾问 ] [ 网站地图 ]
千橡公司 京ICP证041489号 Copyright (c) 1997-2007 All Right Reserved.