database design: size does matter! · database design: size does matter! thomas larock technical...

89
Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only 1

Upload: others

Post on 19-Jul-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Database Design: Size DOES Matter!

Thomas LaRock

Technical Evangelist and Senior DBA

Confio Software

5/11/2013 Confidential - Internal Use Only 1

Page 2: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Why Are You Here?

• You have data

• It is growing larger

• Performance suffers

• You want to make things better

– Or you have been told to make things better

5/11/2013 Confidential - Internal Use Only 2

Page 3: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

A little about me…

Thomas LaRock

[email protected] thomaslarock.com

@sqlrockstar

Page 4: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Agenda

• What’s the problem?

• Why datatypes matter

• Solution options

5/11/2013 Confidential - Internal Use Only 4

Page 5: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

THE PROBLEM

5/11/2013 Confidential - Internal Use Only 5

Page 6: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

The Problem

• Your database has a design

– Just like a ship, or a car, has a design

5/11/2013 Confidential - Internal Use Only 6

Page 7: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

The Problem

• Your database has a design

– Just like a ship, or a car, has a design

5/11/2013 Confidential - Internal Use Only 7

Page 8: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

The Problem

• Your database has a design

– Just like a ship, or a car, has a design

• Data goes in, rarely falls off

5/11/2013 Confidential - Internal Use Only 8

Page 9: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

The Problem

• Your database has a design

– Just like a ship, or a car, has a design

• Data goes in, rarely falls off

• Databases are mixed-use

5/11/2013 Confidential - Internal Use Only 9

Page 10: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

The Problem

• Your database has a design

– Just like a ship, or a car, has a design

• Data goes in, rarely falls off

• Databases are mixed-use

• Data professionals are often asked to convert a pickup truck into

5/11/2013 Confidential - Internal Use Only 10

Page 11: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

The Problem

• Your database has a design

– Just like a ship, or a car, has a design

• Data goes in, rarely falls off

• Databases are mixed-use

• Data professionals are often asked to convert a pickup truck into a Ferrari

5/11/2013 Confidential - Internal Use Only 11

Page 12: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

The Problem

• Your database has a design

– Just like a ship, or a car, has a design

• Data goes in, rarely falls off

• Databases are mixed-use

• Data professionals are often asked to convert a pickup truck into a Ferrari

• Great database performance starts with great database design

5/11/2013 Confidential - Internal Use Only 12

Page 13: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

How Database Designs Fail

• Many designs do not account for size

5/11/2013 Confidential - Internal Use Only 13

Page 14: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

How Database Designs Fail

• Many designs do not account for size

• Rowcounts might be considered

5/11/2013 Confidential - Internal Use Only 14

Page 15: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

How Database Designs Fail

• Many designs do not account for size

• Rowcounts might be considered

• What about inside the rows?

– Those are the columns

– Their width is often overlooked

5/11/2013 Confidential - Internal Use Only 15

Page 16: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

WHY DATATYPES MATTER

5/11/2013 Confidential - Internal Use Only 16

Page 17: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

DATABASE

What Is A Database, Really?

5/11/2013 Confidential - Internal Use Only 17

Page 18: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

DATABASE

What Is A Database, Really?

5/11/2013 Confidential - Internal Use Only 18

F1 F2 FN…

Page 19: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

DATABASE

What Is A Database, Really?

Col1 Col2 Col3 Col4

val1 val2 val3 val4

… … … …

… … … …

5/11/2013 Confidential - Internal Use Only 19

F1 F2 FN…

Page 20: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

DATABASE

What Is A Database, Really?

Col1 Col2 Col3 Col4

val1 val2 val3 val4

… … … …

… … … …

5/11/2013 Confidential - Internal Use Only 20

F1 F2 FN…

Page 21: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

DATABASE

What Is A Database, Really?

Col1 Col2 Col3 Col4

val1 val2 val3 val4

… … … …

… … … …

5/11/2013 Confidential - Internal Use Only 21

F1 F2 FN

Row length

Page 22: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

DATABASE

What Is A Database, Really?

Col1 Col2 Col3 Col4

val1 val2 val3 val4

… … … …

… … … …

5/11/2013 Confidential - Internal Use Only 22

F1 F2 FN

Row length

Page 23: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

DATABASE

What Is A Database, Really?

Col1 Col2 Col3 Col4

val1 val2 val3 val4

… … … …

… … … …

5/11/2013 Confidential - Internal Use Only 23

F1 F2 FN

