我最近一直在将大量历史数据加载到sql数据库中。为此,我在IS中运行了一个Foreach循环容器,该容器在查询数据之前将记录插入sql服务器的登台表中。从第一个表中插入记录花费了几个小时,但是一旦将记录全部插入到临时表中(大约200,000条记录),查询只需要花费几秒钟即可运行。我在具有完全相同的文件类型和数据结构的另一个文件夹上运行了相同的过程,并且循环容器花了将近24小时才能将大约250,000条记录插入到临时表中(可能大约正确)。当我这次运行查询时,它运行了一个多小时,在这一点上我不得不取消查询,因为sql server使用98%的内存和50%的磁盘,完全束缚了我。为什么它对于前200,000条记录完美地起作用,而对后250,000条记录却不完美?我的查询代码在下面列出。 “ rawdatadtn”是登台表的名称。
这是查询计划:https://www.brentozar.com/pastetheplan/?id=S1tWCb1AV
insert into BOLparseA
select
substring(longstring, 1, 3) as SenderCodeA,
substring(longstring, 4, 13) as BOLProvRecKeyA,
substring(longstring, 17, 1) as RecTypeA,
substring(longstring, 18, 4) as FVersion,
substring(longstring, 22, 1) as BOLtype,
substring(longstring, 23, 3) as ReceiverCode,
substring(longstring, 26, 9) as SPLC,
substring(longstring, 35, 9) as TCN,
substring(longstring, 44, 16) as BOLnbr,
substring(longstring, 60, 2) as BOLversion,
substring(longstring, 62, 8) as StartLoadDate,
substring(longstring, 70, 4) as StartLoadTime,
substring(longstring, 74, 8) as EndLoadDate,
substring(longstring, 82, 4) as EndLoadTime,
substring(longstring, 86, 9) as FSTS,
substring(longstring, 95, 8) as Authnbr,
substring(longstring, 103, 3) as ThirdParty,
substring(longstring, 106, 14) as Cosigneenbr,
substring(longstring, 120, 4) as CarrierCode,
substring(longstring, 124, 9) as CarrierFEIN,
substring(longstring, 133, 1) as FEINtype,
substring(longstring, 134, 20) as VehDriverName,
substring(longstring, 154, 1) as VehType,
substring(longstring, 155, 20) as VehNbr,
substring(longstring, 175, 20) as ContainerNbr1,
substring(longstring, 195, 20) as ContainerNbr2,
substring(longstring, 215, 30) as POnbr,
substring(longstring, 245, 16) as ReleaseNbr,
substring(longstring, 261, 32) as SupContractNbr,
substring(longstring, 293, 1) as SplitLoadFlag,
substring(longstring, 294, 10) as ShipperInfo,
substring(longstring, 304, 1) as AuthLoad,
substring(longstring, 305, 2) as DestSTcode,
substring(longstring, 307, 30) as DestCounty,
substring(longstring, 337, 30) as DestCity,
substring(longstring, 367, 9) as DestZip,
substring(longstring, 376, 2) as ProdTransmitted
from rawdatadtn
where substring(longstring, 17, 1) = 'A'
insert into BOLparseB
select
substring(longstring, 1, 3) as SenderCodeB,
substring(longstring, 4, 13) as BOLProvRecKeyB,
substring(longstring, 17, 1) as RecTypeB,
substring(longstring, 18, 3) as BatchID,
substring(longstring, 21, 1) as ProdCodeType,
substring(longstring, 22, 3) as PIDXCode,
substring(longstring, 25, 20) as AdditiveCode,
substring(longstring, 45, 10) as GrossQty,
substring(longstring, 55, 1) as GrossCreditSign,
substring(longstring, 56, 10) as NetQty,
substring(longstring, 66, 1) as NetCreditSign,
substring(longstring, 67, 4) as Temperature,
substring(longstring, 71, 1) as TempType,
substring(longstring, 72, 4) as Gravity,
substring(longstring, 76, 2) as BlendIndicator,
substring(longstring, 78, 3) as Unit,
substring(longstring, 81, 32) as CompContractNbr,
substring(longstring, 113, 9) as SubCompanyID
from
rawdatadtn
where
substring(longstring, 17, 1) = 'B'
insert into BOLArchive
select BOLparseA. *, BOLparseB. *
from BOLparseA
full join BOLparseB on BOLparseA.BOLProvRecKeyA = BOLparseB.BOLProvRecKeyB