Partitioning techniques in SQL Server Eladio Rincon (ERincon@solidq.com)ERincon@solidq.com Javier Loria (javier@solidq.com)javier@solidq.com Solid Quality.

Post on 23-Dec-2015

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

Transcript

Partitioning techniques in SQL Server

Eladio Rincon (ERincon@solidq.com)Javier Loria (javier@solidq.com)Solid Quality Mentors

2

Agenda

© 2008 Solid Quality Mentors

Why?

How?

What?

Where?

Partitioning Toolbox

3

Agenda

© 2008 Solid Quality Mentors

Why?

• Definition• I/O Basics• Table Basics• Operational Benefits

How?

What?

Where?

Toolbox

Definition

4© 2008 Solid Quality Mentors

Physical segregation of a single logical table

name into multiple, identical physical structures

5

I/O BasicsOperation File Type Read Write

SELECT Database Random Synchronous -

INSERTUPDATEDELETE

Log Sequential - Synchronous

Database Random - Asynchronous

Bulk Insert Database Random Synchronous

Full Backup Database Sequential Synchronous *

Log Backup Log Sequential Synchronous -

Reindex Random ? ?

© 2008 Solid Quality Mentors OLTP8x58

8

8

24x7OLTP24

24

24

24

24

OLAPS

S

S

S

6

Table Basics

© 2008 Solid Quality Mentors

7

Operational Benefits

Performanc

eQuery(OLPT/OLAP)

Bulk-Insert

(OLAP)

Availability

Full Backups

Maintainabil

ityArchivi

ngPruning

Reindex

© 2008 Solid Quality Mentors

Poor’s Mans Table PartitioningCreating and using partitioned views

9

Agenda

© 2008 Solid Quality Mentors

Why?

• Partition Function• Partition Scheme• Create Table Reloaded• Create Index Reloaded

How?

What?

Where?

Toolbox

Partition Function

10© 2008 Solid Quality Mentors

CREATE PARTITION FUNCTION Annual (INT) AS RANGE RIGHT FOR VALUES (20060101 , 20070101, 20080101, 20090101, 20100101);

Partition Scheme

11© 2008 Solid Quality Mentors

CREATE PARTITION SCHEME AnnualAS PARTITION AnnualTO (EmptyHistory, Fact2006, Fact2007, Fact2008, Fact2009, EmptyFuture)

12

Create Table Reloaded

© 2008 Solid Quality Mentors

CREATE TABLE SalesDataMart.FactVendas( IdDimDate INT NOT NULL, IdDimProduct INT NOT NULL, IdDimCustomers INT NOT NULL, IdDimStore INT NOT NULL, OrderedQuantity INT NOT NULL, TotalSalesAmount DECIMAL (19, 2) NOT NULL, TotalProductCost DECIMAL (19, 2) NOT NULL, POSNum INT NOT NULL, InvoceNum INT NOT NULL) ON Annual(IdDimDate);

Create Index Reloaded

13© 2008 Solid Quality Mentors

CREATE CLUSTERED INDEX IDX_FactSalesON 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 101Partitioned Hello World

15

Agenda

© 2008 Solid Quality Mentors

Why?

• Table Design Patterns• Partition Types• Partition Methods• Index Partitions

How?

What?

Where?

How?

16

Table and Design Patterns

© 2008 Solid Quality Mentors

OLTP• Reference• Transactional• History/Audit

OLAP• Dimension• Fact Tables

17

Partition Types: Horizontal

Out of the Box: in SQL 2005/2008

18

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)

© 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 Index Non-clustered Index

Partitioned Table/non-partitioned Index

21© 2008 Solid Quality Mentors

Clustered Index Non-clustered Index

Non Partitioned Table/Partitioned Index

22© 2008 Solid Quality Mentors

Clustered Index Non-clustered Index

Filtered Indexes

Partitioned Table/Aligned Index

23© 2008 Solid Quality Mentors

Clustered Index Non-clustered Index

Partitioned ViewCREATE VIEW SalesDataMart.FactSalesByStore WITH SCHEMABINDING AS(SELECT IdDimDate, IdDimStore , SUM(OrderedQuantity) AS OrderedQuantity , SUM(TotalSalesAmount) AS TotalSalesAmount , SUM(TotalProductCost) AS TotalProductCost , COUNT_BIG(*) AS OrderNumFROM SalesDataMart.FactSalesGROUP BY IdDimDate, IdDimStore)GO

CREATE UNIQUE CLUSTERED INDEX PK_FactSalesByStoreON SalesDataMart.FactSalesByStore(IdDimDate, IdDimStore)ON Annual(IdDimDate);GO

Partitioningand Query Performance

26

Agenda

© 2008 Solid Quality Mentors

Why?

• Logical/Physical• Method

How?

What?

Where?

Toolbox

Without Partitions

Disk

File

Filegroup

Partition

Primary

Simple: Partitioned

Disk

File

Filegroup

Partition

Primary 2006 2007 2008 2009

Multiple: Without Partitions

Disk

File

Filegroup

Partition

Primary

Multiple: with Partitions (1/3)

Disk

File

Filegroup

Partition

Primary 2006 2007 2008 2009

High Availability

Multiple: with Partitions (2/3)

Disk

File

Filegroup

Partition

Primary 2006 2007 2008 2009

Performance

Multiple: with Partitions (3/3)

Disk

File

Filegroup

Partition

Primary 2006 2007 2008 2009

PartitioningAvailability and MaintainabilityBackup/Restore

34

Agenda

© 2008 Solid Quality Mentors

Why?

• Pruning• Loading

How?

What?

Where?

Toolbox

Pruning

Sliding Window Loading

37

Agenda

© 2008 Solid Quality Mentors

Why?

How?

What?

Where?

Partitioning Toolbox

Thank You!!Thank You!!

Please remember to fill out evaluations

top related