我一直致力于SSIS项目的自动化报告。现在还很早,所以还没有很多事情发生。我有两个昏暗的桌子:物品,顾客。它们是从我们的ERP中复制的。
物品表设置了慢速变化尺寸,因此它应该是我们ERP中物品表的精确副本以及一些历史数据。
整体工作流程就像这样
其中两个原始数据视图与dim_Items表连接,以获取原始数据中未包含的其他信息。
其中,InvovePalueDetails视图导致在SSIS运行时锁定我的dim_Item表的大问题,而我无法找出原因。
当Load InvNotUsed Details数据流正在运行时,我看到我的dim_Items表上有一个锁,运行大约需要5-10秒。
select
object_name(p.object_id) as TableName,
resource_type, resource_description, *
from
sys.dm_tran_locks l
join sys.partitions p on l.resource_associated_entity_id = p.hobt_id
当Load InvWipValue Details数据流正在运行时,我有33个锁!!它停留在验证阶段。几分钟后它终于结束了。
当我启动visual studio或尝试修改任何内容时,我会遇到类似的行为,我不得不进入离线模式,否则我会在尝试验证时停留VS几分钟。
那么我正在做的是什么导致这些验证问题呢?这将使项目的发展变得非常困难。
项目表
CREATE TABLE [dbo].[dim_Item](
[StartDate] [datetime] NOT NULL,
[EndDate] [datetime] NULL,
[UNIQ_KEY] [char](10) NOT NULL,
[PART_CLASS] [char](8) NOT NULL,
[PART_TYPE] [char](8) NOT NULL,
[CUSTNO] [char](10) NOT NULL,
[PART_NO] [char](25) NOT NULL,
[REVISION] [char](8) NOT NULL,
[PROD_ID] [char](10) NOT NULL,
[CUSTPARTNO] [char](25) NOT NULL,
[CUSTREV] [char](8) NOT NULL,
[DESCRIPT] [char](45) NOT NULL,
[U_OF_MEAS] [char](4) NOT NULL,
[PUR_UOFM] [char](4) NOT NULL,
[ORD_POLICY] [char](12) NOT NULL,
[PACKAGE] [char](15) NOT NULL,
[NO_PKG] [numeric](5, 0) NOT NULL,
[BUYER_TYPE] [char](3) NOT NULL,
[STDCOST] [numeric](13, 5) NOT NULL,
[MINORD] [numeric](7, 0) NOT NULL,
[ORDMULT] [numeric](7, 0) NOT NULL,
[USERCOST] [numeric](11, 5) NOT NULL,
[PULL_IN] [numeric](3, 0) NOT NULL,
[PUSH_OUT] [numeric](3, 0) NOT NULL,
[STATUS] [char](8) NOT NULL,
[PERPANEL] [numeric](4, 0) NOT NULL,
[ABC] [char](1) NOT NULL,
[LAYER] [char](4) NOT NULL,
[PART_SPEC] [char](100) NOT NULL,
[PUR_LTIME] [numeric](3, 0) NOT NULL,
[PUR_LUNIT] [char](2) NOT NULL,
[KIT_LTIME] [numeric](3, 0) NOT NULL,
[KIT_LUNIT] [char](2) NOT NULL,
[PROD_LTIME] [numeric](3, 0) NOT NULL,
[PROD_LUNIT] [char](2) NOT NULL,
[PART_SOURC] [char](10) NOT NULL,
[INSP_REQ] [bit] NOT NULL,
[CERT_REQ] [bit] NOT NULL,
[CERT_TYPE] [char](10) NOT NULL,
[SCRAP] [numeric](6, 2) NOT NULL,
[SETUPSCRAP] [numeric](4, 0) NOT NULL,
[BOM_STATUS] [char](10) NOT NULL,
[BOM_LASTDT] [smalldatetime] NULL,
[SERIALYES] [bit] NOT NULL,
[LOC_TYPE] [char](10) NOT NULL,
[DAY] [numeric](1, 0) NOT NULL,
[DAYOFMO] [numeric](2, 0) NOT NULL,
[DAYOFMO2] [numeric](2, 0) NOT NULL,
[SALETYPEID] [char](10) NOT NULL,
[FEEDBACK] [text] NOT NULL,
[ENG_NOTE] [text] NOT NULL,
[BOMCUSTNO] [char](10) NOT NULL,
[LABORCOST] [numeric](13, 5) NOT NULL,
[INT_UNIQ] [char](10) NOT NULL,
[EAU] [numeric](14, 0) NOT NULL,
[REQUIRE_SN] [bit] NOT NULL,
[OHCOST] [numeric](8, 2) NOT NULL,
[PHANT_MAKE] [bit] NOT NULL,
[CNFGCUSTNO] [char](10) NOT NULL,
[CONFGDATE] [smalldatetime] NULL,
[CONFGNOTE] [text] NOT NULL,
[XFERDATE] [smalldatetime] NULL,
[XFERBY] [char](8) NOT NULL,
[PRODTPUNIQ] [char](10) NOT NULL,
[MAKE_BUY] [bit] NOT NULL,
[LABOR_OH] [numeric](8, 2) NOT NULL,
[MATL_OH] [numeric](8, 2) NOT NULL,
[MATL_COST] [numeric](13, 5) NOT NULL,
[OVERHEAD] [numeric](13, 5) NOT NULL,
[OTHER_COST] [numeric](13, 5) NOT NULL,
[STDBLDQTY] [numeric](8, 0) NOT NULL,
[USESETSCRP] [bit] NOT NULL,
[CONFIGCOST] [numeric](13, 5) NOT NULL,
[OTHERCOST2] [numeric](13, 5) NOT NULL,
[MATDT] [smalldatetime] NULL,
[LABDT] [smalldatetime] NULL,
[OHDT] [smalldatetime] NULL,
[OTHDT] [smalldatetime] NULL,
[OTH2DT] [smalldatetime] NULL,
[STDDT] [smalldatetime] NULL,
[ARCSTAT] [char](8) NOT NULL,
[IS_NCNR] [bit] NOT NULL,
[TOOLREL] [bit] NOT NULL,
[TOOLRELDT] [smalldatetime] NULL,
[TOOLRELINT] [char](8) NOT NULL,
[PDMREL] [bit] NOT NULL,
[PDMRELDT] [smalldatetime] NULL,
[PDMRELINT] [char](8) NOT NULL,
[ITEMLOCK] [bit] NOT NULL,
[LOCKDT] [smalldatetime] NULL,
[LOCKINIT] [char](8) NULL,
[LASTCHANGEDT] [smalldatetime] NULL,
[LASTCHANGEINIT] [char](8) NULL,
[BOMLOCK] [bit] NOT NULL,
[BOMLOCKINIT] [char](8) NULL,
[BOMLOCKDT] [smalldatetime] NULL,
[BOMLASTINIT] [char](8) NULL,
[ROUTREL] [bit] NOT NULL,
[ROUTRELDT] [smalldatetime] NULL,
[ROUTRELINT] [char](8) NOT NULL,
[TARGETPRICE] [numeric](13, 5) NOT NULL,
[FIRSTARTICLE] [bit] NOT NULL,
[MRC] [char](15) NOT NULL,
[TARGETPRICEDT] [smalldatetime] NULL,
[PPM] [numeric](3, 0) NOT NULL,
[MATLTYPE] [char](10) NOT NULL,
[NEWITEMDT] [smalldatetime] NULL,
[BOMINACTDT] [smalldatetime] NULL,
[BOMINACTINIT] [char](8) NULL,
[MTCHGDT] [smalldatetime] NULL,
[MTCHGINIT] [char](8) NULL,
[BOMITEMARC] [bit] NOT NULL,
CONSTRAINT [INVENTOR_PK] PRIMARY KEY CLUSTERED
(
[UNIQ_KEY] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
客户表
CREATE TABLE [dbo].[dim_Customer](
[CUSTNO] [char](10) NOT NULL,
[CUSTNAME] [char](35) NOT NULL,
[PHONE] [char](19) NOT NULL,
[FAX] [char](19) NOT NULL,
[BLINKADD] [char](10) NOT NULL,
[SLINKADD] [char](10) NOT NULL,
[TERRITORY] [char](15) NOT NULL,
[TERMS] [char](15) NOT NULL,
[CREDLIMIT] [numeric](9, 0) NOT NULL,
[PROFILE] [text] NOT NULL,
[CUSTNOTE] [text] NOT NULL,
[ACCTSTATUS] [char](9) NOT NULL,
[DIVISION] [char](12) NOT NULL,
[SREPS] [char](100) NOT NULL,
[CREDITOK] [char](15) NOT NULL,
[RESL_NO] [char](16) NOT NULL,
[AR_CALDATE] [smalldatetime] NULL,
[AR_CALTIME] [char](10) NOT NULL,
[AR_CALBY] [char](10) NOT NULL,
[AR_CALNOTE] [text] NOT NULL,
[AR_HIGHBAL] [numeric](12, 2) NOT NULL,
[CREDITNOTE] [text] NOT NULL,
[ACCT_DATE] [smalldatetime] NULL,
[SAVEINIT] [char](8) NULL,
[OUT_MARGIN] [numeric](6, 2) NOT NULL,
[TL_MARGIN] [numeric](6, 2) NOT NULL,
[MAT_MARGIN] [numeric](6, 2) NOT NULL,
[LAB_MARGIN] [numeric](6, 2) NOT NULL,
[MIN_ORDAMT] [numeric](12, 2) NOT NULL,
[SCRAP_FACT] [numeric](6, 2) NOT NULL,
[COMMITEM] [numeric](1, 0) NOT NULL,
[CUSTSPEC] [numeric](4, 0) NOT NULL,
[LABOR] [bit] NOT NULL,
[MATERIAL] [bit] NOT NULL,
[SPLIT1] [numeric](1, 0) NOT NULL,
[SPLIT2] [numeric](1, 0) NOT NULL,
[SPLITAMT] [numeric](12, 2) NOT NULL,
[SPLITPERC] [numeric](6, 2) NOT NULL,
[TOOLING] [bit] NOT NULL,
[SIC_CODE] [char](5) NOT NULL,
[SIC_DESC] [char](35) NOT NULL,
[DELIVTIME] [char](7) NOT NULL,
[STATUS] [char](8) NOT NULL,
[SERIFLAG] [bit] NOT NULL,
[OVERHEAD] [numeric](6, 2) NOT NULL,
[IS_EDITED] [char](3) NOT NULL,
[SALEDSCTID] [char](10) NOT NULL,
[CUSTPFX] [char](4) NOT NULL,
[ACTTAXABLE] [bit] NOT NULL,
[INACTDT] [smalldatetime] NULL,
[INACTINIT] [char](8) NULL,
[modifiedDate] [datetime] NULL,
[IsSynchronizedFlag] [bit] NOT NULL,
[isQBSync] [bit] NOT NULL,
[internal] [bit] NOT NULL,
CONSTRAINT [CUSTOMER_PK] PRIMARY KEY CLUSTERED
(
[CUSTNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
原始数据表的观点:
CREATE VIEW raw.vwInvNotUsedDetails
AS
SELECT
inu.uniq_key,
cpn.CUSTPARTNO AS CustomerPN,
inu.part_no,
inu.revision,
inu.descript,
inu.part_class,
inu.part_type,
inu.partmfgr,
inu.mfgr_pt_no,
inu.warehouse,
inu.stdcost,
i.TARGETPRICE AS TargetPrice,
inu.qty_oh,
inu.extcost AS ExtStdCost,
inu.qty_oh * ISNULL(i.TARGETPRICE, 0) AS ExtTargetPrice,
inu.lastused,
DATEDIFF(d, lastused, GETDATE()) AS LastUsedDays,
raw.fn_CustomerInventoryAgingStatus(inu.lastused, default) AS InvType
FROM raw.InvNotUsed inu
JOIN dbo.dim_Item i ON i.UNIQ_KEY = inu.uniq_key
LEFT JOIN (
select
ROW_NUMBER() over (partition by int_uniq order by c.status, i.revision) rn,
INT_UNIQ,
--uniq_key,
--i.PART_NO,
i.CUSTPARTNO
from dbo.dim_Item i
join dbo.dim_Customer c on i.custno = c.CUSTNO
)cpn ON cpn.INT_UNIQ = inu.uniq_key
AND cpn.rn = 1 --only select the first one if there are duplicate associated customer parts. this may make mistakes but its probably the best option for right now.
CREATE VIEW raw.vwInvWipValueDetails
AS
SELECT iwv.uniq_key,
iwv.PART_NO,
cpn.CUSTPARTNO,
iwv.REVISION,
iwv.PART_CLASS,
iwv.PART_TYPE,
iwv.DESCRIPT,
iwv.stdcost,
i.TARGETPRICE,
iwv.qtyoh,
iwv.QtyInWip,
iwv.InvtValue AS StdInvValue,
iwv.qtyoh * ISNULL(i.TARGETPRICE, 0) AS TgtInvValue,
iwv.WipValue AS StdWipValue,
iwv.QtyInWip * ISNULL(i.TARGETPRICE, 0) AS TgtWipValue,
iwv.TotalValue AS StdTotalValue,
(iwv.qtyoh + iwv.QtyInWip) * ISNULL(i.TARGETPRICE, 0) AS TgtTotalValue
FROM [raw].[InvWipValue] iwv
JOIN dbo.dim_Item i ON i.UNIQ_KEY = iwv.uniq_key
LEFT JOIN
(
SELECT ROW_NUMBER() OVER(PARTITION BY [i].[INT_UNIQ] ORDER BY c.status,
i.revision) rn,
[i].[INT_UNIQ],
--[i].[UNIQ_KEY],
--i.PART_NO,
i.CUSTPARTNO
FROM dbo.dim_Item i
JOIN dbo.dim_Customer c ON i.custno = c.CUSTNO
) cpn ON cpn.INT_UNIQ = iwv.uniq_key
AND cpn.rn = 1;
CREATE VIEW raw.vwPoOpenDetails
AS
SELECT
part_no,
Revision,
PARTMFGR,
PONUM,
CONUM,
ITEMNO,
SUPNAME,
BalanceQty,
COSTEACH,
PoBalAmt
FROM raw.PoOpenDetails
答案 0 :(得分:0)
这里的问题是我们正在排名的第二次加入,在cte。
中获取此代码即
CREATE VIEW raw.vwInvWipValueDetails
AS
with temp1
as
SELECT ROW_NUMBER() OVER(PARTITION BY [i].[INT_UNIQ] ORDER BY c.status,
i.revision) rn,
[i].[INT_UNIQ],
i.CUSTPARTNO
FROM dbo.dim_Item i
JOIN dbo.dim_Customer c ON i.custno = c.CUSTNO
)
,cpn as(select * from temp1 where rn = 1)
SELECT iwv.uniq_key,
iwv.PART_NO,
cpn.CUSTPARTNO,
iwv.REVISION,
iwv.PART_CLASS,
iwv.PART_TYPE,
iwv.DESCRIPT,
iwv.stdcost,
i.TARGETPRICE,
iwv.qtyoh,
iwv.QtyInWip,
iwv.InvtValue AS StdInvValue,
iwv.qtyoh * ISNULL(i.TARGETPRICE, 0) AS TgtInvValue,
iwv.WipValue AS StdWipValue,
iwv.QtyInWip * ISNULL(i.TARGETPRICE, 0) AS TgtWipValue,
iwv.TotalValue AS StdTotalValue,
(iwv.qtyoh + iwv.QtyInWip) * ISNULL(i.TARGETPRICE, 0) AS TgtTotalValue
FROM [raw].[InvWipValue] iwv
JOIN dbo.dim_Item i ON i.UNIQ_KEY = iwv.uniq_key
LEFT JOIN cpn ON cpn.INT_UNIQ = iwv.uniq_key;
答案 1 :(得分:0)
Ok so I figured out a solution though I'm still not quite sure why this worked, especially given that I have two very similar views and there was only a problem with one of them.
I added an index to each one of my raw tables on the item's unique id. That's it. The whole package verifies and runs in a couple of seconds now.
CREATE INDEX [IX_InvWipValue_uniq_key] ON [raw].[InvWipValue] ([uniq_key])