2011-05-06 44 views
1

我已經1 temporary table和我做一樣的東西:3種不同的插入#table並行的SQL Server 2008中選擇

Insert into #table1 select ... from #temporal 
Insert into #table2 select ... from #temporal 
Insert into #table3 select ... from #temporal 

由於每一個選擇需要相當長的時間,我想paralelize這3個查詢有沒有在SQL Server 2008這樣做的方法?

+0

爲什麼要將相同的數據集放入這些表中?你能不能在你的其他代碼中使用#temporal?你可以索引#時間,它可能會更快。 – HLGEM 2011-05-06 18:16:37

+0

我需要3個時間表,他們的結果是不同的(3個不同領域的表) – cMinor 2011-05-06 18:22:06

回答

0

聽起來像問題的根源在於SELECT from #temporal是一個性能問題。你有臨時表#temporal的索引嗎?有可能索引(或統計更新)可以幫助您避免編寫更多代碼來解決此問題。

您是否能夠或者您是否曾嘗試過將性能測試結果存儲在其中?#temporal SELECT成爲表變量?

DECLARE @myTemporal TABLE (id int, foo varchar(100)) 
INSERT INTO @myTemporal (id, foo) 
    SELECT id, foo FROM #temporal; 

然後你ň插件可從表變量拉動,而不是昂貴/ nonperformant查詢。

Insert into #table1 select id, foo from @myTemporal; 
Insert into #table2 select id, foo from @myTemporal; 
Insert into #table3 select id, foo from @myTemporal; 

好處是您不必對臨時表執行SELECT 3x。你會從表變量中插入你的3個臨時表。所有行,沒有WHERE子句。

+0

那麼,原因是因爲我需要3個時間表,他們將用於其他storeprocedure ... – cMinor 2011-05-06 18:20:52

+0

@dark:很明顯,你需要3個臨時表。如果它的性能適合你的環境,我建議你通過表變量加載它們。 – 2011-05-06 18:22:47

+0

因此使用@tablevar比#tempTable更好?爲什麼? – cMinor 2011-05-06 18:24:08