【问题标题】:SSIS Execution Cause Growing TempDBSSIS 执行导致 TempDB 增长
【发布时间】:2021-01-24 12:15:13
【问题描述】:

我有一个包,其中包含一个 Foreach 循环,在它里面我有任务运行程序执行,它执行一个没有 Order by 或索引的查询 我在里面执行的代码是:

  declare @Sdate int 
set @Sdate=?
declare @Edate int 
set @Edate=?

---------------ActiveShowingType-------
update att.FactWorkPeriod
set ActiveShowingType=0 
update w 
set w.ActiveShowingType=case when w.ShowingTypeId=c.ShowingTypeID then 1
else 0 end
from att.FactWorkPeriod w 
inner join att.DimCode c on w.CodeId=c.[CodeId]
where w.DateSK between @Sdate and @Edate
 ----------------------  HasContract-------------------
  declare @YearStart char(4)=(select min (YearIR) from att.FactWorkPeriod w 
 inner join gnr.DimDate d on w.DateSK=d.DateSK)
 update w1 
set w1.HasContract =case when t.PersonSK is not null then 1 else 0 end 
from att.FactWorkPeriod w1
inner join (
select distinct
(select max(datesk) from gnr.dimdate dd where dd.yearmonthIR=d.YearMonthIR)as dateSK,
p.PersonSK
from gnr.DimDate d 
left join  att.DimPerson p on d.FullDateIR between p.EmployDate and p.ExitDate
 where  YearIR between @YearStart and (select YearIR from gnr.DimDate where IsToday=1)  and d.LastDayOfMonth=1
 )t on t.dateSK=w1.DateSK and t.PersonSK=w1.PersonSK
 where w1.DateSK between @Sdate and @Edate
 --------------------ContractTypeId------------------
 if (case when (select Count(isnull(GroupId ,0)) from kasrawarehouse.att.DimGroup)<1 then 0 else 1 end= 1 )
 begin 
 update w2
 set w2.ContractTypeId=t.ContractTypeId
  from att.FactWorkPeriod w2
 inner join ( select w3.DateSK , w3.PersonSK , case when gp.groupid is not null then 0
else 1 end as ContractTypeId from att.FactWorkPeriod w3
 inner join att.DimPerson p on w3.PersonSK=p.PersonSK
inner join gnr.DimDate d on d.DateSK=w3.DateSK
left join KasraForWarehouseConvert.gnr.GroupPerson gp 
 ON d.FullDateIR BETWEEN gp.SDate COLLATE Arabic_CI_AS AND gp.EDate COLLATE Arabic_CI_AS
 and gp.PersonelID=p.PersonBK
 and gp.GroupID in (select distinct GroupId from [Att].[DimGroup])--='15027' 
where d.LastDayOfMonth=1  )t on t.DateSK=w2.DateSK and t.PersonSK=w2.PersonSK
 where w2.DateSK between @Sdate and @Edate
 end 
  ---------------  به روز رسانی واحد سازمانی که از بین رفته ------
 update w4
set w4.OrgSK='999999999'
 from att.FactWorkPeriod w4
inner join (select distinct OrgSK from att.FactWorkPeriod w5
where w5.OrgSK not in (select distinct OrgIdPreffix from att.DimOrg)) t on t.OrgSK=w4.OrgSK
 where w4.DateSK between @Sdate and @Edate
 -------- پاک کردن افرادی که پاک شده اند -------
delete  from att.FactWorkPeriod 
where PersonSK not in (select distinct PersonSK from att.DimPerson)
and DateSK between @Sdate and @Edate

并且在执行期间 tempDb 快速增长并在驱动器已满时停止。我如何执行它而不将它存储在 tempDb 上并且只插入和更新数据? PS-我在 Sql Server 中运行代码,它可以正常工作。

【问题讨论】:

  • 如果您的存储设备要填充多小,或者您尝试在一次事务中处理多少数据?您不能使用tempdb 停止 SQL Server,如果它觉得需要使用它,用于创建工作表之类的东西,它会使用它。

标签: sql sql-server visual-studio ssis


【解决方案1】:

TempDB 是一个优化的存储位置,SQL 引擎可以根据需要执行的操作来选择使用它来处理查询/操作。发生这种情况时,它的使用是必要的,并且 TempDB 文件的增长是正常的。您可以在 Microsoft Docs TempDB Database 中详细了解 TempDB 中具体存储的内容以及 SQL 引擎如何使用它。

在 TempDB 中的对象不再存在后,由 TempDB 后面的文件消耗的存储空间可能会持续存在(因为 SQL 引擎本身不会将消耗的空间释放回磁盘),但会被重新使用未来使用 TempDB 的操作(基本上相同的字节将在磁盘上被覆盖)。

因此,您不必太担心您所看到的增长,因为它既是必要的,又在未来的操作中重复使用(当应用相同的工作负载时,您的 TempDB 不会呈指数级增长)。

您可以限制它的使用的唯一方法是将 TsmpDB 的文件预先增长到您想要限制它的大小,并减少这些文件所在的磁盘上分配的可用空间,这样就什么都没有了留下来成长。但这将是一种非常糟糕的做法,并且可能会导致您的查询和流程出现许多性能问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-25
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    • 2023-03-22
    • 2020-07-11
    相关资源
    最近更新 更多