<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WAIT_AT_LOW_PRIORITY &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/wait_at_low_priority/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Fri, 22 Sep 2017 20:41:06 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server 2014: WAIT_AT_LOW_PRIORITY improved the performance of ONLINE REBUILD INDEX operation</title>
		<link>https://www.dbrnd.com/2017/11/sql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 12 Nov 2017 16:16:59 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[BLOCKER]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[MAX_DURATION]]></category>
		<category><![CDATA[REBUILD]]></category>
		<category><![CDATA[Rebuild Index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[WAIT_AT_LOW_PRIORITY]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6113</guid>

					<description><![CDATA[SQL Server 2014 introduced WAIT_AT_LOW_PRIORITY option which enhanced the performance of ONLINE REBUILD INDEX. In the previous version of SQL Server, REBUILD INDEX had to wait for the running transaction. But now in SQL Server 2014, you can give options like MAX_DURATION in minutes, ABORT_AFTER_WAIT with different options. For ABORT_AFTER_WAIT, took the reference from Microsoft: [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&amp;linkname=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F11%2Fsql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation%2F&#038;title=SQL%20Server%202014%3A%20WAIT_AT_LOW_PRIORITY%20improved%20the%20performance%20of%20ONLINE%20REBUILD%20INDEX%20operation" data-a2a-url="https://www.dbrnd.com/2017/11/sql-server-2014-wait_at_low_priority-improved-the-performance-of-online-rebuild-index-operation/" data-a2a-title="SQL Server 2014: WAIT_AT_LOW_PRIORITY improved the performance of ONLINE REBUILD INDEX operation"></a></p><p>SQL Server 2014 introduced WAIT_AT_LOW_PRIORITY option which enhanced the performance of ONLINE REBUILD INDEX.</p>
<blockquote><p>In the previous version of SQL Server, REBUILD INDEX had to wait for the running transaction.<br />
But now in SQL Server 2014, you can give options like MAX_DURATION in minutes, ABORT_AFTER_WAIT with different options.</p></blockquote>
<p><a href="https://docs.microsoft.com/en-us/sql/t-sql/statements/alter-index-transact-sql" target="_blank" rel="noopener noreferrer">For ABORT_AFTER_WAIT, took the reference from Microsoft:</a></p><pre class="crayon-plain-tag">ABORT_AFTER_WAIT = [NONE | SELF | BLOCKERS]</pre><p>
<strong>NONE:</strong> Continue waiting for the lock with normal (regular) priority.</p>
<p><strong>SELF:</strong> Exit the online index rebuild DDL operation currently being executed without taking any action.</p>
<p><strong>BLOCKERS:</strong> Kill all user transactions that block the online index rebuild DDL operation so that the operation can continue. The BLOCKERS option requires the login to have ALTER ANY CONNECTION permission.</p>
<p><strong>Please check the below demonstration, where I am comparing old and new approach of REBUILD INDEX:</strong></p>
<p><strong>Create a sample table:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_DumpData
(
	ID INT 
	,RandomID VARCHAR(MAX)
	,CONSTRAINT pk_tbl_DumpData_ID PRIMARY KEY(ID)
)
GO</pre><p>
<p><strong>Insert dummy data:</strong></p><pre class="crayon-plain-tag">;WITH CTE AS
(
	SELECT 1 ID
	UNION all
	SELECT ID + 1
	FROM CTE   
	WHERE ID + 1 &lt;= 100000
)
INSERT INTO tbl_DumpData(ID,RandomID)
SELECT 
	ID
	,NEWID() AS RandomID
FROM CTE 
OPTION (MAXRECURSION 0)
GO</pre><p>
<p><strong>Open new session/query window, execute below update:</strong></p><pre class="crayon-plain-tag">BEGIN TRANSACTION
UPDATE tbl_DumpData SET RandomID = 39840972340234 WHERE ID = 8</pre><p>
<p><strong>Jump to old session window, and execute below REBUILD:</strong><br />
<em>It is Running&#8230; Running&#8230; Running&#8230;, because table is locked by another transaction</em></p><pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
)
GO</pre><p>
<p><strong>Check the lock table:</strong><br />
You can find that your REBUILD query is in WAIT mode.</p><pre class="crayon-plain-tag">SELECT *FROM sys.dm_tran_locks</pre><p>
<img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-6115" src="https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock.png" alt="SQL Index Lock" width="740" height="136" srcset="https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock.png 740w, https://www.dbrnd.com/wp-content/uploads/2017/09/SQLIndexLock-679x125.png 679w" sizes="(max-width: 740px) 100vw, 740px" /></p>
<p><strong>Now stop the execution of the previous REBUILD, and execute below REBUILD WITH WAIT_AT_LOW_PRIORITY:</strong><br />
Set MAX_DURATION for one minute and ABORT_AFTER_WAIT type is SELF.<br />
<pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
   (
	WAIT_AT_LOW_PRIORITY 
	(
		MAX_DURATION = 1
		,ABORT_AFTER_WAIT = SELF
	)
   )
)
GO</pre>
<p><strong>Above REBUILD will wait for One minute and then it will throw an error message:</strong><br />
<pre class="crayon-plain-tag">Msg 1222, Level 16, State 56, Line 1
Lock request time out period exceeded.</pre>
<p><strong>Now, test with BLOCKER option:</strong><br />
It will wait for one minute, and then it will kill the open UPDATE transaction to finish the REBUILD operation.<br />
<pre class="crayon-plain-tag">ALTER INDEX pk_tbl_DumpData_ID ON tbl_DumpData REBUILD
WITH
(
   ONLINE = ON
   (
	WAIT_AT_LOW_PRIORITY 
	(
		MAX_DURATION = 1
		,ABORT_AFTER_WAIT = BLOCKERS 
	)
   )
)
GO</pre>
<p><strong>Now, go to another transaction where UPDATE transaction was there:</strong><br />
Try to execute any query, you will get below error message because this session is terminated by REBUILD + BLOCKERS.<br />
<pre class="crayon-plain-tag">SELECT *FROM tbl_DumpData</pre>
<p><strong>Error:</strong><br />
<pre class="crayon-plain-tag">Msg 0, Level 20, State 0, Line 0
The connection is broken and recovery is not possible.  The connection is marked by the server as unrecoverable.  No attempt was made to restore the connection.</pre>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
