The Ins and Outs of Partitioned Tables

Slides:



Advertisements
Similar presentations
Designing Tables in Microsoft Access By Ed Lance.
Advertisements

Big Data Working with Terabytes in SQL Server Andrew Novick
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.
ETL By Dr. Gabriel.
1  MyOnlineITCourses.com 1 MyOnlineITCourses.com Oracle Partitioning -- A Primer.
Advanced Excel for Finance Professionals A self study material from South Asian Management Technologies Foundation.
ISV Innovation Presented by ISV Innovation Presented by Business Intelligence Fundamentals: Data Loading Ola Ekdahl IT Mentors 9/12/08.
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
10/10/2012ISC239 Isabelle Bichindaritz1 Physical Database Design.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
SQL Server 2005 – Table Partitioning Vinod Kumar Intel Technology India Pvt. Ltd. MVP – SQL Server
Praveen Srivatsa Director| AstrhaSoft Consulting blogs.asthrasoft.com/praveens |
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
7 Strategies for Extracting, Transforming, and Loading.
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.
20 Copyright © 2008, Oracle. All rights reserved. Cache Management.
Aggregator Stage : Definition : Aggregator classifies data rows from a single input link into groups and calculates totals or other aggregate functions.
SQL Server 2005 – Table Partitioning Chad Gronbach Microsoft.
6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration.
Scripting Just Enough SSIS to be Dangerous. 6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation.
SQL Basics Review Reviewing what we’ve learned so far…….
Splits, Merges and Purges THE HOW TO OF TABLE PARTITIONING.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
Database Administration for the Non-DBA Denny Cherry twitter.com/mrdenny.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Introduction to Partitioning in SQL Server
Temporal Databases Microsoft SQL Server 2016
Top 50 SQL Interview Questions & Answers
Relational Database Design
Module 2: Creating Data Types and Tables
Temporal Databases Microsoft SQL Server 2016
Introduction to SQL 2016 Temporal Tables
Antonio Abalos Castillo
Using Partitions and Fragments
T-SQL: Simple Changes That Go a Long Way
Finding more space for your tight environment
Designing Database Solutions for SQL Server
Methodology – Physical Database Design for Relational Databases
Partitioned Tables and Query Performance
Microsoft Access 2003 Illustrated Complete
Introduction to SQL Server Management for the Non-DBA
Why Should I Care About … Partitioned Views?
Why Should I Care About … Partitioned Views?
Relational Algebra Chapter 4, Part A
Beginner Table Partitioning
Using Indexed Views & Computed Columns for Performance !
Please support our sponsors
Introduction to partitioning
Partitioned Tables and Query Performance
Chapter 9 Database and Information Management.
Physical Database Design
Welcome to SQL Saturday Denmark
Hash-Based Indexes Chapter 10
Table Partitioning Intro and make that a sliding window too!
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Why Should I Care About … Partitioned Views?
Table Partitioning Intro and make that a sliding window too!
Contents Preface I Introduction Lesson Objectives I-2
Table Partitioning Intro and make that a sliding window too!
Chapter 11 Managing Databases with SQL Server 2000
Partition Switching Joe Tempel.
Why Should I Care About … Partitioned Views?
Managing Table Partitions at the Extreme
Using Columnstore indexes in Azure DevOps Services. Lessons learned
Using Columnstore indexes in Azure DevOps Services. Lessons learned
Using Columnstore indexes in Azure DevOps Services. Lessons learned.
Presentation transcript:

The Ins and Outs of Partitioned Tables SQL Saturday Houston Brian Dudley Senior Solution Architect Perficient, Inc.

Large Databases What is large? 2 | 9/18/2018 | Footer Goes Here

Large Databases What is large? Issues with large databases Backups Contention Maintenance Loading Archiving Index rebuilds Performance 3 | 9/18/2018 | Footer Goes Here

https://en.wikipedia.org/wiki/Partition_(database) What is Partitioning? “A partition is a division of a logical database or its constituent elements into distinct independent parts. Database partitioning is normally done for manageability, performance or availability reasons, as for load balancing.“ https://en.wikipedia.org/wiki/Partition_(database) Criteria Range – only one supported by SQL Server List Hash Partitioning Methods Vertical – splitting out columns Horizontal – dividing by row 4 | 9/18/2018 | Footer Goes Here

Benefits of Partitioning Partitioning is largely handled transparently Ability to move large amounts of data in or out of a table with metadata operation. Ease of maintenance Rebuild indexes by partition Piecemeal backup and restore at the table level Tuning of tables Location of data Compression by partition Performance gains Partition elimination Better joins across partitioned tables Increased options for parallel operation 5 | 9/18/2018 | Footer Goes Here

Caveats Partitioning is an Enterprise Version feature Use Developer Edition for testing and learning Partitioning is an involved topic. Test your assumptions 6 | 9/18/2018 | Footer Goes Here

Thank You Sponsors! Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration area to be entered in additional drawings. Want more free training? Check out the Houston Area SQL Server User Group which meets on the 2nd Tuesday of each month. Details at http://houston.sqlpass.org 5/14/2016

Partitioning Mechanics Determine tables to partition What pain point does it address? What is the strategy? Decide on Partition Key Data Type Range Should be commonly used in queries Define Partition Function Develop Partition Scheme Create Tables and Indexes on Partition 8 | 9/18/2018 | Footer Goes Here

Partition Function Create Partition Function <name> (<input parameter data type>) As Range [Left|Right] For Values (<list>) Input Parameter Data Type Most types can be used Date, Time, Integer Date Key, Int are Common Enter sorted or it will be done Consider collation Watch formatting of Date/Time values Value List Can use variables and functions Cannot use SQL Expressions 0 to 14,999 entries Lends itself well to being automated No duplicate values Null can be specified, but should be avoided. Always sorts first. $Partition.<function name>(<value>) tells on which partition a row will be placed 9 | 9/18/2018 | Footer Goes Here

