Why You Should Consider Implementing Indexed Views

Slides:



Advertisements
Similar presentations
What is a Database By: Cristian Dubon.
Advertisements

Keys, Referential Integrity and PHP One to Many on the Web.
Understanding Parameter Sniffing Benjamin Nevarez Blog: benjaminnevarez.com 1.
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Introduction to Structured Query Language (SQL)
Topics Views Stored Procedures User Defined Functions Triggers.
ASP.NET Programming with C# and SQL Server First Edition
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
Agenda for Today Chapter 5 –Skip Lesson 2 Review questions Midterm Chapter 6 Review questions.
MICROSOFT ACCESS With your host: Daniel McAllister.
Views Lesson 7.
SQL: DDL. SQL Statements DDL - data definition language –Defining and modifying data structures (metadata): database, tables, views, etc. DML - data manipulation.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Chapter 5 : Integrity And Security  Domain Constraints  Referential Integrity  Security  Triggers  Authorization  Authorization in SQL  Views 
Chapter 5 Index and Clustering
Session 1 Module 1: Introduction to Data Integrity
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
SQL Query Analyzer. Graphical tool that allows you to:  Create queries and other SQL scripts and execute them against SQL Server databases. (Query window)
Chapter 3: Relational Databases
Virtual techdays INDIA │ august 2010 Filtered Indexes – The unexplored index … Vinod Kumar M │ Microsoft India Technology Evangelist – DB and BI.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
SQL Triggers, Functions & Stored Procedures Programming Operations.
 CONACT UC:  Magnific training   
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
SQL Basics Review Reviewing what we’ve learned so far…….
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Presented by: Aaron Stanley King.  Benefits of SQL Azure  Features of SQL Azure  Demos, Demos, Demos!  How to query in SQL Azure  More Demos!  Recent.
Database Design: Solving Problems Before they Start! Ed Pollack Database Administrator CommerceHub.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
MICROSOFT ACCESS With your host: Daniel McAllister.
Chris Index Feng Shui Chris
SQL Query Getting to the data ……..
Parameter Sniffing in SQL Server Stored Procedures
In-Memory Capabilities
Temporal Databases Microsoft SQL Server 2016
Module 11: File Structure
Relational Database Design
Temporal Databases Microsoft SQL Server 2016
Antonio Abalos Castillo
SQL Implementation & Administration
Cameron Blashka| Informer Implementation Specialist
Views, Stored Procedures, Functions, and Triggers
loooooooooooooong Introduction!
Module 7: Implementing Views
The Ins and Outs of Partitioned Tables
Using Indexed Views & Computed Columns for Performance !
Simple Partitioning Building a simple partitioning solution with SQL Server Stephen Fulcher.
SQL 2014 In-Memory OLTP What, Why, and How
20 Questions with Azure SQL Data Warehouse
Steve Hood SimpleSQLServer.com
Chapter 4 Indexes.
CH 4 Indexes.
CH 4 Indexes.
Data Analysis with SQL Window Functions
Contents Preface I Introduction Lesson Objectives I-2
Chapter 8 Advanced SQL.
Diving into Query Execution Plans
Chapter 11 Managing Databases with SQL Server 2000
Why You Should Consider Implementing Indexed Views
IST 318 Database Administration
INTRODUCTION A Database system is basically a computer based record keeping system. The collection of data, usually referred to as the database, contains.
XML? What’s this doing in my database? Adam Koehler
Responding to Data Manipulation Via Triggers
Why You Should Consider Implementing Indexed Views
Presentation transcript:

Why You Should Consider Implementing Indexed Views Alex Fleming Why You Should Consider Implementing Indexed Views

About Me Data Developer at SUNZ Insurance Solutions SQL Developer (since June 2016) Guest Author at simpleprogrammer.com https://simpleprogrammer.com/vba-data-analysis-automation/ https://simpleprogrammer.com/maximizing-efficiency-vba/ https://simpleprogrammer.com/mastering-sql/ https://simpleprogrammer.com/microsoft-sql-server-metadata-developers/ SQL Server (SSRS,SSIS,SSAS 2008R2 – 2016), OLTP + OLAP environments Azure SQL Database PowerShell Excel (VBA)

