Why Should I Care About … Partitioned Views?

Slides:



Advertisements
Similar presentations
Big Data Working with Terabytes in SQL Server Andrew Novick
Advertisements

Tables Lesson 6. Skills Matrix Tables Tables store data. Tables are relational –They store data organized as row and columns. –Data can be retrieved.
Architecting a Large-Scale Data Warehouse with SQL Server 2005 Mark Morton Senior Technical Consultant IT Training Solutions DAT313.
Dual Partitioning for improved performance in VLDBs Ashwin Rao Karavadi, Rakesh Parida Microsoft IT.
Practical Database Design and Tuning. Outline  Practical Database Design and Tuning Physical Database Design in Relational Databases An Overview of Database.
Insert, Update & Delete Performance Joe Chang
Partitioning Design For Performance and Maintainability Martin Cairns
M1G Introduction to Database Development 2. Creating a Database.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Working with SQL Server Database Objects Faculty: Nguyen Ngoc Tu.
Session 1 Module 1: Introduction to Data Integrity
Student Centered ODS ETL Processing. Insert Search for rows not previously in the database within a snapshot type for a specific subject and year Search.
Manipulating Data Lesson 3. Objectives Queries The SELECT query to retrieve or extract data from one table, how to retrieve or extract data by using.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
 What is DB Testing ?  Testing at the Data Access Layer  Need for Testing DB Objects  Common Problems that affect the Application  Should Testers.
SQL Basics Review Reviewing what we’ve learned so far…….
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
In this session, you will learn to: Manage databases Manage tables Objectives.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Database Constraints Ashima Wadhwa. Database Constraints Database constraints are restrictions on the contents of the database or on database operations.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Getting started with Accurately Storing Data
Introduction to Partitioning in SQL Server
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
SQL Query Getting to the data ……..
Understanding Data Storage
Temporal Databases Microsoft SQL Server 2016
Managing Tables, Data Integrity, Constraints by Adrienne Watt
Top 50 SQL Interview Questions & Answers
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Temporal Databases Microsoft SQL Server 2016
MIS2502: Data Analytics SQL – Putting Information Into a Database
Physical Changes That Don’t Change the Logical Design
Indices.
Instructor: Jason Carter
Error Handling Summary of the next few pages: Error Handling Cursors.
Why Should I Care About … Partitioned Views?
Why Should I Care About … Partitioned Views?
The Ins and Outs of Partitioned Tables
Database Design Using Normalization
Beginner Table Partitioning
Module 5: Implementing Data Integrity by Using Constraints
Weird Stuff I Saw While ... Supporting a Java Team
SQL 101.
Simple Partitioning Building a simple partitioning solution with SQL Server Stephen Fulcher.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Why Should I Care About … Partitioned Views?
Why Should I Care About … Partitioned Views?
MIS2502: Data Analytics SQL – Putting Information Into a Database
Practical Database Design and Tuning
Table Partitioning Intro and make that a sliding window too!
Why Should I Care About … Partitioned Views?
MIS2502: Data Analytics SQL – Putting Information Into a Database
Table Partitioning Intro and make that a sliding window too!
MIS2502: Data Analytics SQL – Putting Information Into a Database
Why Should I Care About … Partitioned Views?
Table Partitioning Intro and make that a sliding window too!
MIS2502: Data Analytics SQL 4– Putting Information Into a Database
IST 318 Database Administration
Partition Switching Joe Tempel.
Why Should I Care About … Partitioned Views?
Using Columnstore indexes in Azure DevOps Services. Lessons learned
Using Columnstore indexes in Azure DevOps Services. Lessons learned
Presentation transcript:

Why Should I Care About … Partitioned Views?

Frederick (Rick) Lowe Data FLowe Solutions LLC rick@data-flowe.com DataFLowe https://dataflowe.wordpress.com/ http://data-flowe.com/

I’m Not Here to Start the Retrolution Partitioned tables are awesome for almost all partitioning cases Historical takeaway from this talk – you’re not doomed if you have pre-2016 Standard Ed. Also, there are a couple of cases where views make sense even in EE

First … Why Are Partitioned Tables So Exciting (review)? Appears to be a normal table Table is broken into multiple partitions based on the value of a single column Migrating a partition in or out is a metadata-only operation (i.e. basically instantaneous) Select statements can eliminate partitions

Working With Partitioned Tables (review) Create a partition function and scheme Build clustered and nonclustered indexes on the partition scheme Views, CRUD etc reference a partitioned table pretty much like any other table SQL Server does all the heavy lifting

Partitioned Table (review) Update/Insert/Select MyTable 2005? 2006? 2007? 2008? Partition Scheme Associated With Table P0 … P1 … P2 … P3 …

Working With Partitioned Views Build individual tables Typically, create check constraints on tables View unions together all underlying tables *Create procedure determines which table to insert the data into *Update/Delete also need to either determine which table to work on or operate on all * Indicates operations can actually sometimes be done on view

