Sementara dalam contoh sederhana Anda, semuanya akan sama, beberapa kehati-hatian diperlukan dengan menggunakan tampilan bersarang.
Saya bekerja pada sistem di mana waktu kueri habis setelah 30 detik dibangun pada sekitar 6 tingkat tampilan bersarang dan berhasil mempercepatnya dengan faktor sekitar 100 dengan menulis ulang kueri terhadap tabel dasar.
Contoh sederhana dari jenis masalah yang dapat muncul di bawah ini.
CREATE VIEW MaxTypes
AS
SELECT
[number],
MAX(type) AS MaxType
FROM [master].[dbo].[spt_values]
GROUP BY [number]
GO
CREATE VIEW MinTypes
AS
SELECT
[number],
MIN(type) AS MinType
FROM [master].[dbo].[spt_values]
GROUP BY [number]
GO
SET STATISTICS IO ON
SELECT MaxTypes.number, MinTypes.MinType, MaxTypes.MaxType
FROM MinTypes INNER JOIN
MaxTypes ON MinTypes.number = MaxTypes.number
ORDER BY MaxTypes.number
/*
Gives
Table 'spt_values'. Scan count 2, logical reads 16, physical reads 0,
read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
*/
GO
SELECT
[number],
MAX(type) AS MaxType,
MIN(type) AS MinType
FROM [master].[dbo].[spt_values]
GROUP BY [number]
ORDER BY [number]
/*
Gives
Table 'spt_values'. Scan count 1, logical reads 8, physical reads 0,
read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
*/