• GUID自增ID表关联比较


    1.只有关联条件有非聚集索引

    --清空缓存
    DBCC FREEPROCCACHE  WITH NO_INFOMSGS
    DBCC FREESESSIONCACHE WITH NO_INFOMSGS
    DBCC FREESYSTEMCACHE('All') WITH NO_INFOMSGS
    DBCC DROPCLEANBUFFERS WITH NO_INFOMSGS
     
    SET NOCOUNT on
     
     
    CREATE TABLE #result
    (
     状态 varchar(20),
     [id(毫秒)] INT,
     [guid(毫秒)] INT
    )
     
    DECLARE @start INT
    DECLARE @end INT
    SET @start=1
    SET @end=30
     
    WHILE (@start<=@end)
      BEGIN      --循环开始
     
        DBCC FREEPROCCACHE
        DBCC FREESESSIONCACHE
        DBCC FREESYSTEMCACHE('All')
        DBCC DROPCLEANBUFFERS
     
        
        declare @d datetime     
        set @d=getdate()     
     
        SELECT *
          FROM BKListid
            join studentid
            on BKListid.stuid=studentid.stuid
         -- where studentid.stuname in ('刘宁','刘志华','刘莉苹','潘焕清')
       --where studentid.bzktypeid =85 and studentid.stuname like '刘%'
       where BKListid.bzktypeid =85 and studentid.stuname like '刘%'
        declare @result int     
        select  @result=datediff(ms,@d,getdate())      
       
        declare @d1 datetime     
        set @d1=getdate()     
     
        SELECT *
          FROM [BKListguid]
            join studentguid
            on BKListguid.bkguid=studentguid.stuguid
         -- where studentguid.stuname in ('刘宁','刘志华','刘莉苹','潘焕清')
      where BKListguid.bzktypeid =85 and studentguid.stuname like '刘%'
        declare @result1 int     
        select  @result1=datediff(ms,@d1,getdate())      
     
        INSERT INTO #result
            SELECT '正常',@result AS 'id(毫秒)',@result1 'guid(毫秒)'
        
     
        SET @start=@start+1
     
      END
          --循环结束
           
     
    SELECT *
      FROM #result
    UNION ALL
    SELECT '最小值',min([id(毫秒)]),min([guid(毫秒)])
      FROM #result
     
    UNION  ALL
    SELECT '平均值',AVG([id(毫秒)]),AVG([guid(毫秒)])
      FROM #result
      where [id(毫秒)] not in (select top 2 [id(毫秒)]
                              from #result
                              order by [id(毫秒)] desc)
        and [id(毫秒)] not in (select top 2 [id(毫秒)]
                              from #result
                              order by [id(毫秒)])
        and [guid(毫秒)] not in (select top 2 [guid(毫秒)]
                                from #result
                                order by [guid(毫秒)] desc)
        and [guid(毫秒)] not in (select top 2 [guid(毫秒)]
                                from #result
                                order by [guid(毫秒)])
    UNION ALL
    SELECT '最大值',max([id(毫秒)]),max([guid(毫秒)])
      FROM #result
     
     
    --DROP TABLE #result


    --CREATE  INDEX stuname ON studentid(stuname)
    --CREATE  INDEX stuname ON studentguid(stuname)

    /*
    CREATE   INDEX stuid ON studentid(stuid)
    CREATE   INDEX stuid ON bklistid(stuid)

    CREATE   INDEX stuguid ON studentguid(stuguid)
    CREATE   INDEX bkguid ON bklistguid(bkguid)
    sp_helpindex   studentid
    sp_helpindex   bklistid
    sp_helpindex   studentguid
    sp_helpindex   bklistguid
    drop index studentid.stuid
    drop index bklistid.stuid
    drop index studentguid.stuguid
    drop index bklistguid.bkguid
    */


     状态 id(毫秒) guid(毫秒)
    正常 3596 5313
    正常 3450 4893
    正常 3903 4580
    正常 3736 4863
    正常 3523 4626
    正常 3813 4543
    正常 3810 4763
    正常 3763 5086
    正常 3573 4860
    正常 3536 4580
    正常 3626 4930
    正常 3736 4373
    正常 3693 4560
    正常 3566 4530
    正常 3676 4450
    正常 3730 4373
    正常 3523 5020
    正常 3736 4580
    正常 3573 4530
    正常 3860 4500
    正常 3546 4566
    正常 3863 4530
    正常 3496 4610
    正常 3490 4856
    正常 3713 4903
    正常 3753 5076
    正常 3603 6483
    正常 5963 7203
    正常 4060 4990
    正常 3940 4950
    最小值 3450 4373
    平均值 3687 4736
    最大值 5963 7203

    GUID败

    -----------------------------------------------------------------------------------------------------

    2.where 条件字段也有非聚集索引,条件少量数据

      declare @d datetime     
        set @d=getdate()     
     
        SELECT *
          FROM BKListid
            join studentid
            on BKListid.stuid=studentid.stuid
          where studentid.stuname in ('刘宁','刘志华','刘莉苹','潘焕清')
     
        declare @result int     
        select  @result=datediff(ms,@d,getdate())      
       
        declare @d1 datetime     
        set @d1=getdate()     
     
        SELECT *
          FROM [BKListguid]
            join studentguid
            on BKListguid.bkguid=studentguid.stuguid
         where studentguid.stuname in ('刘宁','刘志华','刘莉苹','潘焕清')

    ----------------------------------------------------------------------------

    状态 id(毫秒) guid(毫秒)
    正常 453 370
    正常 426 763
    正常 420 386
    正常 440 376
    正常 426 526
    正常 436 376
    正常 563 576
    正常 430 466
    正常 430 376
    正常 503 376
    正常 436 466
    正常 426 396
    正常 430 430
    正常 426 533
    正常 426 370
    正常 446 410
    正常 426 486
    正常 586 690
    正常 520 383
    正常 530 446
    正常 430 503
    正常 793 433
    正常 436 490
    正常 660 440
    正常 470 440
    正常 460 470
    正常 576 583
    正常 660 376
    正常 470 510
    正常 436 390
    正常 470 470
    正常 430 690
    正常 536 506
    正常 503 420
    正常 436 596
    正常 453 370
    正常 463 583
    正常 463 370
    正常 620 430
    正常 436 656
    正常 826 386
    正常 450 463
    正常 503 426
    正常 466 426
    正常 703 386
    正常 460 383
    正常 646 410
    正常 520 400
    正常 486 616
    正常 633 376
    正常 570 460
    正常 503 1433
    正常 600 383
    正常 440 443
    正常 650 386
    正常 510 440
    正常 550 376
    正常 1120 460
    正常 543 376
    正常 530 493
    最小值 420 370
    平均值 499 463
    最大值 1120 1433

    GUID胜

    3.where 条件字段也有非聚集索引,条件非少量数据

      declare @d datetime     
        set @d=getdate()     
     
        SELECT *
          FROM BKListid
            join studentid
            on BKListid.stuid=studentid.stuid
          where studentid.stuname in (select top 100 stuname  from SGPZ..student)
     
        declare @result int     
        select  @result=datediff(ms,@d,getdate())      
       
        declare @d1 datetime     
        set @d1=getdate()     
     
        SELECT *
          FROM [BKListguid]
            join studentguid
            on BKListguid.bkguid=studentguid.stuguid
         where studentguid.stuname in (select top 100 stuname  from SGPZ..student)
     

    ---------------------------------------------------------------------------------------

    状态 id(毫秒) guid(毫秒)
    正常 2716 1603
    正常 2436 1533
    正常 2133 1530
    正常 2160 1543
    正常 2260 1580
    正常 2220 1610
    正常 3206 1500
    正常 2200 1546
    正常 3183 2873
    正常 2140 1483
    正常 2746 2093
    正常 3590 2326
    正常 3853 2170
    正常 3140 2903
    正常 3456 2656
    正常 2183 2623
    正常 2226 1546
    正常 2270 1860
    正常 2813 1500
    正常 2403 1500
    正常 2326 2093
    正常 2230 1686
    正常 2203 1560
    正常 2670 1596
    正常 2246 1706
    正常 2586 1500
    正常 2136 1516
    正常 2460 1490
    正常 2216 1563
    正常 2340 1516
    正常 2316 1623
    正常 2213 1610
    正常 2760 2330
    正常 2236 2046
    正常 2230 1690
    正常 3373 1610
    正常 2406 2110
    正常 2273 1626
    正常 2353 1580
    正常 2263 2193
    最小值 2133 1483
    平均值 2330 1720
    最大值 3853 2903

    guid胜

    4.只有关联条件有聚集索引

       declare @d datetime     
        set @d=getdate()     
     
        SELECT *
          FROM BKListid
            join studentid
            on BKListid.stuid=studentid.stuid
           where studentid.areaorganID=36
     
        declare @result int     
        select  @result=datediff(ms,@d,getdate())      
       
        declare @d1 datetime     
        set @d1=getdate()     
     
        SELECT *
          FROM [BKListguid]
            join studentguid
            on BKListguid.bkguid=studentguid.stuguid
         where BKListguid.areaorganID=36
     
        declare @result1 int     
        select  @result1=datediff(ms,@d1,getdate())      
     

    ----------------------------------------------------------------------------------------

    状态 id(毫秒) guid(毫秒)
    正常 12433 12983
    正常 12373 12716
    正常 12620 12906
    正常 12330 13153
    正常 12126 14463
    正常 12236 12186
    正常 12433 12546
    正常 12900 13296
    正常 12543 12626
    正常 13116 12750
    正常 12626 12660
    正常 12400 12703
    正常 13160 12876
    正常 12476 14813
    正常 17870 14810
    正常 14910 14686
    正常 65936 13750
    正常 12833 12703
    正常 12320 12780
    正常 12246 12653
    正常 12653 12750
    正常 13123 13313
    正常 13610 12873
    正常 12266 13140
    正常 12776 12753
    正常 12273 13483
    正常 13550 12736
    正常 11966 13000
    正常 12106 12723
    正常 12260 12543
    正常 12506 12860
    正常 14770 12796
    正常 13420 14266
    正常 13693 13560
    正常 13260 14110
    正常 14076 12920
    正常 12903 13203
    正常 14446 13513
    正常 12336 12676
    正常 12486 13533
    最小值 11966 12186
    平均值 12824 13017
    最大值 65936 14813

    GUID败

    5.关联条件聚集索引,where 一个条件非聚集索引,数据量9W

    状态 id(毫秒) guid(毫秒)
    正常 12860 14330
    正常 14176 14643
    正常 18403 14343
    正常 13230 13593
    正常 13070 13030
    正常 12470 13226
    正常 12610 13060
    正常 12993 13610
    正常 13110 13576
    正常 12836 12906
    最小值 12470 12906
    平均值 13575 13631
    最大值 18403 14643

    GUID败

    6.关联条件聚集索引,where 两个条件两个非聚集索引,数据量5000

    状态 id(毫秒) guid(毫秒)
    正常 7553 7593
    正常 7250 7046
    正常 7523 8420
    正常 7563 8080
    正常 7766 8526
    正常 8003 8220
    正常 8600 8313
    正常 8353 7576
    正常 13043 7983
    正常 8036 8890
    最小值 7250 7046
    平均值 8369 8064
    最大值 13043 8890

    7.关联条件聚集索引,where 一个条件非聚集索引,数据量小

    状态 id(毫秒) guid(毫秒)
    正常 170 110
    正常 153 73
    正常 163 73
    正常 153 76
    正常 163 93
    正常 156 73
    正常 153 70
    正常 143 76
    正常 193 100
    正常 153 70
    正常 220 146
    正常 143 66
    正常 156 96
    正常 156 193
    正常 153 70
    正常 153 66
    正常 156 70
    正常 156 76
    正常 170 73
    正常 156 73
    最小值 143 66
    平均值 160 87
    最大值 220 193

    8.关联条件非聚集索引,where 两个条件一个聚集索引,另一个没索引

     
        declare @d datetime     
        set @d=getdate()     
     
        SELECT  *
          FROM BKListid
            join studentid
            on BKListid.stuid=studentid.stuid
           where  studentid.areaorganID=36 and  studentid.STUNAME   like '刘%'
     
        declare @result int     
        select  @result=datediff(ms,@d,getdate())      
       
        declare @d1 datetime     
        set @d1=getdate()     
     
        SELECT *
          FROM [BKListguid]
            join studentguid
            on BKListguid.bkguid=studentguid.stuguid
         where  studentguid.areaorganID=36 and  studentguid.STUNAME   like '刘%'

    -----------------------------------------------------------------------------------

    状态 id(毫秒) guid(毫秒)
    正常 3566 3126
    正常 3590 3283
    正常 3580 3320
    正常 3270 3000
    正常 3373 3360
    正常 3633 3256
    正常 3263 3266
    正常 3216 3270
    正常 3186 3230
    正常 3846 3420
    正常 3643 3140
    正常 3850 3310
    正常 3866 3843
    正常 3766 3436
    正常 3560 3373
    正常 4023 3790
    正常 4056 3690
    正常 4323 3790
    正常 4186 3750
    正常 4340 3906
    最小值 3186 3000
    平均值 3706 3427
    最大值 4340 3906

  • 相关阅读:
    常用的文件查看命令
    Linux常用快捷按键
    寒冬储粮
    创建型模式:抽象工厂
    创建型模式:工厂方法
    创建型模式:单例模式
    开闭原则
    迪米特法则
    接口隔离原则
    依赖倒置原则
  • 原文地址:https://www.cnblogs.com/qanholas/p/2526032.html
Copyright © 2020-2023  润新知