Partitioned View Worst Case Update Insert Select UpdateMyTable CreateMyTable vwMyTable 2005? 2006? 2007? 2008? Data Boundaries Coded Into View / Procs MyTbl_05 … MyTbl_06 … MyTbl_07 … MyTbl_08 …

Partitioned View If You’re Lucky Update Insert Select UpdateMyTable CreateMyTable vwMyTable 2005? 2006? 2007? 2008? Data Boundaries Coded Into View / Procs MyTbl_05 … MyTbl_06 … MyTbl_07 … MyTbl_08 …

Working With Partitioned Views

Defining a Partitioned View CREATE VIEW Sales.vwSalesOrderHeader AS SELECT OrderDate, SalesOrderID, … FROM Sales.SalesOrderHeader_2005 UNION ALL SELECT OrderDate, SalesOrderID, … FROM Sales.SalesOrderHeader_2006 SELECT OrderDate, SalesOrderID, … FROM Sales.SalesOrderHeader_2007 SELECT OrderDate, SalesOrderID, … FROM Sales.SalesOrderHeader_2008; CREATE PROCEDURE Sales.SalesOrderHeader_Create … AS INSERT INTO Sales.SalesOrderHeader_2008( OrderDate, SalesOrderID, ….) VALUES( …. )

Adding A New Table to View Create table with appropriate structure Add check constraints Import data, if appropriate Create indexes Add new UNION ALL to view Update Stored Procedures

Removing Table From View Update stored procedures, if necessary Remove appropriate UNION ALL from view Data can now be truncated / Archived / etc

Demo

“Table” Elimination Partitioned tables only search partitions that match WHERE clause Note: in practice, this typically isn’t a performance “game changer” SQL Server will leverage check constraints by using startup conditions in execution plans … so check constraints do give partitioned views similar “table elimination”

Use Cases For Partitioned Views

Limitations of Partitioned Tables Prior to MSSQL 2016 SP1, Enterprise feature Horizontal partitioning scheme only Statistics tracked at table (not partition) level Indexing defined at the table level Partitioning can only occur on one column Prior to MSSQL 2014, online rebuild only supported at table level

Vertical Partitioning Horizontal partitioning separates groups of rows into partitions (table) or tables (view) Vertical partitioning on the other hand separates columns from the rest of the table Can be driven by normalization In practice, this term is more often associated with row splitting

Horizontal Partition

Vertical Partition

Before Row Splitting ID_Int ID_GUID Name … Big_xml Rating 1 1a23… Anna <doc <a name=a/>… /> 2 2ff0… Bubba <doc <a name=b/>… /> 9001 10ab… Goku

After Row Splitting ID_Int ID_GUID Name … 1 1a23… Anna 2 2ff0… Bubba 9001 10ab… Goku ID_Int Big_xml Rating 1 <… /> … 2 9001

Before Row Splitting ID_Int ID_GUID Name … SSN Salary 1 1a23… Anna 111-22-3333 $150,000 2 2ff0… Bubba 111-22-4444 $80,000 9001 10ab… Goku 111-22-9999 $125,000

After Row Splitting ID_Int ID_GUID Name … 1 1a23… Anna 2 2ff0… Bubba 9001 10ab… Goku ID_Int SSN Salary 1 111-22-3333 $150,000 2 111-22-4444 $80,000 … 9001 111-22-9999 $125,000

Statistics Sampling

Connect the Dots Simply

Possible Answer

Remember This? 2005? 2006? 2007? 2008? Data Boundaries Coded Into View / Procs MyTbl_05 … MyTbl_06 … MyTbl_07 … MyTbl_08 …

Multi-Dimensional Partitioned View 2005? 2006? 2007? 2008? Data Boundaries Coded Into View / Procs MyTbl_05 … MyTbl_06 … MyTbl_07 … Premium? no yes MyTbl_08 … Fast_SSD …

Thank You Rick Lowe – rick@data-flowe.com DataFLowe

Partition Function vs Scheme Partition Functions Partition Scheme

Defining a Partitioned Table (review) CREATE PARTITION FUNCTION MyFunction(DATE) AS RANGE RIGHT FOR VALUES (…); CREATE PARTITON SCHEME MyPartitionScheme AS PARTITION MyFunction TO( … ); CREATE TABLE Sales.SalesOrderHeader( OrderDate DATETIME2(3), SalesOrderID INT IDENTITY NOT NULL, … CONSTRAINT PK_SalesOrderHeader PRIMARY KEY CLUSTERED(OrderDate, SalesOrderID) ON MyPartitionScheme( OrderDate ) );

Moving Data Around – Partitioned Table (review) To extract an entire partition from a table Use ALTER TABLE SWITCH to instantly switch the partition out to a new table Archive / delete / manipulate the new table To add existing data to partitioned table Get data into table with same structure/indexing Add check constraints Switch the new table into the partitioned table