0
我有一個foreach
環查找一個querythat此查詢爲每一個item
一個innerjoin
,但它是如此緩慢慢速查詢。
foreach (string item in X)
{
//This is the prototype
querystring = "select distinct g.N,g.NH + ' - ' + g.NV + ' - ' + g.S + ' - ' + g.VS ID
from Table1 as g inner join Table2 as d on d.V=g.V
where d.MD= '1234' and g.AC= 'item' and
g.N <> '' and g.NV <> '' and g.S <> '' and g.VS <> '' ORDER BY g.N";
}
我跑Estimated Execution Plan
,我不能在這裏附上的結果,但對於表1中的index seek(nonClustered)
成本爲40%
和parallelism (repartion streams) is 24%
剩下的全是低的。
單個查詢是否緩慢,還是需要大量時間來處理'foreach'? – HoneyBadger
即使是單個查詢也很慢,並且每次搜索最多20次。但它太慢了。需要4到7秒才能給出結果 – lol
啓動單個查詢可能更有效,並且可以在C#(?)代碼中檢索X中每個項目的相關數據。 – HoneyBadger