“I hate views,” the DBA said. “They kill performance. And nested views are even worse.”
Wrong. I’ll prove it.
I’m going to use the 50GB StackOverflow2013 database, and I’ll start by creating a couple of indexes on the Users table to help our queries, then create a view on the Users table:
USE StackOverflow2013; GO DropIndexes; CREATE INDEX DisplayName ON dbo.Users(DisplayName); CREATE INDEX Location ON dbo.Users(Location); GO CREATE OR ALTER VIEW dbo.vwUsers AS SELECT * FROM dbo.Users; GO
First, compare plans for the table and the view.
If I run two identical queries looking for users in a specific city: