Partitioning techniques in SQL Server Eladio Rincon Javier Loria Solid Quality Mentors
Agenda 2 © 2008 Solid Quality Mentors Why?How?What?Where?Partitioning Toolbox
Agenda 3 © 2008 Solid Quality Mentors Why? Definition I/O Basics Table Basics Operational Benefits How?What?Where? Toolbox
Definition 4 © 2008 Solid Quality Mentors
I/O Basics OperationFileTypeReadWrite SELECTDatabaseRandomSynchronous- INSERT UPDATE DELETE LogSequential-Synchronous DatabaseRandom-Asynchronous Bulk InsertDatabaseRandomSynchronous Full BackupDatabaseSequentialSynchronous* Log BackupLogSequentialSynchronous- ReindexRandom?? 5 © 2008 Solid Quality Mentors S S S S
Table Basics 6 © 2008 Solid Quality Mentors
Operational Benefits Performance Query (OLPT/OLAP) Bulk-Insert (OLAP) Availability Full Backups Maintainability Archiving Pruning Reindex 7 © 2008 Solid Quality Mentors
Poor’s Mans Table Partitioning Creating and using partitioned views
Agenda 9 © 2008 Solid Quality Mentors Why?How? Partition Function Partition Scheme Create Table Reloaded Create Index Reloaded What?Where? Toolbox
Partition Function 10 © 2008 Solid Quality Mentors CREATE PARTITION FUNCTION Annual (INT) AS RANGE RIGHT FOR VALUES ( , , , , );
Partition Scheme 11 © 2008 Solid Quality Mentors CREATE PARTITION SCHEME Annual AS PARTITION Annual TO (EmptyHistory, Fact2006, Fact2007, Fact2008, Fact2009, EmptyFuture)
Create Table Reloaded 12 © 2008 Solid Quality Mentors CREATE TABLE SalesDataMart.FactVendas( IdDimDateINT NOT NULL, IdDimProductINT NOT NULL, IdDimCustomersINT NOT NULL, IdDimStoreINT NOT NULL, OrderedQuantityINT NOT NULL, TotalSalesAmountDECIMAL (19, 2) NOT NULL, TotalProductCostDECIMAL (19, 2) NOT NULL, POSNumINT NOT NULL, InvoceNumINT NOT NULL ) ON Annual(IdDimDate);
Create Index Reloaded 13 © 2008 Solid Quality Mentors CREATE CLUSTERED INDEX IDX_FactSales ON SalesDataMart.FactSales(IdDimDate, IdDimStore) ON Annual(IdDimDate); ALTER TABLE SalesDataMart.FactSales ADD CONSTRAINT PK_FactSales PRIMARY KEY(IdDimDate, IdDimProduct, IdDimCustomers, IdDimStore) ON Annual(IdDimDate);
Partition 101 Partitioned Hello World
Agenda 15 © 2008 Solid Quality Mentors Why?How? What? Table Design Patterns Partition Types Partition Methods Index Partitions Where? How?
Table and Design Patterns 16 © 2008 Solid Quality Mentors OLTP Reference Transactional History/Audit OLAP Dimension Fact Tables
Partition Types: Horizontal 17 Out of the Box : in SQL 2005/2008
Horizontal Partition Methods RANGE –Out of the Box (SQL 2005, SQL 2008) HASH –Build your own (Calculated Column/Hash/Range) LIST –Build your own (RANGE or Partitioned Views) 18 © 2008 Solid Quality Mentors
Partition Types: Vertical 19 Out of the Box : (n)text, image, xml, (n)varchar(max), varbinary(max) and CLR Types. Build your own : Views and Instead of Trigger
Index Structures 20 © 2008 Solid Quality Mentors Clustered IndexNon-clustered Index
Partitioned Table/non-partitioned Index 21 © 2008 Solid Quality Mentors Clustered IndexNon-clustered Index
Non Partitioned Table/Partitioned Index 22 © 2008 Solid Quality Mentors Clustered IndexNon-clustered Index Filtered Indexes
Partitioned Table/Aligned Index 23 © 2008 Solid Quality Mentors Clustered IndexNon-clustered Index
Partitioned View CREATE VIEW SalesDataMart.FactSalesByStore WITH SCHEMABINDING AS( SELECT IdDimDate, IdDimStore, SUM(OrderedQuantity) AS OrderedQuantity, SUM(TotalSalesAmount) AS TotalSalesAmount, SUM(TotalProductCost) AS TotalProductCost, COUNT_BIG(*) AS OrderNum FROM SalesDataMart.FactSales GROUP BY IdDimDate, IdDimStore) GO CREATE UNIQUE CLUSTERED INDEX PK_FactSalesByStore ON SalesDataMart.FactSalesByStore(IdDimDate, IdDimStore) ON Annual(IdDimDate); GO
Partitioning and Query Performance
Agenda 26 © 2008 Solid Quality Mentors Why?How?What?Where? Logical/Physical Method Toolbox
Without Partitions Disk File Filegroup Partition Primary
Simple: Partitioned Disk File Filegroup Partition Primary
Multiple: Without Partitions Disk File Filegroup Partition Primary
Multiple: with Partitions (1/3) Disk File Filegroup Partition Primary
Multiple: with Partitions (2/3) Disk File Filegroup Partition Primary
Multiple: with Partitions (3/3) Disk File Filegroup Partition Primary
Partitioning Availability and Maintainability Backup/Restore
Agenda 34 © 2008 Solid Quality Mentors Why?How?What?Where?Toolbox Pruning Loading
Pruning
Sliding Window Loading
Agenda 37 © 2008 Solid Quality Mentors Why?How?What?Where?Partitioning Toolbox
Please remember to fill out evaluations