Left or Right Illustrated Create Partition Function PF_Left(int) As Range Left For Values(10, 20, 30, 40) Create Partition Function PF_LeftEquiv(int) As Range Right For Values(11, 21, 31, 41) Create Partition Function PF_Right(int) As Range Right For Values(10, 20, 30, 40) Create Partition Function PF_RightEquiv(int) As Range Left For Values(9, 19, 29, 39) Left <-…10 11…20 21…30 31…40 41…-> Right <-…9 10…19 20…29 31…39 40…-> Date Example – Right or Left? <- 2015 Dec 31 2016 Jan 1…31 2016 Feb 1…29 2016 Mar 1…31 2016 Apr 1 -> 10 | 9/18/2018 | Footer Goes Here

Partition Scheme File Group List Design Decision Create Partition Scheme <name> As Partition <partition function> To (<file group list>) Create Partition Scheme <name> As Partition <partition function> All To (<file group>) File Group List Number of Boundary Values + 1 Can specify “Next Used” Design Decision Single File group File group Per Partition Older data on slower media Mix of Read only and Writeable Rotating List to “Stripe” the data 11 | 9/18/2018 | Footer Goes Here

Partition a Table Table must have a column that serves as the Partition Key Must be identical to the function parameter Can be a Persisted Computed Column e.g. Composite key Include On <Partition Scheme>(<key>) Many Tables can use the same Scheme Partition existing table with Clustered Index SSMS has Wizards 12 | 9/18/2018 | Footer Goes Here

Indexes on Partitioned Tables Aligned – uses the same partition scheme as the table. Default behavior for an index is to be aligned. Partition key is added to the index if it is not already specified. Has an impact on unique indexes. All active indexes must be aligned when swapping partitions. Logically, each partition has its own index. Non-aligned – explicitly created on its own File Group or Partition Can give better performance for searches that cross partitions. Have to be disabled in order to swap data. Factor in the cost of rebuilding.

Inspecting with System Views sys.Partition_Functions sys.Partition_Range_Values Left Join because of the extra partition Add 1 to boundary_id for Range Right sys.Partition_Schemes sys.Indexes sys.Data_Spaces Holds both Partition Schemes and File Groups Type and Type Description fields sys.Destination_Data_Spaces sys.FileGroups sys.Partitions Every table and index has an entry 14 | 9/18/2018 | Footer Goes Here

Switching Partitions Major benefit of Partitioned Tables Requirements Able to move a large amount of data as a metadata operation Load new data Remove old data for archive or truncation Requirements Two tables are required, at least one is partitioned Partition schemes must be compatible Tables must match in column name, data type, and order Indexes must all be aligned and must match Destination partition must exist and be empty Must acquire a schema lock Can cause time outs SSMS has Wizards 15 | 9/18/2018 | Footer Goes Here

Switch Illustrated Alter Table Right Switch Partition 3 To StagingTable Partition 3 Right <-…9 10…19 20…29 31…39 40…-> Data is moved with a metadata operation StagingTable <-…9 10…19 20…29 31…39 40…->

Split and Merge Used to maintain partition functions and schemes All Partition Schemes using a Partition Function are changed. All Tables on a Partition Scheme are changed. Can cause data movement Best case is to only effect empty partitions Sliding Window use case uses both splitting and merging 17 | 9/18/2018 | Footer Goes Here

Merge Illustrated Alter Partition Function PF_Right() Merge Range(10) <-…9 10…19 20…29 31…39 40…-> Alter Partition Function PF_Right() Merge Range(10) This file group is removed. Any data is moved. 10…19 Right <-…19 20…29 31…39 40…->

Split Illustrated Right <-…9 10…19 20…29 31…39 40…-> Alter Partition Scheme PS_Right Next Used FG1 Alter Partition Function PF_Right() Split Range(50) FG1 Scheme knows what File Group to use. Data will be moved if necessary. Right <-…9 10…19 20…29 31…39 40…49 50…->

ETL – Incremental Load Scenario: Data mart is refreshed monthly with new transactional data. Use split to create a new partition on a designated Next File Group. Partitions can also be created in advance. Create a non-partitioned staging table matching the target structure. File group matches the new partition Populate the staging table with a bulk copy Add all necessary indexes. Add a Check constraint. Swap data into target table. Update statistics on the target table.

ETL – Sliding Window Scenario: Maintain a fixed number of months of data. Create a non-partitioned archive table with necessary indexes. File group matches the last partition. Swap out the last partition. Data can be truncated or archived. Merge the now empty partition. Use split to create a new partition on a designated Next File Group. Create a non-partitioned staging table matching the target table. File group matches the new partition Populate the staging table with a bulk copy Add all necessary indexes. Add a Check constraint. Swap data into target table. Update statistics on the target table.

Odds and Ends Partition Elimination Identity Columns Transactions Shows in the actual plan detail Identity Columns Enforcing Uniqueness Ident_Current() Transactions

References Microsoft Whitepapers Brent Ozar Books Online “Partitioned Table and Index Strategies Using SQL Server 2008” https://technet.microsoft.com/en-us/library/dd578580(v=sql.100).aspx Brent Ozar SQL Server Table Partitioning: Resources https://www.brentozar.com/sql/table-partitioning-resources/ Books Online

Questions?

Thank You Sponsors! Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration area to be entered in additional drawings. Want more free training? Check out the Houston Area SQL Server User Group which meets on the 2nd Tuesday of each month. Details at http://houston.sqlpass.org 5/14/2016