Why You Should Consider Implementing Indexed Views

Slides:



Advertisements
Similar presentations
Aaron Bertrand SQL Sentry, Senior Kevin Kline SQL Sentry, Dir of Engineering
Advertisements

What is a Database By: Cristian Dubon.
Transact-SQL. 1. Declare float = 10 select * from customers where discnt
Keys, Referential Integrity and PHP One to Many on the Web.
Help! My table is getting too big! How to divide and conquer SQL Relay 2014.
Understanding Parameter Sniffing Benjamin Nevarez Blog: benjaminnevarez.com 1.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
Topics Views Stored Procedures User Defined Functions Triggers.
Overview SQL Server 2008 Overview Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP, MCTS Microsoft Web Development MCP ITIL.
How a little code can help with support.. Chris Barba – Developer at Cimarex Energy Blog:
Version 1.0. MCAD MCSD MCPD Enterprise SQL MCTS MCT Software/Web Development Consultant Cryptography/Digital Signature Consultant SQL Server 2005/2008R2/2012.
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
TSQL Improvements & Data Types SQL Server 2008 TSQL Improvements & Data Types Presented by Tarek Ghazali IT Technical Specialist Microsoft SQL Server MVP,
MICROSOFT ACCESS With your host: Daniel McAllister.
Views Lesson 7.
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.
Chapter 5 Index and Clustering
Session 1 Module 1: Introduction to Data Integrity
Learningcomputer.com SQL Server 2008 –Views, Functions and Stored Procedures.
Louis Davidson drsql.org.  Introduction  Designing a Trigger Solution  Trigger Coding Basics  Advanced Trigger Concepts  Summary SQL Saturday East.
SQL Query Analyzer. Graphical tool that allows you to:  Create queries and other SQL scripts and execute them against SQL Server databases. (Query window)
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.
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.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
7.5 Using Stored-Procedure and Triggers NAME MATRIC NUM GROUP Muhammad Azwan Bin Khairul Anwar CS2305A Muhammad Faiz Bin Badrol Shah CS2305B.
Oracle Announced New In- Memory Database G1 Emre Eftelioglu, Fen Liu [09/27/13] 1 [1]
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
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.
SQL Query Getting to the data ……..
Parameter Sniffing in SQL Server Stored Procedures
In-Memory Capabilities
How to Write a DML Trigger
Temporal Databases Microsoft SQL Server 2016
The Basics of Data Manipulation
Temporal Databases Microsoft SQL Server 2016
Cameron Blashka| Informer Implementation Specialist
Views, Stored Procedures, Functions, and Triggers
loooooooooooooong Introduction!
Isolation Levels Understanding Transaction Temper Tantrums
Module 7: Implementing Views
Purpose, Pitfalls and Performance Implications
Using Indexed Views & Computed Columns for Performance !
Traveling in time with SQL Server 2017
Simple Partitioning Building a simple partitioning solution with SQL Server Stephen Fulcher.
SQL 2014 In-Memory OLTP What, Why, and How
Purpose, Pitfalls and Performance Implications
The Basics of Data Manipulation
Steve Hood SimpleSQLServer.com
TEMPDB – INTERNALS AND USAGE
SQL Fundamentals in Three Hours
Understanding Transaction Isolation Levels
Data Analysis with SQL Window Functions
Four Rules For Columnstore Query Performance
Chapter 8 Advanced SQL.
Diving into Query Execution Plans
Chapter 11 Managing Databases with SQL Server 2000
Isolation Levels Understanding Transaction Temper Tantrums
Why You Should Consider Implementing Indexed Views
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, Data Developer

Alex Fleming, Data Developer 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 PowerShell Excel (VBA) Alex Fleming, Data Developer

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

Should you create indexed views? Alex Fleming, Data Developer

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

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

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

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

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

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

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

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

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

Alex Fleming, Data Developer

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

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

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

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

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

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

Further Reading & References 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/ Alex Fleming, Data Developer