• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    對Sql Server 的性能測試數據解密

    發布: 2010-2-20 10:01 | 作者: 網絡轉載 | 來源: 領測軟件測試網 | 查看: 117次 | 進入軟件測試論壇討論

    領測軟件測試網

      以下是本性能試驗中使用的一些代碼,是我在Tsuranoff先生的代碼的基礎上改進的結果.

      --------create table and populate data

      CREATE TABLE [dbo].[NUM]

      ([n] int NOT NULL, s varchar(128) NULL, PRIMARY KEY CLUSTERED([n] ASC))

      go

      -- populate data

      set nocount on

      declare @n int, @i int

      set @n=1000000

      set @i = 0

      while @n>0 begin

      if @i = 0 begin tran

      insert into dbo.NUM

      select @n, convert(varchar,@n + @i * 2)

      set @n=@n-1

      set @i = (@i + 1) % 1000

      if @i = 0 commit

      end

      GO

      ---Create stored procs

      SET ANSI_NULLS ON

      GO

      SET QUOTED_IDENTIFIER ON

      GO

      Create procedure [dbo].[T1]

      @total int

      as begin

      create table #T (n int, s varchar(128))

      set nocount on

      insert into #T select n,s from dbo.NUM

      where n%100>0 and n<=@total

      declare @res varchar(128)

      select @res=max(s) from dbo.NUM

      where n<=@total

      and not exists(select * from #T where #T.n=NUM.n)

      return @res

      end

      go

      ----------

      CREATE procedure [dbo].[T2]

      @total int

      as

      begin

      create table #T (n int primary key, s varchar(128))

      set nocount on

      insert into #T select n,s from dbo.NUM

      where n%100>0 and n<=@total

      declare @res varchar(128)

      select @res=max(s) from dbo.NUM

      where n<=@total and

      not exists(select * from #T where #T.n=NUM.n)

      option(merge join) -- Query hint

      return @res

      end

      go

      -------

      CREATE procedure [dbo].[T3]

      @total int

      as begin

      create table #T (n int, s varchar(128))

      set nocount on

      insert into #T select n,s from dbo.Num

      where n%100>0 and n<=@total

      create clustered index Tind on #T (n)

      declare @res varchar(128)

      select @res=max(s) from dbo.Num

      where n<=@total and

      not exists(select * from #T

      where #T.n=NUM.n)

      return @res

      end

      go

      --------

      CREATE procedure [dbo].[V1]

      @total int

      as begin

      declare @V table (n int, s varchar(128))

      set nocount on

      insert into @V select n,s from dbo.NUM

      where n%100>0 and n<=@total

      declare @res varchar(128)

      select @res=max(s) from dbo.NUM

      where n<=@total and

      not exists(select * from @V V

      where V.n=NUM.n)

      return @res

      end

      go

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

      CREATE procedure [dbo].[V2]

      @total int

      as begin

      declare @V table (n int primary key, s varchar(128))

      set nocount on

      insert into @V select n,s from dbo.NUM

      where n%100>0 and n<=@total

      declare @res varchar(128)

      select @res=max(s) from dbo.NUM

      where n<=@total and

      not exists(select * from @V V where V.n=NUM.n)

      option(merge join) -- query hint

      return @res

      end

      go

      --------Test Code

      declare @t1 datetime, @n int, @i int, @total int

      set @total = 50000 -- should less than 1,000,000

      set @n=10 --重復次數,先取小值,逐漸加大,以免用時過長

      print @total

      -- test T1

      set @t1=getdate()

      set @i = 0

      while @i < @n begin

      exec dbo.T1 @total

      set @i=@i + 1

      end

      select datediff(ms,@t1,getdate()) * 1.0 / @n

      -- test T2

      set @t1=getdate()

      set @i = 0

      while @i < @n begin

      exec dbo.T2 @total

      set @i=@i + 1

      end

      select datediff(ms,@t1,getdate()) * 1.0 / @n

      -- test T3

      set @t1=getdate()

      set @i = 0

      while @i < @n begin

      exec dbo.T3 @total

      set @i=@i + 1

      end

      select datediff(ms,@t1,getdate()) * 1.0 / @n

      -- test V1

      set @t1=getdate()

      set @i = 0

      while @i < @n begin

      exec dbo.V1 @total

      set @i=@i + 1

      end

      select datediff(ms,@t1,getdate()) * 1.0 / @n

      -- test V2

      set @t1=getdate()

      set @i = 0

      while @i < @n begin

      exec dbo.V2 @total

      set @i=@i + 1

      end

      select datediff(ms,@t1,getdate()) * 1.0 / @n

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

      注意,在T2和V2的代碼中使用了option(merge join),這時再來看它們的查詢計劃圖,就發現,T2和V2現在使用完全相同的查詢計劃.

      帶有query hint的T2的查詢計劃:

      帶有query hint的V2的查詢計劃:

      現在,T2和V2的查詢計劃相同,再進行性能比較試驗,就能得出完全合理的實驗數據.

    N

    T1

    T2

    T3

    V1

    V2

    10011.9811.38.46.8
    1000166233623919
    1000036630438417695290
    100000333837403653太長3586
    500000210402509618076太長20036
    1000000377168778368246太長40956

      Note:單位為ms,只有T2和V2的數據是可比的,因為它們的execution plan是相同的.

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/

    22/2<12

    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>