Вы находитесь на странице: 1из 21

SQL Server 2014 :

Online Operation Enhancements


Vinod Kumar
Technical Architect MTC
vinodk_sql
http://blogs.ExtremeExperts.com

So is Online Truly Online??

Session Objectives And Takeaways


Understand the changes to partition switching in SQL Server 2014
Understand the changes to online indexing options to manage OLTP workloads in
SQL Server 2014

Online
Operations

Managed Lock
Priority

Single Partition Online


Index Rebuild

Best Practices

Demos

Problem
Statement

Blocking by online DDL operations

Partition SWITCH

Short Sch-M lock on the source and


target tables

Online Index Rebuild (OIR)


Short table S and Sch-M lock

Concurrency and throughput affected

Blocking transactions need to be


completed before DDL

SWITCH/OIR will block new


transactions
Workload slow down or timeouts
Impact to Tier1 mission-critical OLTP
workloads

Behavior without Managed Lock Priority


51-SELECT

Grant
52-DDL

53-SELECT

Wait

54-SELECT
55-SELECT

Session

First In First Out

Lock Queue

MLP SWITCH/OIR Options


Kill all blockers

Blocking user
transactions killed
Immediately or
specified wait time
MAX_DURATION* =n
minutes]

Switch to normal queue

Exit DDL after wait

Wait for blockers

Wait for blockers

MAX_DURATION*

MAX_DURATION*

Regular lock queue

Terminates DDL
(SWITCH/OIR)

*If no blockers, lock granted immediately and the DDL statement will complete
successfully

MLP SWITCH/OIR Details


PARTITION SWITCH

Sch-M lock (source and destination)


Blocking by user transactions
Killed at source and destination tables

ONLINE INDEX REBUILD

MAX_DURATION applies to every lock request


Time reset for every S & Sch-M lock
Only Sch-M lock conflict for read only workloads

Benefits

Managed by DBA for both partition switch and OIR


Lock request placed in lower priority queue
Decision to wait or kill self or blockers
Executed immediately if no blockers

MLP SWITCH/OIR Syntax


New clause in existing T-SQL DDL for ALTER TABLE and
ALTER INDEX

<low_priority_lock_wait>::=

WAIT_AT_LOW_PRIORITY ( MAX_DURATION =
<time>[MINUTES],
}

ABORT_AFTER_WAIT = { NONE | SELF | BLOCKERS } )


NONE - current behavior
SELF - abort DDL
BLOCKERS abort user blockers

Syntax
SQL 2012 behavior omit the
new clause or use
WITH (WAIT_AT_LOW_PRIORITY
(MAX_DURATION= 0
minutes,
ABORT_AFTER_WAIT=NONE))

ALTER TABLE stgtab SWITCH PARTITION 1 TO parttab


PARTITION 1
WITH (WAIT_AT_LOW_PRIORITY (MAX_DURATION=
60 minutes,
ABORT_AFTER_WAIT=BLOCKERS))
ALTER INDEX clidx ON parttable REBUILD
WITH ( ONLINE=ON (WAIT_AT_LOW_PRIORITY
(MAX_DURATION= 300,
ABORT_AFTER_WAIT=SELF)) )

Examples

Behavior with MLP


51-SELECT

Grant

52-DDL
53-SELECT

Low Priority Wait

54-SELECT

55-SELECT

Session

Lock Queue

Permissions and Security


Current
ALTER TABLE
Requires ALTER permission on the table
Applies to both source and target tables
Switched data inherits the security of the target table
ALTER INDEX
ALTER permission on the table or view is required

MLP SWITCH/OIR
ABORT_AFTER_WAIT=BLOCKERS all blocking user transactions killed
ALTER ANY CONNECTION server wide permission

Limitations
Only user blocking sessions can be killed
System sessions cause blocking

SQL transaction log truncation delayed by MLP


MAX_DURATION=n time affects log truncation
Best Practice: Additional disk space
Best Practice: Properly define the MAX_DURATION time

SWITCH operation only supported between two tables or indexed views


MLP applies only to primary server
AlwaysOn, Transactional Replication

SPOIR - Benefits
Granularity

One or more partitions

Accessibility

Table accessible for DML and query operations


Short term locks beginning and end of the index rebuild

Lock Priority

Use Managed Lock Priority with SPOIR

Availability
Resource savings

Reduced down time for mission critical workloads


CPU, memory and disk space
Log space usage reduced

SPOIR - Syntax
<single_partition_rebuild_index_option> ::=
{
. | ONLINE = { ON [ ( <low_priority_lock_wait> ) ] | OFF
}
}
<low_priority_lock_wait>::=
{
WAIT_AT_LOW_PRIORITY ( MAX_DURATION =
<time>[MINUTES],
ABORT_AFTER_WAIT = { NONE | SELF | BLOCKERS } )
}

ALTER INDEX clidx ON part_table REBUILD


PARTITION= 3
WITH ( ONLINE=ON
(WAIT_AT_LOW_PRIORITY
(MAX_DURATION= 300,
ABORT_AFTER_WAIT=NONE)) )

Syntax

Example

Best Practices
ABORT_AFTER_WAIT=BLOCKERS

Locking

DDL Transaction

Transaction Log Growth

Long running queries/transactions


May not be beneficial in workloads with short
transactions
SWITCH acquires locks on source and target tables
Wait on the second lock affects concurrency on first
Dormant tables

Nested transaction holds locks longer

Log truncation affected by MAX_DURATION


Extra logging OIR DDL operation
Can lead to system performance issue

Вам также может понравиться