と呼ばれるテーブルを更新し、その列を VIEW 内の一致する行にRecipes
設定しています。ImageUrl
私のUPDATEステートメントは次のとおりです。
UPDATE Recipes R
SET ImageUrl=L.ImageUrl
FROM Link.Recipes L
WHERE L.RecipeId=R.RecipeId AND L.ImageUrl is not null;
Link.Recipes
Recipes
別のサーバー上の別のデータベースからすべての行を返す VIEW であるため、すでにかなり遅いです。
クエリが正常に返されました: 8541 行が影響を受け、実行時間は 173236 ミリ秒です。
少しでも速くなる方法があれば教えていただきたいです。同様の数の行を持つ同じビューを含む INSERT ステートメントははるかに高速であるため、ここでは何かが異なっています。
もちろん にはインデックスがありますが、どちらのテーブルにもインデックスがありませんRecipeId
。ImageUrl
3 分近くかからないこの UPDATE ステートメントを作成できるより良い方法はありますか?
説明:
'Update (cost=0.00..4136.54 rows=995 width=1531)'
' -> Nested Loop (cost=0.00..4136.54 rows=995 width=1531)'
' -> Function Scan on dblink t1 (cost=0.00..10.00 rows=995 width=266)'
' Filter: (imageurl IS NOT NULL)'
' -> Index Scan using recipes_pkey on recipes r (cost=0.00..4.13 rows=1 width=1281)'
' Index Cond: (r.recipeid = t1.recipeid)'
説明する 分析する:
'Update (cost=0.00..4233.18 rows=995 width=1532) (actual time=168887.016..168887.016 rows=0 loops=1)'
' -> Nested Loop (cost=0.00..4233.18 rows=995 width=1532) (actual time=23689.440..24500.006 rows=8549 loops=1)'
' -> Function Scan on dblink t1 (cost=0.00..10.00 rows=995 width=266) (actual time=23689.250..23749.288 rows=8550 loops=1)'
' Filter: (imageurl IS NOT NULL)'
' -> Index Scan using recipes_pkey on recipes r (cost=0.00..4.23 rows=1 width=1282) (actual time=0.083..0.085 rows=1 loops=8550)'
' Index Cond: (r.recipeid = t1.recipeid)'
'Trigger trg_recipes_searchupdate: time=3808.617 calls=8549'
'Total runtime: 168889.272 ms'