首页 > 代码库 > SqlServer性能优化索引(五)

SqlServer性能优化索引(五)

导入表结构:

select * into ProductCategory from AdventureWorksDW2014.dbo.DimProductCategory
select * into Product from AdventureWorksDW2014.dbo.DimProduct

 

开启磁盘io:

set statistics io on
select EnglishProductName,StandardCost,Color,Size,Weight from Product
where size>‘M‘--0.189 io:251
set statistics io off

 技术分享

 

非聚簇索引:

创建的语句:
create nonclustered index nc_product_size on product(size)

 再次执行上面的查询代码(提高了三倍):

set statistics io on
select EnglishProductName,StandardCost,Color,Size,Weight from Product
where size>‘M‘   --0.054 io:19
set statistics io off

 技术分享

建立覆盖索引:

create nonclustered index nc_product_size1 on product(size) include(EnglishProductName,
StandardCost,Color,Weight)

再次执行上述语句:

set statistics io on
select EnglishProductName,StandardCost,Color,Size,Weight from Product
where size>‘M‘   --0.003 io:2
set statistics io off

 数据库会自动选择索引:

技术分享

技术分享

 

SqlServer性能优化索引(五)