使用1行表而不是局部变量,是否会显着降低性能或其他不利影响?
而不是:
Declare @DT date = getdate()
使用:
Select convert(date, getdate()) as DT into #DT
我想要这样做的原因是代码测试。当我只想运行一大块代码时,如果代码说100行,但需要运行几个声明,那就太烦人了。
而不是:
Line 104 select
Line 105 somecolumn
Line 106 where datadate = @DT
-- MUST DECLARE SCALAR @DT, EVEN THOUGH LINES 1-103 WERE PREVIOUSLY RUN
使用:
Line 104 select
Line 105 somecolumn
Line 106 where datadate = (select DT from #DT)
-- NO ISSUE EXECUTING ONLY THESE 3 LINES, SINCE LINES 1-103 WERE PREVIOUSLY RUN
我只需知道执行时间是否相同,准确性如何。我知道子查询会一遍又一遍地运行,但是因为#DT是一行(和1列)什么时候会开始滞后?