在 ETL 服務器上,我有一個 DW 用戶表。
在 prod OLTP 服務器上,我有銷售資料庫。我只想為 ETL 服務器上的用戶表中存在的用戶提取銷售額。
目前我正在使用執行 SQL 任務將 DW 用戶提取到 SSIS System.Object 變數中。然后使用 for each 回圈遍歷此變數中的每個專案(用戶 ID),并通過資料流任務獲取每個用戶的 OLTP 銷售表并將其轉儲到 DW 臨時表中。for each 需要很長時間才能運行。
我希望能夠進行內部聯接,以便回應更快,但我無法這樣做,因為它們位于不同的服務器上。出于同樣的原因,我也不能使用全域臨時表來進行內部聯接。
我試圖將 DW 用戶收集到一個逗號分隔的字串變數中,然后使用它(通過 string_split)查詢 OLTP,但這在預執行階段也需要更多時間(不確定為什么),即使對于少量用戶。
我也知道查找轉換,但這也會導致所有 oltp 行都被帶入 dw etl 服務器以測驗查找條件。
是否有任何替代方法可以通過將用戶串列放入源中來進行內部聯接?
注意:我對 OLTP 資料庫沒有寫權限。
uj5u.com熱心網友回復:
根據評論,我認為我們可以使用臨時表來解決這個問題。
你能幫我理解這個限制嗎?“出于同樣的原因,我也不能使用全域臨時表來進行內部聯接。”
限制是因為 oltp 服務器和 dw 服務器是分開的,所以不能有兩個服務器通用的全域臨時表。希望是有道理的。
我們要做的一般模式是
- 執行SQL Task在OLTP服務器上創建臨時表
- 用于填充新臨時表的資料流任務。來源 = DW。目標 = OLTP。確保延遲驗證 = True
- 修改現有資料流。將源修改為使用臨時表的查詢,即
SELECT S.* FROM oltp.sales AS S WHERE EXISTS (SELECT * FROM #SalesPerson AS SP WHERE SP.UserId = S.UserId);確保延遲驗證 = True
關于使用臨時表的長格式答案(全域設定元資料,此后定期)

I have 67k as there are only 3 employees in the temporary table.

Reference package

But wait, there's more!
Close out visual studio, open it back up and try to touch something in the data flows. Suddenly, there are red Xs everywhere! Any time you close a data flow component, it fires a revalidate metadata operation and guess what, it can't do that as the connection to the temporary table is gone. The package will run fine, it will not throw VS_NEEDSNEWMETADATA but editing/maintenance becomes a pain.
If you switched from global temporary table to local, switch the table name variable's value back to a global and then run the define statement in SSMS. Once that's done, then you can continue editing the package.
I assure you, the local temporary table does work once you have the metadata set and you use queries via variables for source/destination.

uj5u.com熱心網友回復:
不需要全域臨時表 hack 或 SET FMTONLY OFF hack(不再有效)。
只需在 SQL 查詢中指定結果集元資料WITH RESULT SETS。例如
EXEC ('
create table #t
(
ID INT,
Name VARCHAR(150),
Number VARCHAR(15)
)
insert into #t (Id, Name, Number)
select object_id, name, 12
from sys.objects
select * from #t
')
WITH RESULT SETS
(
(
ID INT,
Name VARCHAR(150),
Number VARCHAR(15)
)
)
如果您需要引數化查詢,則有一些問題,因為 SSIS 發現引數的方式存在一些限制。SSIS 運行sp_describe_undeclared_pa??rameters,它實際上不適用于呼叫sp_executesql 的批處理,因為 sp_executesql 有一種處理引數的非常獨特的方式,您無法使用用戶存盤程序復制這種方式。
因此,要引數化查詢,您需要使用“來自變數的查詢”和 SSIS 運算式將引數值傳遞到查詢中,或者將所有這些 TSQL 推送到存盤程序中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/401909.html
標籤:sql-server 姐姐
