Learn. Connect. Explore.Learn. Connect. Explore.
SQL Server 2014 :Online Operation Enhancements
Vinod Kumar
Technical Architect – MTC
vinodk_sql
http://blogs.ExtremeExperts.com
So is Online Truly Online??
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
Session Objectives And Takeaways
Online
Operations
DemosBest PracticesManaged Lock
Priority
Single Partition Online
Index Rebuild
Partition SWITCHShort Sch-M lock on the source and
target tables
Online Index Rebuild (OIR) Short table S and Sch-M lock
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
Pro
ble
m
Sta
tem
en
tBlocking by online DDL operations Concurrency and throughput affected
Behavior without Managed Lock Priority
Lock QueueSession
Wait
Grant
51-SELECT
52-DDL
53-SELECT
54-SELECT
55-SELECT First In First Out
MLP SWITCH/OIR – Options
Blocking user
transactions killed
Immediately or
specified wait time
MAX_DURATION* =n
minutes]
Wait for blockers
MAX_DURATION*
Regular lock queue
Kill all blockers Switch to normal queue
Wait for blockers
MAX_DURATION*
Terminates DDL
(SWITCH/OIR)
Exit DDL after wait
*If no blockers, lock granted immediately and the DDL statement will complete
successfully
MLP SWITCH/OIR – Details
PARTITION SWITCHSch-M lock (source and destination)
Blocking by user transactions
Killed at source and destination tables
ONLINE INDEX REBUILDMAX_DURATION applies to every lock request
Time reset for every S & Sch-M lock
Only Sch-M lock conflict for read only workloads
BenefitsManaged 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
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
<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
MLP SWITCH/OIR – Syntax
New clause in existing T-SQL DDL for ALTER TABLE and
ALTER INDEX
SQL 2012 behavior – omit the
new clause or use
WITH (WAIT_AT_LOW_PRIORITY
(MAX_DURATION= 0
minutes,
ABORT_AFTER_WAIT=NONE))
Behavior with MLP
Lock QueueSession
Low Priority Wait
Grant
51-SELECT
52-DDL
53-SELECT
54-SELECT
55-SELECT
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
• One or more partitionsGranularity
• Table accessible for DML and query operations
• Short term locks beginning and end of the index rebuildAccessibility
• Use Managed Lock Priority with SPOIRLock Priority
• Reduced down time for mission critical workloadsAvailability
• CPU, memory and disk space
• Log space usage reducedResource savings
SPOIR - Syntax
ALTER INDEX clidx ON part_table REBUILD
PARTITION= 3
WITH ( ONLINE=ON
(WAIT_AT_LOW_PRIORITY
(MAX_DURATION= 300,
ABORT_AFTER_WAIT=NONE)) )
Example
<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 } )
}
Syntax
Best Practices
• Long running queries/transactions
• May not be beneficial in workloads with short
transactions
ABORT_AFTER_WAIT=BLOCKERS
• SWITCH acquires locks on source and target tables
• Wait on the second lock affects concurrency on first
• Dormant tables
Locking
• Nested transaction holds locks longer
DDL Transaction
• Log truncation affected by MAX_DURATION
• Extra logging OIR DDL operation
• Can lead to system performance issue
Transaction Log Growth
Tell us what you think
Scan the QR code to evaluate
this session.
Lock Manager changes
Stores Kill, Low Priority Convert and Low Priority Wait requests
Scan GRANT queue and if no conflicting locks GRANT immediately
Place in KILL queue and sleep till all tasks with conflicting locks are aborted
Only one KILL request supported at a time
Scan KILL queue which has higher priority first
Grant, Convert and Wait queues scanned next and request placed accordingly
Wait behind existing KILL, normal priority and other low priority requests
Add to Low Priority Convert or Low Priority Wait as applicable
ReferencesRelated references for you to expand your knowledge on the subject• <Quote related references here>
technet.microsoft.com/en-in
aka.ms/mva
msdn.microsoft.com/