Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds wait at low pri support to create 2022+ #108

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions SqlScriptDom/Parser/TSql/TSql120ParserBaseInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,19 @@ protected static void CheckLowPriorityLockWaitValue(IntegerLiteral maxDuration,
protected static void VerifyAllowedIndexOption120(IndexAffectingStatement statement, IndexOption option)
{
VerifyAllowedIndexOption(statement, option, SqlVersionFlags.TSql120);
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option, SqlVersionFlags.TSql120);
}

protected static void VerifyAllowedOnlineIndexOptionLowPriorityLockWait(IndexAffectingStatement statement, IndexOption option, SqlVersionFlags versionFlags)
{
// for a low priority lock wait (MLP) option, check if it is allowed for the statement.
//
if (option is OnlineIndexOption)
{
OnlineIndexOption onlineIndexOption = option as OnlineIndexOption;
if (onlineIndexOption.LowPriorityLockWaitOption != null)
{
// 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.
switch (statement)
{
case IndexAffectingStatement.AlterIndexRebuildOnePartition:
Expand All @@ -81,6 +86,19 @@ protected static void VerifyAllowedIndexOption120(IndexAffectingStatement statem
//
break;

case IndexAffectingStatement.CreateIndex:
// allowed in Sql160 and higher only
//
if (versionFlags > SqlVersionFlags.TSql150)
{
break;
}
else
{
ThrowWrongIndexOptionError(statement, onlineIndexOption.LowPriorityLockWaitOption);
break;
}

default:
// WAIT_AT_LOW_PRIORITY is not a valid index option in the statement
//
Expand Down
31 changes: 2 additions & 29 deletions SqlScriptDom/Parser/TSql/TSql150ParserBaseInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,9 @@ public TSql150ParserBaseInternal(bool initialQuotedIdentifiersOn)
protected static void VerifyAllowedIndexOption150(IndexAffectingStatement statement, IndexOption option)
{
VerifyAllowedIndexOption(statement, option, SqlVersionFlags.TSql150);
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option);
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option, SqlVersionFlags.TSql150);
}

protected static void VerifyAllowedOnlineIndexOptionLowPriorityLockWait(IndexAffectingStatement statement, IndexOption option)
{
// for a low priority lock wait (MLP) option, check if it is allowed for the statement.
//
if (option is OnlineIndexOption)
{
OnlineIndexOption onlineIndexOption = option as OnlineIndexOption;
if (onlineIndexOption.LowPriorityLockWaitOption != null)
{
switch (statement)
{
case IndexAffectingStatement.AlterIndexRebuildOnePartition:
case IndexAffectingStatement.AlterTableRebuildOnePartition:
case IndexAffectingStatement.AlterIndexRebuildAllPartitions:
case IndexAffectingStatement.AlterTableRebuildAllPartitions:
// allowed
//
break;

default:
// WAIT_AT_LOW_PRIORITY is not a valid index option in the statement
//
ThrowWrongIndexOptionError(statement, onlineIndexOption.LowPriorityLockWaitOption);
break;
}
}
}
}

}
}
2 changes: 1 addition & 1 deletion SqlScriptDom/Parser/TSql/TSql160ParserBaseInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public TSql160ParserBaseInternal(bool initialQuotedIdentifiersOn)
protected static void VerifyAllowedIndexOption160(IndexAffectingStatement statement, IndexOption option)
{
VerifyAllowedIndexOption(statement, option, SqlVersionFlags.TSql160);
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option);
VerifyAllowedOnlineIndexOptionLowPriorityLockWait(statement, option, SqlVersionFlags.TSql160);
}

protected static SqlDataTypeOption ParseDataType160(string token)
Expand Down
5 changes: 4 additions & 1 deletion Test/SqlDom/Baselines160/CreateIndexStatementTests160.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,7 @@ CREATE CLUSTERED INDEX tableWithClusteredIndex_index
ON dbo.tableWithClusteredIndex(c1) WITH (XML_COMPRESSION = ON);

CREATE UNIQUE INDEX tableWithUniqueIndex_index
ON dbo.tableWithUniqueIndex(c1) WITH (XML_COMPRESSION = ON);
ON dbo.tableWithUniqueIndex(c1) WITH (XML_COMPRESSION = ON);

CREATE CLUSTERED INDEX idx_1
ON dbo.T2(a) WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 5 MINUTES, ABORT_AFTER_WAIT = SELF)));
2 changes: 1 addition & 1 deletion Test/SqlDom/Only160SyntaxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public partial class SqlDomTests
new ParserTest160("CreateExternalDataSourceStatementTests160.sql", nErrors80: 2, nErrors90: 2, nErrors100: 2, nErrors110: 2, nErrors120: 2, nErrors130: 0, nErrors140: 0, nErrors150: 0),
new ParserTest160("CreateDatabaseTests160.sql", nErrors80: 4, nErrors90: 4, nErrors100: 4, nErrors110: 4, nErrors120: 4, nErrors130: 4, nErrors140: 4, nErrors150: 4),
new ParserTest160("CreateLedgerTableTests160.sql", nErrors80: 14, nErrors90: 14, nErrors100: 14, nErrors110: 14, nErrors120: 14, nErrors130: 14, nErrors140: 14, nErrors150: 14),
new ParserTest160("CreateIndexStatementTests160.sql", nErrors80: 12, nErrors90: 16, nErrors100: 14, nErrors110: 14, nErrors120: 14, nErrors130: 14, nErrors140: 14, nErrors150: 14),
new ParserTest160("CreateIndexStatementTests160.sql", nErrors80: 12, nErrors90: 17, nErrors100: 15, nErrors110: 15, nErrors120: 15, nErrors130: 15, nErrors140: 15, nErrors150: 15),
new ParserTest160("MergeStatementTests160.sql", nErrors80: 1, nErrors90: 5, nErrors100: 5, nErrors110: 5, nErrors120: 5, nErrors130: 5, nErrors140: 5, nErrors150: 5),
new ParserTest160("SelectStatementTests160.sql", nErrors80: 5, nErrors90: 5, nErrors100: 5, nErrors110: 5, nErrors120: 5, nErrors130: 5, nErrors140: 5, nErrors150: 5),
new ParserTest160("CreateTableTests160.sql", nErrors80: 11, nErrors90: 11, nErrors100: 11, nErrors110: 11, nErrors120: 11, nErrors130: 7, nErrors140: 7, nErrors150: 7),
Expand Down
2 changes: 2 additions & 0 deletions Test/SqlDom/TestScripts/CreateIndexStatementTests160.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ CREATE CLUSTERED INDEX tableWithClusteredIndex_index ON dbo.tableWithClusteredIn

-- Unique index
CREATE UNIQUE INDEX tableWithUniqueIndex_index ON dbo.tableWithUniqueIndex (c1) WITH (XML_COMPRESSION = ON);

CREATE CLUSTERED INDEX idx_1 ON dbo.T2 (a) WITH (ONLINE = ON (WAIT_AT_LOW_PRIORITY (MAX_DURATION = 5 MINUTES, ABORT_AFTER_WAIT = SELF)));
Loading