Row length

…8k

Page 24: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

DATABASE

What Is A Database, Really?

Col1 Col2 Col3 Col4

val1 val2 val3 val4

… … … …

… … … …

5/11/2013 Confidential - Internal Use Only 24

F1 F2 FN

Row length

…8k

Page 25: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

What Is an Integer?

• Math major says: integers are numbers, positive and negative, including 0, without any fractions

5/11/2013 Confidential - Internal Use Only 25

Page 26: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

What Is an Integer?

• Math major says: integers are numbers, positive and negative, including 0, without any fractions

• Database designer: integers are the range of numbers from -2,147,483,648 to 2,147,483,647 and require 4 bytes of storage

5/11/2013 Confidential - Internal Use Only 26

Page 27: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

What Is an Integer?

• Math major says: integers are numbers, positive and negative, including 0, without any fractions

• Database designer: integers are the range of numbers from -2,147,483,648 to 2,147,483,647 and require 4 bytes of storage

• Do you see a disconnect there?

5/11/2013 Confidential - Internal Use Only 27

Page 28: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Visual Studio Defaults

5/11/2013 Confidential - Internal Use Only 28

Page 29: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Visual Studio Defaults

5/11/2013 Confidential - Internal Use Only 29

Page 30: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Visual Studio Defaults

5/11/2013 Confidential - Internal Use Only 30

Page 31: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Visual Studio Defaults

5/11/2013 Confidential - Internal Use Only 31

Mismatch Likely!

Page 32: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

SSMS Defaults

5/11/2013 Confidential - Internal Use Only 32

Page 33: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

SSMS Defaults

5/11/2013 Confidential - Internal Use Only 33

Page 34: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

SSMS Defaults

5/11/2013 Confidential - Internal Use Only 34

Page 35: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

SSMS Defaults

5/11/2013 Confidential - Internal Use Only 35

Page 36: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Date Example

Datatype Name Length (bytes)

Date 3

Smalldatetime 4

Time 5

Datetime2 6, 7, or 8

Datetime 8

Datetimeoffset 10

5/11/2013 Confidential - Internal Use Only 36

Page 37: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Where Will This Hurt?

• Disk space

• Memory space

• Performance

5/11/2013 Confidential - Internal Use Only 37

Page 38: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #1: Disk Space

• Disk is cheap…sure it is…but there are hidden costs!

– More storage = longer maintenance

– More storage = longer database backups

– More storage = longer tape backups

5/11/2013 Confidential - Internal Use Only 38

Page 39: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #1: Disk Space

• Disk is cheap…sure it is…but there are hidden costs!

– More storage = longer maintenance

– More storage = longer database backups

– More storage = longer tape backups

• Most are unaware how that tiny piece of data is stored multiple times

– Wide clustering key is spread to EVERY NC index!

5/11/2013 Confidential - Internal Use Only 39

Page 40: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #2: Memory Space

• Those extra bytes are read from disk into SQL Server buffer cache

5/11/2013 Confidential - Internal Use Only 40

Page 41: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #2: Memory Space

• Those extra bytes are read from disk into SQL Server buffer cache

• Extra Logical I/O needed to return a query result

5/11/2013 Confidential - Internal Use Only 41

Page 42: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #2: Memory Space

• Those extra bytes are read from disk into SQL Server buffer cache

• Extra Logical I/O needed to return a query result

• What about indexes?

– Same thing, they drag around the extra I/O

5/11/2013 Confidential - Internal Use Only 42

Page 43: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

EXTRA LOGICAL I/ODEMO

5/11/2013 Confidential - Internal Use Only 43

Page 44: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #3: Performance

• Datatype mismatch results in implicit conversions

5/11/2013 Confidential - Internal Use Only 44

Page 45: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #3: Performance

• Datatype mismatch results in implicit conversions

• Optimizer knows this is bad, will display a warning for you

5/11/2013 Confidential - Internal Use Only 45

Page 46: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #3: Performance

• Datatype mismatch results in implicit conversions

• Optimizer knows this is bad, will display a warning for you

• It is up to you to make a change, SQL Server won’t change your code for you!

5/11/2013 Confidential - Internal Use Only 46

Page 47: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Datatype Pain #3: Performance

• Datatype mismatch results in implicit conversions

• Optimizer knows this is bad, will display a warning for you

• It is up to you to make a change, SQL Server won’t change your code for you!

• Issue with code generators (ADO.NET 3.5, EMF, nHibernate, LINQ)

