Introduction to partitioning

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

This work is by Kendra Little and is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported LicenseCreative Commons Attribution-NonCommercial-NoDerivs.
Big Data Working with Terabytes in SQL Server Andrew Novick
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
Working with SQL and PL/SQL/ Session 1 / 1 of 27 SQL Server Architecture.
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.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
Architecture Rajesh. Components of Database Engine.
Denny Cherry twitter.com/mrdenny.
Application Data and Database Activities Auditing Dr. Gabriel.
Chapter 15: Achieving High Availability Through Replication.
SQL Server 2005 Implementation and Maintenance Chapter 12: Achieving High Availability Through Replication.
SQL Server 2005 – Table Partitioning Vinod Kumar Intel Technology India Pvt. Ltd. MVP – SQL Server
Praveen Srivatsa Director| AstrhaSoft Consulting blogs.asthrasoft.com/praveens |
SQL SERVER DAYS 2011 Indexing Internals Denny Cherry twitter.com/mrdenny.
SQL Server 2005 – Table Partitioning Chad Gronbach Microsoft.
# CCNZ What is going on here???
October 15-18, 2013 Charlotte, NC SQL Server Index Internals Tim Chapman Premier Field Engineer.
SQL Basics Review Reviewing what we’ve learned so far…….
Splits, Merges and Purges THE HOW TO OF TABLE PARTITIONING.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Doing fast! Optimizing Query performance with ColumnStore Indexes in SQL Server 2012 Margarita Naumova | SQL Master Academy.
Database Design: Solving Problems Before they Start! Ed Pollack Database Administrator CommerceHub.
Introduction to columnstore indexes Taras Bobrovytskyi SQL wincor nixdorf.
Introduction to Partitioning in SQL Server
Temporal Databases Microsoft SQL Server 2016
Module 2: Creating Data Types and Tables
Temporal Databases Microsoft SQL Server 2016
Finding more space for your tight environment
Resumable Online Index Rebuild (ROIR) in SQL 2017 & SQL DB
Taking your application to memory
Module 4: Creating and Tuning Indexes
Introduction to SQL Server Management for the Non-DBA
The Ins and Outs of Partitioned Tables
SSAS Tabular Toolbelt Sergiy Lunyakin.
Beginner Table Partitioning
Azure and SQL Server: Getting the best out of the cloud
SQL Server May Let You Do It, But it Doesn’t Mean You Should
Parallel Database Maintenance with 24/7 Systems and Huge DBs
Performance Monitoring Using Extended Events, DMVs & Query Store
Query Execution Expectation-Reality Denis Reznik
What Power BI users need to know about R
Migrating a Disk-based Table to a Memory-optimized one in SQL Server
What is the Azure SQL Datawarehouse?
Please support our sponsors
T-SQL Window Function Deep Dive part 1
Table Partitioning Intro and make that a sliding window too!
T-SQL Window function deep dive part 2
Microsoft SQL Server 2014 for Oracle DBAs Module 7
In Memory OLTP Not Just for OLTP.
What’s new with SQL Server
Stretch Database - Historical data storage in SQL Server 2016
Denny Cherry twitter.com/mrdenny
Table Partitioning Intro and make that a sliding window too!
Clustered Columnstore Indexes (SQL Server 2014)
Table Partitioning Intro and make that a sliding window too!
The Ins and Outs of Indexes
Partition Switching Joe Tempel.
Change Tracking Live Data Warehouse
Managing Table Partitions at the Extreme
Using Columnstore indexes in Azure DevOps Services. Lessons learned
Using Columnstore indexes in Azure DevOps Services. Lessons learned
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
All about Indexes Gail Shaw.
Reinhard Flügel Possiblities and Limitations of System-Versioned Temporal Tables beyond the Basics.
Advanced Database Topics
XML? What’s this doing in my database? Adam Koehler
An Introduction to Partitioning
Presentation transcript:

Introduction to partitioning

About Me Andrew Pruski @dbafromthecold dbafromthecold@gmail.com www.dbafromthecold.com SQL Server DBA & Data Platform MVP Originally from Wales, now living in Dublin

Session Aim To give you a base of knowledge to work with partitioning in SQL Server

Agenda Partitioning Definition Partitioning Key Partition Functions & Schemes Indexing Considerations Splitting, Merging & Switching Partitions Implementing Sliding Windows Filegroup Restores

Partitioning Definition Splitting a table horizontally into different units Units can be spread across different physical locations Limit of 15,000 partitions per table Primarily for maintenance of data Specialist functions available to manage data

