partitioning design

15
Partitioning Design For Performance and Maintainability Martin Cairns http://sqlbyparts.com http://twitter.com/ MartinCairnsSQL

Upload: dolph

Post on 22-Feb-2016

53 views

Category:

Documents


0 download

DESCRIPTION

Partitioning Design. For Performance and Maintainability. Martin Cairns http://sqlbyparts.com http://twitter.com/MartinCairnsSQL. Who am I?. @MartinCairnsSQL. www.sqlbyparts.com. Partitioning Defined. Source: http://oxforddictionaries.com/definition/english/partition. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Partitioning  Design

Partitioning Design

For Performance and Maintainability

Martin Cairnshttp://sqlbyparts.com

http://twitter.com/MartinCairnsSQL

Page 2: Partitioning  Design

Who am I?

@MartinCairnsSQL

www.sqlbyparts.com

Page 3: Partitioning  Design

Partitioning Defined

Partitioning (noun)

1. the action or state of dividing or being divided into parts

2. a structure dividing a space into two parts

Source: http://oxforddictionaries.com/definition/english/partition

Page 4: Partitioning  Design

Types of Partitioning

• Horizontal• Partition Table by Rows

• Vertical• Partition Table by Columns

• File Group• Partition Tables by File Group

Page 5: Partitioning  Design

Horizontal Partitioning

Divides the rows into small sets by boundariesYear PK Order ID Product ID Qty Cost Line XML2010 1 1 1 5 1.5 <Line…

2010 2 1 1 7 2 <Line…

2011 1000000 20000 345 1000 5 <Line…

2011 1000001 20000 347 3000 12 <Line…

2012 2000000 40000 705 8000 3 <Line…

2012 2000001 40001 706 3000 7 <Line…

Page 6: Partitioning  Design

Vertical Partitioning

Divides columns from one table into multiple tablesYear PK Order ID …2010 1 1 …

2010 2 1 …2011 1000000 345 …2011 1000001 347 …2012 2000000 705 …2012 2000001 706 …

Year PK Line XML2010 1 <Line…

2010 2 <Line…2011 1000000 <Line…2011 1000001 <Line…2012 2000000 <Line…2012 2000001 <Line…

Page 7: Partitioning  Design

File Group Partitioning

File group partitioning is separating the storage of tables and indexes onto separate database files

During a Primary File Group restore the whole database will be offline

Separate the system & user tables to allow the quickest restore time

Since the partitioned database is made up of smaller parts it is easier to manage the storage location of the files

Page 8: Partitioning  Design

Using Table Partitioning

Supports Horizontal Partitioning Partition Function defines boundaries based

on a single column Partition Scheme defines the File Group Inserts automatically supported All partitions share the same definition as the

table (indexes, columns, fill factor etc)

Page 9: Partitioning  Design

Table Level Limitations

Only ~200 steps for each statistics across the whole table

Online Index rebuilds are for the whole table not individual partitions

Fill Factor Lock settings (Row, Page, Escalation, etc) Indexes are defined for the whole table rather

than partitions

Page 10: Partitioning  Design

Using View Partitioning

View Partitioning allows you to overcome Table Level Constraints

Check Constraints used to define partitions Combine all tables with a UNION ALL View Can be used together with Table Partitioning Trigger required to allow INSERT with Identity

column Allows more complex partitioning schemes

Page 11: Partitioning  Design

Candidates for Partitioning

Large vs. Small Tables Replicated vs. Non-Replicated Tables Normal vs. BLOB columns Write Heavy Current data vs. Heavily

Read Historic data Read \ Write vs. Read Only Tables

Page 12: Partitioning  Design

Partial Database Availability

Also referred to as Piecemeal Restore Full Recovery Model is Required Individual File & File Groups Restore Only the Primary File Group is required to

restore a database Allows restoring a subset of a correctly

partitioned database for quicker recovery from a disaster

Page 13: Partitioning  Design

Tipping Point \ Why is it Table Scanning

As the number of rows in a table increase the depth of the B+Tree increases

The number of Page Reads for a lookup is equal to the depth of the B+Tree

The Tipping Point is the point where a Full Table Scan requires less Page Reads than the lookups

Page 14: Partitioning  Design

What Does Partition Give Us

Choices Using different Tiers of Storage Allows quicker recovery strategies Allows partial restores of the database

Performance Allows reduction of overhead of backups Allows better query plans due to more

accurate statistics on large tables

Page 15: Partitioning  Design

Demos

Moving Tables to File Groups Partial Restore + Using Partial Restore to

Initialise Replication Moving Partition Between Tables For Current

vs. Historic Show how View Partitioning can present a

single view of all tables & still support partition elimination