– Supposedly fixed?

5/11/2013 Confidential - Internal Use Only 47

Page 48: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

IMPLICIT CONVERSIONSDEMO

5/11/2013 Confidential - Internal Use Only 48

Page 49: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

SOLUTION OPTIONS

5/11/2013 Confidential - Internal Use Only 49

Page 50: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

First Step: Admit You Have a Problem!

• First sign: when OLAP queries interfere with OLTP processing

5/11/2013 Confidential - Internal Use Only 50

Page 51: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

First Step: Admit You Have a Problem!

• First sign: when OLAP queries interfere with OLTP processing

• For SQL Server, that typically means high levels of locking waits and blocking

5/11/2013 Confidential - Internal Use Only 51

Page 52: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

First Step: Admit You Have a Problem!

• First sign: when OLAP queries interfere with OLTP processing

• For SQL Server, that typically means high levels of locking waits and blocking

• Another sign: plan cache bloat

5/11/2013 Confidential - Internal Use Only 52

Page 53: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Solutions

• Find duplicate/unused/misused indexes

• Compression

• Filtered indexes

• Archiving/partitioning

• Verify datatypes are correct

• Update code

• Update architecture

5/11/2013 Confidential - Internal Use Only 53

Page 54: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Index Maintenance

• Want to reduce the extra I/O

– Remove duplicate indexes

– Remove unused/misused indexes

5/11/2013 Confidential - Internal Use Only 54

Page 55: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Index Maintenance

• Want to reduce the extra I/O

– Remove duplicate indexes

– Remove unused/misused indexes

• Test thoroughly!

– Examine plan cache to find if indexes are used

– Plan cache resets on service restart (or manual)

5/11/2013 Confidential - Internal Use Only 55

Page 56: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only
Page 57: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Solutions

• Find duplicate/unused/misused indexes

• Compression

• Filtered indexes

• Archiving/partitioning

• Verify datatypes are correct

• Update code

• Update architecture

5/11/2013 Confidential - Internal Use Only 57

Page 58: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Compression

• Native compression has two steps

– Row compression

– Page compression

– Each table/index requires compression to be enabled

5/11/2013 Confidential - Internal Use Only 58

Page 59: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

ROW/PAGE COMPRESSIONDEMO

5/11/2013 Confidential - Internal Use Only 59

Page 60: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Compression

• Native compression has two steps

– Row compression

– Page compression

– Each table/index requires compression to be enabled

• ColumnStore

– Dictionary compression

– Segments and batches

5/11/2013 Confidential - Internal Use Only 60

Page 61: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Solutions

• Find duplicate/unused/misused indexes

• Compression

• Filtered indexes

• Archiving/partitioning

• Verify datatypes are correct

• Update code

• Update architecture

5/11/2013 Confidential - Internal Use Only 61

Page 62: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Filtered Indexes

• Look like regular indexes

– Contain a WHERE clause

• Smaller footprint

• Less logical I/O

5/11/2013 Confidential - Internal Use Only 62

Page 63: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Solutions

• Find duplicate/unused/misused indexes

• Compression

• Filtered indexes

• Archiving/partitioning

• Verify datatypes are correct

• Update code

• Update architecture

5/11/2013 Confidential - Internal Use Only 64

Page 64: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Partitioning

• Can be viable alternative to proper archiving

5/11/2013 Confidential - Internal Use Only 65

Page 65: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Partitioning

• Can be viable alternative to proper archiving

• Queries hit only the partitions necessary

– Better than full table scans

5/11/2013 Confidential - Internal Use Only 66

Page 66: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Partitioning

• Can be viable alternative to proper archiving

• Queries hit only the partitions necessary

– Better than full table scans

• Easier to maintain

– Not necessarily easier to administer!

5/11/2013 Confidential - Internal Use Only 67

Page 67: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Partitioning

• Can be viable alternative to proper archiving

• Queries hit only the partitions necessary

– Better than full table scans

• Easier to maintain

– Not necessarily easier to administer!

5/11/2013 Confidential - Internal Use Only 68

Page 68: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Solutions

• Find duplicate/unused/misused indexes

• Compression

• Filtered indexes

• Archiving/partitioning

• Verify datatypes are correct

• Update code

• Update architecture

5/11/2013 Confidential - Internal Use Only 69

Page 69: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Verify Datatypes

• Compare datatype definition to actual data

– i.e., BIGINT defined, but only SMALLINT used

5/11/2013 Confidential - Internal Use Only 70

