Presentation is loading. Please wait.

Presentation is loading. Please wait.

Why You Should Consider Implementing Indexed Views

Similar presentations


Presentation on theme: "Why You Should Consider Implementing Indexed Views"— Presentation transcript:

1 Why You Should Consider Implementing Indexed Views
Alex Fleming, Data Developer

2 Alex Fleming, Data Developer
About me Data Developer at SUNZ Insurance Solutions SQL Developer (since June 2016) Guest Author at simpleprogrammer.com automation/ vba/ metadata-developers/ SQL Server (SSRS,SSIS,SSAS 2008R2 – 2016), OLTP + OLAP environments PowerShell Excel (VBA) Alex Fleming, Data Developer

3 https://github.com/SqlBroveloper Twitter: @SQLBroveloper
Alex Fleming, Data Developer

4 Should you create indexed views?
Alex Fleming, Data Developer

5 Alex Fleming, Data Developer
No. Alex Fleming, Data Developer

6 Alex Fleming, Data Developer
Further Reading Alex Fleming, Data Developer

7 Alex Fleming, Data Developer
What is an Indexed View? Indexed (or “Materialized”) view – a schemabound view in which data is persisted on disc in the format of a unique clustered index Alex Fleming, Data Developer

8 Should you create indexed views?
It depends on the following: What is the problem? Performance tuning slow reports? Performance tuning an application? Does the data change frequently in the base tables (i.e., update, insert, and delete statements)? Is TempDB heavily utilized already? Are report tables an option? Alex Fleming, Data Developer

9 Alex Fleming, Data Developer
Why should you use them? Increase the performance of queries that contain: Expensive aggregate calculations Expensive join logic Other benefits: Increase awareness of dependent objects during development (schemabinding requirement) Enforce uniqueness for known (i.e., not null) values while allowing nulls (without using triggers) They’re cool! Encourage some best-practices Alex Fleming, Data Developer

10 Why should you not use them?
High resource consumption in Tempdb High maintenance costs for Inserts and Updates against base tables Volume and complexity of requirements and limitations Alex Fleming, Data Developer

11 Indexed View Pre-Requisites
1) SCHEMABINDING 2) Deterministic functions only 3) SET options 4) TempDB dependency 5) Unique Clustered Index Two-part naming required (i.e., [schema].[table]) COUNT_BIG(*) How DML is tracked on underlying tables Alex Fleming, Data Developer

12 Alex Fleming, Data Developer
1) SCHEMABINDING Prevent changes on parent objects from breaking child objects “Safety” feature – best practices? Slight Performance enhancement eliminate the need for Halloween Protection “Eager Table Spool” Plan operator Alex Fleming, Data Developer

13 2) Prohibition of Non-deterministic Functions
Deterministic function – return the same output for any set of inputs Three types of functions: Deterministic functions Non-deterministic functions Functions that vary on determinism qualities depending on use Alex Fleming, Data Developer

14 Alex Fleming, Data Developer

15 Alex Fleming, Data Developer
3) SET Options (Part ¼) SET ANSI_NULLS ON; SET ANSI_PADDING ON; SET ANSI_WARNINGS ON; Divide by 0 and arithmetic overflow cause rollback + warning warning when NULL appears in aggregate functions Parameters are unaffected (UDFs, Stored Procs, variables in batch statements) Alex Fleming, Data Developer

16 Alex Fleming, Data Developer
3) SET Options (Part 2/4) SET ARITHABORT ON; Implicitly turned on when ANSI_WARNINGS is on Performance issues arise when turned off SET CONCAT_NULL_YIELDS_NULL ON; Alex Fleming, Data Developer

17 Alex Fleming, Data Developer
3) SET Options (Part ¾) SET NUMERIC_ROUNDABORT OFF; Alex Fleming, Data Developer

18 Alex Fleming, Data Developer
3) SET Options (Part 4/4) SET QUOTED_IDENTIFIER ON; Alex Fleming, Data Developer

19 Alex Fleming, Data Developer
4) TempDB Space Prevent changes on parent objects from breaking child objects “Safety” feature – best practices? Slight Performance enhancement – eliminate the need for Halloween Protection Alex Fleming, Data Developer

20 Alex Fleming, Data Developer
Demos! Alex Fleming, Data Developer

21 Further Reading & References
docs.microsoft.com -and-nondeterministic-functions?view=sql-server-2017 Darling, Erik. “Indexed Views and Data Modifications.” Ozar, Brent. “What You Can (And Can’t) Do With Indexed Views.” Hammer, Derik. “SQL Server Schemabinding.” Borland, Jes. “SQL Server Indexed Views: The Basics.” Ben-Gan, Itzik. “Views.” Inside Microsoft SQL Server (1-29). Korotkevitch, Dmitri. “Indexed (Materialized) Views.” Pro SQL Server Internals. ( ). StackOverflow Database download link and instructions (Thank you Brent!): Alex Fleming, Data Developer


Download ppt "Why You Should Consider Implementing Indexed Views"

Similar presentations


Ads by Google