首页 > 开发 > 综合 > 正文

SQL并行与否的性能差异

2024-07-21 02:49:15
字体:
来源:转载
供稿:网友
SQL并行与否的性能差异

比较两种代码,核心代码相同,其中一个使用变量保存查询出的结果,另一个直接输出。使用同一变量时,强迫SQL放弃了并行,使用了循环。

 

测试结果

表'#1699586C'。扫描计数1,逻辑读取186 次,物理读取0 次,预读0 次,lob 逻辑读取0 次,lob 物理读取0 次,lob 预读0 次。

 

SQL Server 执行时间:

CPU 时间= 0 毫秒,占用时间= 335 毫秒。

 

SQL Server 执行时间:

CPU 时间= 33954 毫秒,占用时间= 35315毫秒。

 

表'#1699586C'。扫描计数1,逻辑读取186 次,物理读取0 次,预读0 次,lob 逻辑读取0 次,lob 物理读取0 次,lob 预读0 次。

 

SQL Server 执行时间:

CPU 时间= 93 毫秒,占用时间= 167毫秒

 

 

 

  1. SELECT @bin = @bin + CASE @withDeviceID
  2.                                         WHEN 0 THEN 0x
  3.                                         ELSECAST (deviceid ASBINARY(16))
  4.                                       END
  5.                         + dbo.updatesum(dbo.long2Bin_4byte(CardSerialNo)
  6.                                         + dbo.long2Bin_4byte(Tac)
  7.                                         + dbo.long2Bin(CardSeq)
  8.                                         + dbo.int2Bin(HardwareNo)
  9.                                         + CAST (CardType ASBINARY(1))
  10.                                         + CAST (TranscationType ASBINARY(1))
  11.                                         + CAST (Station ASBINARY(1))
  12.                                         + dbo.int2Bin_3byte(PReBalance)
  13.                                         + dbo.int2Bin_3byte(Amount)
  14.                                         + dbo.time2utcbin(TranscationTime)
  15.                                         + CAST (DeviceType ASBINARY(1))
  16.                                         + dbo.int2Bin(TotalIntegral)
  17.                                         + dbo.short2bin(Integral)
  18.                                         + dbo.int2Bin(AccountCount)
  19.                                         + CAST (Account ASBINARY(1))
  20.                                         + dbo.int2Bin(Balance)
  21.                                         + dbo.int2bin_3byte(Price)
  22.                                         + CAST (Period ASBINARY(1))
  23.                                         + dbo.int2Bin(Device)
  24.                                         + CAST (InOutFlag ASBINARY(1))
  25.                                         + CAST (UpDownFlag ASBINARY(1))
  26.                                         + dbo.short2bin(Operator)
  27.                                         + CAST (CardStandard ASBINARY(1))
  28.                                         + CAST (TranscationMode ASBINARY(1))
  29.                                         + CAST (0 ASBINARY(1))
  30.                                         + CAST(0 ASBINARY(7)) + 0x55, 0, 62,
  31.                                         63)
  32.                 FROM @record

 

 

  1. SELECTCASE 1
  2.           WHEN 0 THEN 0x
  3.           ELSECAST (deviceid ASBINARY(16))
  4.         END + dbo.updatesum(dbo.long2Bin_4byte(CardSerialNo)
  5.                             + dbo.long2Bin_4byte(Tac) + dbo.long2Bin(CardSeq)
  6.                             + dbo.int2Bin(HardwareNo)
  7.                             + CAST (CardType ASBINARY(1))
  8.                             + CAST (TranscationType ASBINARY(1))
  9.                             + CAST (Station ASBINARY(1))
  10.                             + dbo.int2Bin_3byte(PreBalance)
  11.                             + dbo.int2Bin_3byte(Amount)
  12.                             + dbo.time2utcbin(TranscationTime)
  13.                             + CAST (DeviceType ASBINARY(1))
  14.                             + dbo.int2Bin(TotalIntegral)
  15.                             + dbo.short2bin(Integral)
  16.                             + dbo.int2Bin(AccountCount)
  17.                             + CAST (Account ASBINARY(1))
  18.                             + dbo.int2Bin(Balance) + dbo.int2bin_3byte(Price)
  19.                             + CAST (Period ASBINARY(1)) + dbo.int2Bin(Device)
  20.                             + CAST (InOutFlag ASBINARY(1))
  21.                             + CAST (UpDownFlag ASBINARY(1))
  22.                             + dbo.short2bin(Operator)
  23.                             + CAST (CardStandard ASBINARY(1))
  24.                             + CAST (TranscationMode ASBINARY(1))
  25.                             + CAST (0 ASBINARY(1)) + CAST(0 ASBINARY(7))
  26.                             + 0x55, 0, 62, 63)
  27. FROM @record

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表