Omu
Omu

Reputation: 71188

is using views faster or slower than just writing the whole sql from scratch

I have 3 tables (A,B,C) and I need quite often to query the result of

A inner join B
union
A inner join C

I'm just thinking which way is going to be faster:

Upvotes: 2

Views: 329

Answers (2)

SQLMenace
SQLMenace

Reputation: 134923

A view in general is nothing else but a stored version of the SQL, in that case no. However you might get some benefit by using indexed view, especially with aggregations....having said that..indexed views have a ton of restrictions...for one union is not allowed

Upvotes: 2

Mitch Wheat
Mitch Wheat

Reputation: 300489

If the view contains no aggregations, then using the view will be exactly the same as using the raw SQL. No aggregations means that a where clause can be applied 'internally' to a view where the optimiser deems optimal (based on statistics). (I think this is often referred to as 'pushing' the where clause inside a view)

Upvotes: 1

Related Questions