From this SO answer a view should provide the same performance as using the same query directly.
Is querying over a view slower than executing SQL directly?
I have a view where this is not true.
This query targeting a view
SELECT
*
FROM
[Front].[vw_Details] k
WHERE
k.Id = 970435
Takes 10 seconds to complete. Copying the query from the view and adding WHERE k.Id = 970435
to it completes in less than 1 second. The view is nothing special, 4 LEFT JOIN
s, and a few CASE
directives to clean up data.
How can I figure out what the problem is, or what do I need to complete this question with in order for this to be answerable?
Update 1:
- SQL Server Version: 12.0.4436.0
- Query plan for view: https://pastebin.com/RY40Ab0k
- Query plan for select: https://pastebin.com/gwahhgpu
SELECT * FROM [Bospar].[Front].[vw_Kontakt_Detaljer] [k] WHERE [k].[Kontakt_sk]=970435
– Woodnote