开发者

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

开发者_如何学C

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:

  • to write in each query the whole thing from scratch

  • to create a view and use it in queries


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


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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