zoukankan      html  css  js  c++  java
  • SqlServer性能优化 通过压缩与计算列提高性能(十一)

    压缩:

       1.压缩的对象

            1.表   2.索引(非聚集索引手工做)   3.备份(手工做)

       2.对性能影响

            1.提高IO性能     2.降低CPU性能

     行压缩:

         1.对null值不占用空间

         2.对Numeric值不占用空间

    页压缩:

         1.行压缩

         2.前缀压缩

         3.字典压缩

       实例:

    准备表数据:

    1
    2
    3
    4
    5
    select * from SalesOrderDetail
     
    select * into ComOrderDetail from SalesOrderDetail
     
    sp_spaceused 'ComOrderDetail'--data:4696k

     磁盘io:

    1
    2
    3
    set statistics io on
     select * from ComOrderDetail  --0.57
    set statistics io off

     压缩:

    1
    2
    alter table ComOrderDetail rebuild partition=all
        with(data_compression=page)

     压缩后表空间的使用情况:

    1
    2
    -- 表空间的使用情况
    sp_spaceused 'ComOrderDetail'  --data:1376k

     

    对非聚集索引的压缩:

     持久化的计算列:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    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

     

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
        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

     

  • 相关阅读:
    linux解释器、内建和外建命令
    linux文件cat/tac/more/less/head/tail/find/vimdiff
    zk和eureka的区别(CAP原则)
    Hystrix断路器中的服务熔断与服务降级
    windows 查看端口被占用,解除占用
    JS中操作JSON总结
    Ajax请求($.ajax()为例)中data属性传参数的形式
    通过 Ajax 发送 PUT、DELETE 请求的两种实现方式
    feignclient发送get请求,传递参数为对象
    Spring Boot 和 Spring Cloud Feign调用服务及传递参数踩坑记录
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/9558207.html
Copyright © 2011-2022 走看看