Skip to content

Commit d44ca9b

Browse files
authored
adds wait at low pri support to create 2022+ (#108)
1 parent 3aec78d commit d44ca9b

File tree

6 files changed

+28
-32
lines changed

6 files changed

+28
-32
lines changed

SqlScriptDom/Parser/TSql/TSql120ParserBaseInternal.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,19 @@ protected static void CheckLowPriorityLockWaitValue(IntegerLiteral maxDuration,
6363
protected static void VerifyAllowedIndexOption120(IndexAffectingStatement statement, IndexOption option)
6464
{
6565
VerifyAllowedIndexOption(statement, option, SqlVersionFlags.TSql120);
66+
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option, SqlVersionFlags.TSql120);
67+
}
6668

69+
protected static void VerifyAllowedOnlineIndexOptionLowPriorityLockWait(IndexAffectingStatement statement, IndexOption option, SqlVersionFlags versionFlags)
70+
{
6771
// for a low priority lock wait (MLP) option, check if it is allowed for the statement.
6872
//
6973
if (option is OnlineIndexOption)
7074
{
7175
OnlineIndexOption onlineIndexOption = option as OnlineIndexOption;
7276
if (onlineIndexOption.LowPriorityLockWaitOption != null)
7377
{
78+
// This syntax for CREATE INDEX currently applies to SQL Server 2022 (16.x), Azure SQL Database, and Azure SQL Managed Instance only. For ALTER INDEX, this syntax applies to SQL Server (Starting with SQL Server 2014 (12.x)) and Azure SQL Database.
7479
switch (statement)
7580
{
7681
case IndexAffectingStatement.AlterIndexRebuildOnePartition:
@@ -81,6 +86,19 @@ protected static void VerifyAllowedIndexOption120(IndexAffectingStatement statem
8186
//
8287
break;
8388

89+
case IndexAffectingStatement.CreateIndex:
90+
// allowed in Sql160 and higher only
91+
//
92+
if (versionFlags > SqlVersionFlags.TSql150)
93+
{
94+
break;
95+
}
96+
else
97+
{
98+
ThrowWrongIndexOptionError(statement, onlineIndexOption.LowPriorityLockWaitOption);
99+
break;
100+
}
101+
84102
default:
85103
// WAIT_AT_LOW_PRIORITY is not a valid index option in the statement
86104
//

SqlScriptDom/Parser/TSql/TSql150ParserBaseInternal.cs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,36 +49,9 @@ public TSql150ParserBaseInternal(bool initialQuotedIdentifiersOn)
4949
protected static void VerifyAllowedIndexOption150(IndexAffectingStatement statement, IndexOption option)
5050
{
5151
VerifyAllowedIndexOption(statement, option, SqlVersionFlags.TSql150);
52-
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option);
52+
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option, SqlVersionFlags.TSql150);
5353
}
5454

55-
protected static void VerifyAllowedOnlineIndexOptionLowPriorityLockWait(IndexAffectingStatement statement, IndexOption option)
56-
{
57-
// for a low priority lock wait (MLP) option, check if it is allowed for the statement.
58-
//
59-
if (option is OnlineIndexOption)
60-
{
61-
OnlineIndexOption onlineIndexOption = option as OnlineIndexOption;
62-
if (onlineIndexOption.LowPriorityLockWaitOption != null)
63-
{
64-
switch (statement)
65-
{
66-
case IndexAffectingStatement.AlterIndexRebuildOnePartition:
67-
case IndexAffectingStatement.AlterTableRebuildOnePartition:
68-
case IndexAffectingStatement.AlterIndexRebuildAllPartitions:
69-
case IndexAffectingStatement.AlterTableRebuildAllPartitions:
70-
// allowed
71-
//
72-
break;
73-
74-
default:
75-
// WAIT_AT_LOW_PRIORITY is not a valid index option in the statement
76-
//
77-
ThrowWrongIndexOptionError(statement, onlineIndexOption.LowPriorityLockWaitOption);
78-
break;
79-
}
80-
}
81-
}
82-
}
55+
8356
}
8457
}

SqlScriptDom/Parser/TSql/TSql160ParserBaseInternal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public TSql160ParserBaseInternal(bool initialQuotedIdentifiersOn)
5353
protected static void VerifyAllowedIndexOption160(IndexAffectingStatement statement, IndexOption option)
5454
{
5555
VerifyAllowedIndexOption(statement, option, SqlVersionFlags.TSql160);
56-
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option);
56+
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option, SqlVersionFlags.TSql160);
5757
}
5858

