Download presentation
Presentation is loading. Please wait.
1
Why Should I Care About … Partitioned Views?
Rick Lowe Data FLowe Solutions
3
Please Support Our Sponsors
SQL Saturday is made possible with the generous support of these sponsors. You can support them by opting-in and visiting them in the sponsor area.
4
Don’t Forget Silence your cell phones Online Evaluations
Submit for raffles by 3:30PM
5
Frederick (Rick) Lowe DataFLowe
6
I’m Not Here to Start the Retrolution
Partitioned tables are awesome for almost all partitioning cases Main takeaway from this talk – you’re not doomed if you have Standard Also, there are a couple of cases where views make sense even in EE
7
Overview of Partitioned Tables (Opposed to Partitioned Views)
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 Enterprise edition, MSSQL 2008 and higher
8
Working With Partitioned Tables
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
9
Partitioned Table MyTable 2005? 2006? 2007? 2008?
Update/Insert/Select MyTable 2005? 2006? 2007? 2008? Partition Scheme Associated With Table P1 … P2 … P3 … P4 …
10
Defining a Partitioned Table
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 ) );
11
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 on view can save work
12
Partitioned View Insert Select UpdateMyTable CreateMyTable vwMyTable
2005? 2006? 2007? 2008? Data Boundaries Coded Into View / Procs MyTbl_05 … MyTbl_06 … MyTbl_07 … MyTbl_08 …
13
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( …. )
14
Limitations of Partitioned Tables
Enterprise feature Horizontal partitioning scheme only Prior to MSSQL 2014, Statistics only 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
15
Vertical (vs Horizontal) 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
16
Horizontal Partition
17
Vertical Partition
18
Before Row Splitting ID_Int ID_GUID Name … Big_xml LastDoc 1 1a23…
Anna <… /> 2 2ff0… Bubba 9001 10ab… Goku
19
After Row Splitting ID_Int ID_GUID Name … 1 1a23… Anna 2 2ff0… Bubba
9001 10ab… Goku ID_Int Big_xml LastDoc 1 <… /> … 2 9001
20
Statistics Sampling
21
Common Answer
22
Possible Answer
23
Moving Data Around – Partitioned Table
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
24
Moving Data Around – Partitioned View
To separate a table from the view Alter the view so that it no longer references table Update stored procedures if necessary To add existing data to partitioned view Get data into table with same structure Ideally, add check constraints Update view and stored procedures to reference new table
25
Demo Startup Conditions in Execution Plan
26
Multi Dimensional Partitioning
Demo Multi Dimensional Partitioning
27
QUESTIONS
28
Thank You This FREE SQL Saturday is brought to you courtesy of these sponsors, speakers and volunteers who staff this event
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.