Partition Switching Joe Tempel.

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

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.
Dual Partitioning for improved performance in VLDBs Ashwin Rao Karavadi, Rakesh Parida Microsoft IT.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
ISV Innovation Presented by ISV Innovation Presented by Business Intelligence Fundamentals: Data Loading Ola Ekdahl IT Mentors 9/12/08.
Architecture Rajesh. Components of Database Engine.
Module 11: Programming Across Multiple Servers. Overview Introducing Distributed Queries Setting Up a Linked Server Environment Working with Linked Servers.
SQL Server Indexes Indexes. Overview Indexes are used to help speed search results in a database. A careful use of indexes can greatly improve search.
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
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 |
Chapter 15 A External Methods. © 2004 Pearson Addison-Wesley. All rights reserved 15 A-2 A Look At External Storage External storage –Exists beyond the.
02 | Data Flow – Extract Data Richard Currey | Senior Technical Trainer–New Horizons United George Squillace | Senior Technical Trainer–New Horizons Great.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
Relational Database Management System(RDBMS) Structured Query Language(SQL)
Best Practices in Loading Large Datasets Asanka Padmakumara (BSc,MCTS) SQL Server Sri Lanka User Group Meeting Oct 2013.
SQL Server 2005 – Table Partitioning Chad Gronbach Microsoft.
# CCNZ What is going on here???
SQL Basics Review Reviewing what we’ve learned so far…….
Splits, Merges and Purges THE HOW TO OF TABLE PARTITIONING.
Oracle Announced New In- Memory Database G1 Emre Eftelioglu, Fen Liu [09/27/13] 1 [1]
Doing fast! Optimizing Query performance with ColumnStore Indexes in SQL Server 2012 Margarita Naumova | SQL Master Academy.
Understanding Core Database Concepts Lesson 1. Objectives.
Partitioning & Creating Hardware Tablespaces for Performance
Introduction to Partitioning in SQL Server
With Temporal Tables and More
Data Warehouse ETL By Garrett EDmondson Thanks to our Gold Sponsors:
SQL Backups for Beginners by Mark Gordon
Katowice,
Antonio Abalos Castillo
SQL Creating and Managing Tables
T-SQL: Simple Changes That Go a Long Way
Introduction To Database Systems
Finding more space for your tight environment
CSE-291 (Cloud Computing) Fall 2016
Why Should I Care About … Partitioned Views?
The Ins and Outs of Partitioned Tables
Beginner Table Partitioning
SQL Backups for Beginners by Mark Gordon
DATABASE MANAGEMENT SYSTEM
SQL Creating and Managing Tables
Traveling in time with SQL Server 2017
Simple Partitioning Building a simple partitioning solution with SQL Server Stephen Fulcher.
Workbench Data Definition Language (DDL)
Introduction to partitioning
SQL Creating and Managing Tables
Why Should I Care About … Partitioned Views?
20 Questions with Azure SQL Data Warehouse
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?
In Memory OLTP Not Just for OLTP.
How Does it Work? If I have tables with the identical data structure that use the same partition scheme, I can move data using partition switching. Table_Staging.
Why Should I Care About … Partitioned Views?
Table Partitioning Intro and make that a sliding window too!
Why Should I Care About … Partitioned Views?
Clustered Columnstore Indexes (SQL Server 2014)
Table Partitioning Intro and make that a sliding window too!
Bulk Load and Minimal Logging
In Memory OLTP Not Just for OLTP.
Understanding Core Database Concepts
Managing Table Partitions at the Extreme
Using Columnstore indexes in Azure DevOps Services. Lessons learned
Using Columnstore indexes in Azure DevOps Services. Lessons learned
T-SQL: Simple Changes That Go a Long Way
Sunil Agarwal | Principal Program Manager
An Introduction to Partitioning
Presentation transcript:

Partition Switching Joe Tempel

Who Am I? Joe Tempel Degree in Environmental Science IT professional for 19+ years Consultant for Digineer (a MN based consulting firm) for 5 years Many Hats Developer, Data Architect, Product Manager, Business Analyst… Interests (Other than SQL Server) Running Trekking and Rock Climbing Cooking Craft Beers

What is Partitioning? Data in a table is split into groups horizontally Groups of rows are mapped into individual partitions Data in partitioned tables can be spread across more than one filegroup in a database Requires a partition function and a partition scheme Function defines the datatype and values used as dividing lines for the partitions Scheme defines where each partition will be stored

What is Partition Switching? When your data is in partitioned tables, you can use the Transact-SQL ALTER TABLE...SWITCH statement to quickly and efficiently transfer subsets of your data in the following ways: Assigning a table as a partition to an already existing partitioned table. Switching a partition from one partitioned table to another. Reassigning a partition to form a single table. SOURCE: https://technet.microsoft.com/en-us/library/ms191160(v=sql.105).aspx Old News (has been around since SQL 2005)

How Does it Work? If I have tables with the identical data structure that use the same partition scheme, I can move data using partition switching. Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition

How Does it Work? I can load and modify data in a staging table… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition

How Does it Work? …issue a switch command… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 ALTER TABLE [Table_Staging] SWITCH PARTITION 7 to [Table] PARTITION 7; Contains Data Empty Partition

How Does it Work? …and the data will be ‘moved’ instantly. Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition

How Does it Work. I can only switch data into an empty partition How Does it Work? I can only switch data into an empty partition. If I stage data that I want to replace existing data with, I need to make room. Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition

How Does it Work? I can switch data out of my primary table… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 ALTER TABLE [Table] SWITCH PARTITION 1 to [Table_Delete] PARTITION 1; SWITCH PARTITION 2 to [Table_Delete] PARTITION 2; Contains Data Empty Partition

How Does it Work? …switch the data from staging to my primary table… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 ALTER TABLE [Table_Staging] SWITCH PARTITION 1 to [Table] PARTITION 1; SWITCH PARTITION 2 to [Table] PARTITION 2; Contains Data Empty Partition

How Does it Work? …and then truncate Table_Delete… Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 TRUNCATE TABLE Table_Delete; Contains Data Empty Partition

How Does it Work? …done. Table_Staging 1 2 3 4 5 6 7 Table 1 2 3 4 5 6 7 Table_Delete 1 2 3 4 5 6 7 Contains Data Empty Partition

A Few Notes Staging and delete tables do not need to be partitioned (if you work with data that does not span partitions in the primary table) Before you can switch data into a table with indexes, you need to make sure that the source table has identical indexes. You can switch data from an indexed table to an unindexed table (Table_Delete from our example does not need to be index aligned) For additional requirements see: https://technet.microsoft.com/en-us/library/ms191160(v=sql.105).aspx

Why Would I Use Partition Switching? Data Warehouse updates Archiving old data Updating a SQL 2012 table with a columnstore index Drop Columnstore Index on Staging Stage DataCreate Columnstore Index on StagingSwitch Data to Primary Table

Benefits Faster Less Logging Minimizes the amount of time a lock is on the primary table

DEMO

Larger Scale Test Results Larger data set on spinning disk: Partition switching took 15% as long as DELETE and INSERT

SPLIT and MERGE You can increase the number of partitions by using SPLIT You can decrease the number of partitions by using MERGE ALTER PARTITION FUNCTION partition_function () { SPLIT RANGE (boundary_value) | MERGE RANGE (boundary_value) } [ ; ]

DEMO

Additional Resources http://www.brentozar.com/sql/table-partitioning-resources/ A ton of material on when partitioning is and is not advantageous https://technet.microsoft.com/en-us/library/ms191160(v=sql.105).aspx https://msdn.microsoft.com/en-us/library/ms190787.aspx