5959
protected static SqlDataTypeOption ParseDataType160(string token)

Test/SqlDom/Baselines160/CreateIndexStatementTests160.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ CREATE CLUSTERED INDEX tableWithClusteredIndex_index
4747
ON dbo.tableWithClusteredIndex(c1) WITH (XML_COMPRESSION = ON);
4848

4949
CREATE UNIQUE INDEX tableWithUniqueIndex_index
50-
ON dbo.tableWithUniqueIndex(c1) WITH (XML_COMPRESSION = ON);
50+
ON dbo.tableWithUniqueIndex(c1) WITH (XML_COMPRESSION = ON);
51+
52+
CREATE CLUSTERED INDEX idx_1
53+
ON dbo.T2(a) WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 5 MINUTES, ABORT_AFTER_WAIT = SELF)));

Test/SqlDom/Only160SyntaxTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public partial class SqlDomTests
2323
new ParserTest160("CreateExternalDataSourceStatementTests160.sql", nErrors80: 2, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 0, nErrors140: 0, nErrors150: 0),
2424
new ParserTest160("CreateDatabaseTests160.sql", nErrors80: 4, nErrors90: 4, nErrors100: 4, nErrors110: 4, nErrors120: 4, nErrors130: 4, nErrors140: 4, nErrors150: 4),
2525
new ParserTest160("CreateLedgerTableTests160.sql", nErrors80: 14, nErrors90: 14, nErrors100: 14, nErrors110: 14, nErrors120: 14, nErrors130: 14, nErrors140: 14, nErrors150: 14),
26-
new ParserTest160("CreateIndexStatementTests160.sql", nErrors80: 12, nErrors90: 16, nErrors100: 14, nErrors110: 14, nErrors120: 14, nErrors130: 14, nErrors140: 14, nErrors150: 14),
26+
new ParserTest160("CreateIndexStatementTests160.sql", nErrors80: 12, nErrors90: 17, nErrors100: 15, nErrors110: 15, nErrors120: 15, nErrors130: 15, nErrors140: 15, nErrors150: 15),
2727
new ParserTest160("MergeStatementTests160.sql", nErrors80: 1, nErrors90: 5, nErrors100: 5, nErrors110: 5, nErrors120: 5, nErrors130: 5, nErrors140: 5, nErrors150: 5),
2828
new ParserTest160("SelectStatementTests160.sql", nErrors80: 5, nErrors90: 5, nErrors100: 5, nErrors110: 5, nErrors120: 5, nErrors130: 5, nErrors140: 5, nErrors150: 5),
2929
new ParserTest160("CreateTableTests160.sql", nErrors80: 11, nErrors90: 11, nErrors100: 11, nErrors110: 11, nErrors120: 11, nErrors130: 7, nErrors140: 7, nErrors150: 7),

Test/SqlDom/TestScripts/CreateIndexStatementTests160.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ CREATE CLUSTERED INDEX tableWithClusteredIndex_index ON dbo.tableWithClusteredIn
4343

4444
-- Unique index
4545
CREATE UNIQUE INDEX tableWithUniqueIndex_index ON dbo.tableWithUniqueIndex (c1) WITH (XML_COMPRESSION = ON);
46+
47+
CREATE CLUSTERED INDEX idx_1 ON dbo.T2 (a) WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 5 MINUTES, ABORT_AFTER_WAIT = SELF)));

0 commit comments

Comments
 (0)