压缩:
1.压缩的对象
1.表 2.索引(非聚集索引手工做) 3.备份(手工做)
2.对性能影响
1.提高IO性能 2.降低CPU性能
行压缩:
1.对null值不占用空间
2.对Numeric值不占用空间
页压缩:
1.行压缩
2.前缀压缩
3.字典压缩
实例:
准备表数据:
select * from SalesOrderDetail select * into ComOrderDetail from SalesOrderDetail sp_spaceused 'ComOrderDetail'--data:4696k
磁盘io:
set statistics io on select * from ComOrderDetail --0.57 set statistics io off
压缩:
alter table ComOrderDetail rebuild partition=all with(data_compression=page)
压缩后表空间的使用情况:
-- 表空间的使用情况 sp_spaceused 'ComOrderDetail' --data:1376k
对非聚集索引的压缩:
持久化的计算列:
create table computetable(c1 int,c2 int,c3 as (c1+c2)*50) declare @n int set @n=1 while @n<50000 begin insert computetable values(@n,@n+1) set @n=@n+1 end sp_spaceused 'computetable' --data:1608 KB --cpu 的情况 set statistics time on select * from computetable --0.57 set statistics time off
create table computetable(c1 int,c2 int,c3 as (c1+c2)*50 persisted) declare @n int set @n=1 while @n<50000 begin insert computetable values(@n,@n+1) set @n=@n+1 end sp_spaceused 'computetable' --data:1608 KB 1824kb --cpu 的情况 set statistics time on select * from computetable set statistics time off