diff --git a/SqlScriptDom/Parser/TSql/TSql120ParserBaseInternal.cs b/SqlScriptDom/Parser/TSql/TSql120ParserBaseInternal.cs index 6016f7d..ac8c7d2 100644 --- a/SqlScriptDom/Parser/TSql/TSql120ParserBaseInternal.cs +++ b/SqlScriptDom/Parser/TSql/TSql120ParserBaseInternal.cs @@ -63,7 +63,11 @@ 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) @@ -71,6 +75,7 @@ protected static void VerifyAllowedIndexOption120(IndexAffectingStatement statem 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: @@ -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 // diff --git a/SqlScriptDom/Parser/TSql/TSql150ParserBaseInternal.cs b/SqlScriptDom/Parser/TSql/TSql150ParserBaseInternal.cs index 9c6b48c..66cd1a0 100644 --- a/SqlScriptDom/Parser/TSql/TSql150ParserBaseInternal.cs +++ b/SqlScriptDom/Parser/TSql/TSql150ParserBaseInternal.cs @@ -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; - } - } - } - } + } } diff --git a/SqlScriptDom/Parser/TSql/TSql160ParserBaseInternal.cs b/SqlScriptDom/Parser/TSql/TSql160ParserBaseInternal.cs index 4dd2554..8d49eb1 100644 --- a/SqlScriptDom/Parser/TSql/TSql160ParserBaseInternal.cs +++ b/SqlScriptDom/Parser/TSql/TSql160ParserBaseInternal.cs @@ -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) diff --git a/Test/SqlDom/Baselines160/CreateIndexStatementTests160.sql b/Test/SqlDom/Baselines160/CreateIndexStatementTests160.sql index 83f9b7c..8827534 100644 --- a/Test/SqlDom/Baselines160/CreateIndexStatementTests160.sql +++ b/Test/SqlDom/Baselines160/CreateIndexStatementTests160.sql @@ -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); \ No newline at end of file + 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))); \ No newline at end of file diff --git a/Test/SqlDom/Only160SyntaxTests.cs b/Test/SqlDom/Only160SyntaxTests.cs index e0545b3..045425f 100644 --- a/Test/SqlDom/Only160SyntaxTests.cs +++ b/Test/SqlDom/Only160SyntaxTests.cs @@ -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), diff --git a/Test/SqlDom/TestScripts/CreateIndexStatementTests160.sql b/Test/SqlDom/TestScripts/CreateIndexStatementTests160.sql index be1fd57..41519a1 100644 --- a/Test/SqlDom/TestScripts/CreateIndexStatementTests160.sql +++ b/Test/SqlDom/TestScripts/CreateIndexStatementTests160.sql @@ -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)));