Page 70: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Verify Datatypes

• Compare datatype definition to actual data

– i.e., BIGINT defined, but only SMALLINT used

• You can estimate savings

– Space as well as LIO

5/11/2013 Confidential - Internal Use Only 71

Page 71: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Verify Datatypes

• Compare datatype definition to actual data

– i.e., BIGINT defined, but only SMALLINT used

• You can estimate savings

– Space as well as LIO

• Can be intrusive to alter

– Especially if PK/FK defined

5/11/2013 Confidential - Internal Use Only 72

Page 72: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Verify Datatypes

• Compare datatype definition to actual data

– i.e., BIGINT defined, but only SMALLINT used

• You can estimate savings

– Space as well as LIO

• Can be intrusive to alter

– Especially if PK/FK defined

• Periodically check to make sure you are not running out!

5/11/2013 Confidential - Internal Use Only 73

Page 73: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

VERIFY DATATYPESDEMO

5/11/2013 Confidential - Internal Use Only 74

Page 74: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Solutions

• Find duplicate/unused/misused indexes

• Compression

• Filtered indexes

• Archiving/partitioning

• Verify datatypes are correct

• Update code

• Update architecture

5/11/2013 Confidential - Internal Use Only 75

Page 75: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Update Code/Architecture

• If you are seeing the signs, then you may consider updating code

5/11/2013 Confidential - Internal Use Only 76

Page 76: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Update Code/Architecture

• If you are seeing the signs, then you may consider updating code

• Some frameworks are not optimal

– ADO.NET 3.5

– LINQ to SQL

– EMF

5/11/2013 Confidential - Internal Use Only 77

Page 77: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Update Code/Architecture

• If you are seeing the signs, then you may consider updating code

• Some frameworks are not optimal

– ADO.NET 3.5

– LINQ to SQL

– EMF

• Scale out architecture

– Create real reporting solution

– AlwaysOn

5/11/2013 Confidential - Internal Use Only 78

Page 78: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

1. Understand the storage requirements for every datatype you consider

5/11/2013 Confidential - Internal Use Only 79

Page 79: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

1. Understand the storage requirements for every datatype you consider

2. Review all design decisions based on the shape of the data – where it is now and where it is likely to be later.

5/11/2013 Confidential - Internal Use Only 80

Page 80: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

1. Understand the storage requirements for every datatype you consider

2. Review all design decisions based on the shape of the data – where it is now and where it is likely to be later.

3. Set datatypes based on business requirements, not tool defaults

5/11/2013 Confidential - Internal Use Only 81

Page 81: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

4. Measure and monitor fit of the data to its datatypes regularly

5/11/2013 Confidential - Internal Use Only 82

Page 82: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

4. Measure and monitor fit of the data to its datatypes regularly

5. Review each index creation request to see if it is duplicate

5/11/2013 Confidential - Internal Use Only 83

Page 83: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

4. Measure and monitor fit of the data to its datatypes regularly

5. Review each index creation request to see if it is duplicate

6. Measure for unused and duplicate indexes regularly

5/11/2013 Confidential - Internal Use Only 84

Page 84: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

7. Review new stored procedures to verify parameters are matching

5/11/2013 Confidential - Internal Use Only 85

Page 85: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

7. Review new stored procedures to verify parameters are matching

8. Find longest running and most often used queries

5/11/2013 Confidential - Internal Use Only 86

Page 86: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

7. Review new stored procedures to verify parameters are matching

8. Find longest running and most often used queries

9. Look for implicit conversions in your plan cache

5/11/2013 Confidential - Internal Use Only 87

Page 87: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

10 Steps For Right Sizing

7. Review new stored procedures to verify parameters are matching

8. Find longest running and most often used queries

9. Look for implicit conversions in your plan cache

10.Remember that size matters

5/11/2013 Confidential - Internal Use Only 88

Page 88: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

Summary

• What’s the problem?

• Why datatypes matter

• Solution options

5/11/2013 Confidential - Internal Use Only 89

Page 89: Database Design: Size DOES Matter! · Database Design: Size DOES Matter! Thomas LaRock Technical Evangelist and Senior DBA Confio Software 5/11/2013 Confidential - Internal Use Only

For More Information

• http://tinyurl.com/sql-datatypes

• http://tinyurl.com/imp-cols-in-plan-cache

• http://tinyurl.com/data-access-perf

• http://tinyurl.com/row-compression

5/11/2013 Confidential - Internal Use Only 93