Introduction:
Creating and Altering indexes for large tables can be a time-consuming process and may block other processes as well. However, with the introduction of the “Wait at Low Priority” that allows index creation to wait for resources to become available before executing. This feature reduces the impact on long-running queries that have a higher execution priority. In this blog post, we will explore the syntax and usage of this option, along with its limitations and potential benefits.
Understanding the Syntax:
To use the “Wait at Low Priority” option during index creation, the following syntax can be used:
CREATE CLUSTERED INDEX INDEX_NAME ON TABLENAME (COLUMNNAME) WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = X MINUTES, ABORT_AFTER_WAIT = NONE/SELF/BLOCKERS) ) );
Here’s a breakdown of the different components:
NONE: Waits for the lock with regular priority. SELF: Exits the online index operation. BLOCKERS: Kills transactions that are blocking the index rebuild.Example:
To demonstrate how the “Wait at Low Priority” option can be used during index creation, consider the following example:
CREATE NONCLUSTERED INDEX [test_idx] ON [dbo].[tblAuthors]( [Id], [Author_name] )WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 1 MINUTES, ABORT_AFTER_WAIT = SELF) ) );GOIn this scenario, we are creating a non-clustered index named “test_idx” on the “tblAuthors” table, specifically on the “Id” and “Author_name” columns. The index creation will wait for a maximum duration of 1 minute, and if it exceeds this time, the operation will be aborted or the index will be created if the resource is available.
Maintenance with ALTER INDEX:
The “Wait at Low Priority” option can also be utilized during index maintenance tasks like rebuilding or reorganizing. The below syntax can be used for index REBUILD & REORGANIZE:
ALTER INDEX index_name ON table_name REBUILD WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = X MINUTES, ABORT_AFTER_WAIT = NONE/SELF/BLOCKERS) ) );
The components of this syntax are similar to the index creation syntax described earlier.
Limitations:
While the “Wait at Low Priority” option is a valuable feature, it does come with certain limitations.
The key points to consider are:
Conclusion:
The “Wait at Low Priority” option provides developers with a useful tool for managing index creation and maintenance operations. By leveraging this option, it becomes possible to prioritize these operations and make them more efficient.
Miru IT Park, Vallankumaranvillai,
Nagercoil, Tamilnadu - 629 002.
Unit 303, Vanguard Rise,
5th Main, Konena Agrahara,
Old Airport Road, Bangalore - 560 017.
Call: +91 6383016411
Email: sales@mafiree.com