Benefits Partitioned tables appear as normal tables Data is automatically mapped to the correct partition Specialist operations allow for easy management of data Individual partitions can be compressed Individual partitions can be rebuilt

Drawbacks Requires management of partitions and filegroups Specialist operations can be blocked by DML operations Foreign keys referencing partitioned table will prevent switch operations Performance of queries not referencing the partitioning key will be affected

Building a partitioned table

Partitioning key Column in the table which defines partition boundaries How is the data going to be split? Archiving/retention policy for the data? How is the table going to be queried? All column types except timestamp, ntext, text, image, xml, varchar(max), nvarchar(max), or varbinary(max)

Partition Functions Maps rows in the table to a partition CREATE PARTITION FUNCTION [NAME](DATATYPE) AS RANGE RIGHT | LEFT FOR VALUES (n,n1,n2...nx);

Left / Right Range Types Defines which side of the boundary the value specified belongs CREATE PARTITION FUNCTION [MyPartitionFunction](DATE) AS RANGE RIGHT | LEFT FOR VALUES (2016-01-01,2017-01-01,2018-01-01); RIGHT 2017-01-01 <= x < 2018-01-01 LEFT 2017-01-01 < x <= 2018-01-01

Partition Schemes Maps partitions to filegroups CREATE PARTITION SCHEME [NAME] AS PARTITION [FUNCTION NAME] [ALL] TO (FILEGROUP,FILEGROUP,FILEGROUP...);

Creating a partitioned table CREATE TABLE dbo.PartitionedTable (ColA INT IDENTITY(1,1), ColB VARCHAR(10), ColC VARCHAR(10), ColD VARCHAR(10), PartitioningKey DATE) ON PartitionScheme(PartitioningKey);

Demo

Indexing Considerations

Clustered indexes Create on the partition scheme specifying the partitioning key Unique – the partitioning key has to be explicitly specified Nonunique – the partitioning key will be added by SQL if not explicitly specified

Nonclustered indexes An index that is created using the same partition scheme as the base table is aligned An index that is created on a different filegroup or using a different partition scheme is non-aligned

Nonclustered indexes Unique - the partitioning key has to be explicitly specified Nonunique - the partitioning key will be added by SQL if not explicitly specified as an included column

Demo

Merging & Splitting Partitions

Merging Partitions Removes a partition Effectively “merges” two partitions into one Meta-data only operation if performed on an empty partition Data will be moved if partition is not empty, causing blocking and transaction log growth

Merging Partitions ALTER PARTITION FUNCTION [NAME]() MERGE RANGE (VALUE);

Splitting partitions Creates a new partition with new boundary value New boundary value must be distinct from other values Takes a schema modification lock on the table Meta-data only operation if partition is empty SQL will move data to the new partition if the data crosses the new boundary value

Splitting partitions ALTER PARTITION SCHEME [NAME] NEXT USED [FILEGROUP]; ALTER PARTITION FUNCTION [NAME]() SPLIT RANGE (VALUE);

Demo

Switching partitions

Switching partitions Move a partition from one table to another Meta-data operation, runs immediately Both tables must have the same structures Destination partition must be empty or… if destination table is not partitioned, it must be completely empty

Switching partitions ALTER TABLE [Source Table] SWITCH PARTITION Partition_Number TO [Destination Table] PARTITION Partition_Number;

Demo

Implementing Partition Sliding Windows

Partition Sliding Windows Method to remove old data and bring in new data periodically Implements the SWITCH, MERGE, & SPLIT functions Partitions in the table move “forward” but the overall number of partitions remains the same

Partition Sliding Windows SWITCH oldest partition in live table to archive table MERGE oldest partition SPLIT new partition Load new data into staging table SWITCH data from staging table to live table Update statistics on live table

Demo

Filegroup Restores

Filegroup Restores Can be useful for VLDBs Can be used to restore live partitions to development Individual partitions are on different filegroups Data in older partitions does not change or is not needed Reduce recovery time for “active” data

Demo

A quick story

Resources https://github.com/dbafromthecold/IntroToPartitioning https://dbafromthecold.com/2018/02/19/summary-of-my-partitioning-series/ https://docs.microsoft.com/en-us/sql/relational-databases/partitions/partitioned- tables-and-indexes https://technet.microsoft.com/en-us/library/ms187526(v=sql.105).aspx

Questions?

Just like Jimi Hendrix … We love to get feedback Please complete the session feedback forms

SQLBits - It's all about the community... Please visit Community Corner We are trying this year to get more people to learn about the SQL Community If you would be happy to visit the community corner we’d really appreciate it