【问题标题】:Insert into a temp table is to slow插入临时表会变慢
【发布时间】:2014-04-11 18:05:04
【问题描述】:

我想知道为什么如果我从我的过程中创建了一个临时表,那么插入其中的速度比我在我的过程中创建该临时表要慢。 举个例子:

create table #Test (col1 varchar(max))
go
create proc dbo.test
as
begin
    truncate table #Test
    insert into #Test
    select 'teste'
    FROM sys.tables
    cross join sys.columns
end
go
exec dbo.test
go

create table #Test2 (col1 varchar(max))
go
truncate table #Test2
insert into #Test2
select 'teste'
FROM sys.tables
cross join sys.columns

在测试中,我们得到持续时间 71700,读取 45220,CPU 26052 在 test2,我们得到持续时间 49636,读取 45166,cpu 24960

最好的问候

【问题讨论】:

  • 你的问题是?
  • 为什么会这样。如果我从我的过程中创建了一个临时表,那么插入其中的速度比我在我的过程中创建该临时表要慢。

标签: sql-server performance insert temp-tables


【解决方案1】:

在逻辑读取和 CPU 几乎相等的情况下(您应该多次运行测试并确定平均值),这可能是冷缓存与热缓存或阻塞的问题。检查输出 od set statistics io on 的物理读取和预读,看看发生了什么。

【讨论】:

    猜你喜欢
    • 2013-09-05
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 2019-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-31
    相关资源
    最近更新 更多