Should You Create Indexed Views?

No.

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 What does that mean? 1) Querying the view does not require base table access 2) Updates, Inserts, and Deletes require additional overhead

Demo #1

Why should you create Indexed Views?

Primary benefits: increase the performance of queries that contain: Expensive aggregate calculations Expensive join logic Queries that join hierarchies Relatively fast implementation Performance tuning slow reports? Performance tuning an application?

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 (more on this later)

Important Indexed View Considerations

Does the data change frequently in the base tables? Numerous limitations (especially T-SQL) Are report tables an option? Is TempDB heavily utilized already? SQL Server Edition (Enterprise or Developer?) Express Edition requires WITH (NOEXPAND) hint

Indexed View Pre-requisites

2) Deterministic functions only 3) SET options 1) SCHEMABINDING 2) Deterministic functions only 3) SET options 4) Unique Clustered Index Two-part naming required (i.e., [schema].[table]) COUNT_BIG(*) How DML is tracked on underlying tables

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

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

SET Options (Part 1) 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) SET ARITHABORT ON; Implicitly turned on when ANSI_WARNINGS is on Performance issues arise when turned off SET CONCAT_NULL_YIELDS_NULL ON; SET NUMERIC_ROUNDABORT OFF; SET QUOTED_IDENTIFIER ON;

SET Options (Part 2)

SET Options (Part 3)

Alternatives Reporting Tables - No T-SQL restrictions, SET options, SCHEMABINDING, etc. - Require ETL process to load & refresh the table - Other queries that don’t directly reference the table can’t benefit from the table’s index(es)

Demo #2

Indexed View Opportunity Recognition Analyze existing view definitions Are any schemabound already? If so, are any indexable? select OBJECTPROPERTY(OBJECT_ID(‘[schema name].[view name]'),'IsIndexable’); Can you modify the view definition and remove T-SQL not supported by indexed views, and re-add the logic to a query referencing the indexed view?

Further Reading docs.microsoft.com https://docs.microsoft.com/en-us/sql/relational-databases/views/create-indexed-views?view=sql-server-2017 https://docs.microsoft.com/en-us/sql/relational-databases/user-defined-functions/deterministic -and-nondeterministic-functions?view=sql-server-2017 https://docs.microsoft.com/en-us/sql/t-sql/statements/set-ansi-nulls-transact-sql?view=sql-server-2017 https://docs.microsoft.com/en-us/sql/t-sql/statements/set-ansi-warnings-transact-sql?view=sql-server-2017 https://docs.microsoft.com/en-us/sql/t-sql/statements/set-arithabort-transact-sql?view=sql-server-2017 https://docs.microsoft.com/en-us/sql/t-sql/statements/set-concat-null-yields-null-transact-sql?view=sql-server-2017 https://docs.microsoft.com/en-us/sql/t-sql/statements/set-quoted-identifier-transact-sql?view=sql-server-2017 Darling, Erik. “Indexed Views and Data Modifications.” https://www.brentozar.com/archive/2017/03/indexed-views-data-modifications/ Ozar, Brent. “What You Can (And Can’t) Do With Indexed Views.” https://www.brentozar.com/archive/2013/11/what-you-can-and-cant-do-with-indexed-views/ Hammer, Derik. “SQL Server Schemabinding.” https://www.sqlhammer.com/sql-server-schemabinding/ Borland, Jes. “SQL Server Indexed Views: The Basics.” https://www.red-gate.com/simple-talk/sql/learn-sql-server/sql-server-indexed-views-the-basics/ Ben-Gan, Itzik. “Views.” Inside Microsoft SQL Server 2008. (1-29). Korotkevitch, Dmitri. “Indexed (Materialized) Views.” Pro SQL Server Internals. (219-225). StackOverflow Database download link and instructions (Thank you Brent!): https://www.brentozar.com/archive/2015/10/how-to-download-the-stack-overflow-database-via-bittorrent/