Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with...

38

Transcript of Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with...

Page 1: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 2: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 3: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

Work with SQL from Version 2000

OLTP/ BI Database Design and Code Review

Performance Tuning

HA/DR Plan Design

Upgrade/ Migration/ Consolidation

Capacity Planning

Health Check

Page 4: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 5: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 6: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 7: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

- Columnstore indexes store data column-wise

- Highly compressed

- Each column can be accessed independently

C1 C2 C3 C4

- Heaps, B-trees store data row-wise

Rowstore

Columnstore

Page 8: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

Up to 1000 rows per operation

Row mode 1 row per operation

Batch Mode Less CPU usage

Page 9: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 10: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 11: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

Pros Less CPU time

Row mode requires to read metadata

every single one operation

Cons Batch mode requires larger memory size

Page 12: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

MAXDOP > 1

Outer Join

IN

DOs

DON’Ts NOT IN UNION ALL

HASH JOIN Hint

EXISTS

Page 13: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 14: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 15: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 16: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

Segments

Minimum

Logical

Data Chunk 1 million rows

Meta data Max ValueMin Value

Page 17: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

Storage Engine

Check Filter Condition

Check Meta Data

Eliminate unnecessary segments

Page 18: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

column_id segment_id min_data_id max_data_id

1 1 20120601 20120630

1 2 20120615 20120715

1 3 20120701 20120731

1 4 20120715 20120815sys.column_store_segments

select C1, sum(C2)

from T

where C1 between 20120618 and 20120713

group by C1

Segment_id 4 can be eliminated

Page 19: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

xEvent

column_store_segment_eliminate

Debug Channel

Attention:

Number of events

Size of xel file

Trace Flag 646

Undocumented

But

found in Technet site…

Page 20: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

column_id segment_id min_data_id max_data_id

1 1 20120601 20120730

1 2 20120620 20120812

1 3 20120713 20120831

1 4 20120710 20120915Not Sorted Data

Data is mixed between

segments

Difficult

To

Maximize the benefit of segment elimination

select C1, sum(C2)

from T

where C1 between 20120618 and 20120713

group by C1

Page 21: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

column_id segment_id min_data_id max_data_id

1 1 20120601 20120630

1 2 20120701 20120731

1 3 20120801 20120831

1 4 20120901 20120930Sorted Data

Clear border of Segments

Easy

To

Maximze the benefit of Segment

Elimination

Ensure data is sorted effectively Clustered Index

select C1, sum(C2)

from T

where C1 between 20120618 and 20120713

group by C1

Page 22: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 23: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 24: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

Nightly Load Scenario

Drop-Rebuild Strategy

Common in BI space

Data

Warehouse Data Mart

Required Fast Parallel Columnstore Index Builds

Page 25: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

DOP

Memory Size

Check sys.dm_exec_query_memory_grants

Required size in MB =

[(4.2 *Num of cols in the CS idx) + 68]*DOP + (Num of string cols * 34)

Page 26: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

8657/8658 Error

Page 27: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

8657/8658 Error

Msg 8657

Could not get the memory grant of %I64d KB because it exceeds the maximum

configuration limit in workload group '%ls' (%ld) and resource pool '%ls' (%ld).

Contact the server administrator to increase the memory usage limit.

Msg 8658

Cannot start the columnstore index build because it requires at least %I64d KB,

while the maximum memory grant is limited to %I64d KB per query in workload

group '%ls' (%ld) and resource pool '%ls' (%ld).

Retry after modifying columnstore index to contain fewer columns, or after

increasing the maximum memory grant limit with Resource Governor.

Page 28: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

8657/8658 Error

Increase RESOURCE GOVERNOR Default Pool Setting

REQUEST_MAX_MEMORY_GRANT_PERCENT= 25% (Should be <=50%)

Page 29: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 30: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning

Partitioned Table Scenario Switch Partition Strategy

Improvement for avoiding DDL Starvation

Page 31: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 32: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 33: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 34: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 35: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 36: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 37: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning
Page 38: Work with SQL from Version 2000download.microsoft.com/documents/hk/technet/techdays2013...Work with SQL from Version 2000 OLTP/ BI Database Design and Code Review Performance Tuning