我有一个 select 语句,它在 2.55 亿行的表上执行亚秒级。结果大约是 50 行。
当我尝试执行 INSERT @Tbl SELECT ...时,查询需要 45 秒。
谁可以给我解释一下这个?
这是完整的批次。计时器为 127 秒。注释掉插入行时,Timer 为 2 秒。
DBCC DROPCLEANBUFFERS
GO
DBCC FREEPROCCACHE
GO
declare @fr datetime = '2013-01-01', @to datetime = '2013-09-01'
declare @TempTable table (Title varchar(50), PlayCount int, Wt float)
declare @t1 datetime = getdate()
insert @TempTable
select Title, PlayCount, MaxCount * 1.0 / PlayCount as Weight
from (
select l.SkinDescription as Title, count(*) as PlayCount, max(count(*)) OVER() AS MaxCount
from LegalConfiguration l
join Play p on p.LegalConfigNumber = l.SequenceNumber
where p.CurrentDate between @fr and @to
group by l.SkinDescription
) sub
declare @t2 datetime = getdate()
select * from @TempTable
select datediff(ss,@t1,@t2) as timer