diff --git a/src/DurableTask.SqlServer/Scripts/logic.sql b/src/DurableTask.SqlServer/Scripts/logic.sql index 6fbc422..835e65d 100644 --- a/src/DurableTask.SqlServer/Scripts/logic.sql +++ b/src/DurableTask.SqlServer/Scripts/logic.sql @@ -1282,7 +1282,6 @@ BEGIN -- Table order for this sproc: NewTasks --> Payloads -- Update (lock) and return a single row. - -- The PK_NewTasks hint is specified to help ensure in-order selection. -- TODO: Filter out tasks for instances that are in a non-running state (suspended, etc.) UPDATE TOP (1) NewTasks WITH (READPAST) SET @@ -1291,7 +1290,7 @@ BEGIN [LockExpiration] = @LockExpiration, [DequeueCount] = [DequeueCount] + 1 FROM - NewTasks WITH (INDEX (PK_NewTasks)) + NewTasks WHERE [TaskHub] = @TaskHub AND ([LockExpiration] IS NULL OR [LockExpiration] < @now) AND diff --git a/src/DurableTask.SqlServer/Scripts/schema-1.7.0.sql b/src/DurableTask.SqlServer/Scripts/schema-1.7.0.sql new file mode 100644 index 0000000..09ad453 --- /dev/null +++ b/src/DurableTask.SqlServer/Scripts/schema-1.7.0.sql @@ -0,0 +1,17 @@ +-- Copyright (c) Microsoft Corporation. +-- Licensed under the MIT License. + +-- PERSISTENT SCHEMA OBJECTS (tables, indexes, types, etc.) +-- +-- The contents of this file must never be changed after +-- being published. Any schema changes must be done in +-- new schema-{major}.{minor}.{patch}.sql scripts. + +-- Add a covering index on NewTasks to improve the performance of _LockNextTask. +-- This allows SQL Server to efficiently find unlocked, visible tasks without +-- performing a full clustered-index scan, which is important under high concurrency +-- when there may be a backlog of locked or not-yet-visible tasks. +IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID('__SchemaNamePlaceholder__.NewTasks') AND name = 'IX_NewTasks_LockNext') + CREATE NONCLUSTERED INDEX IX_NewTasks_LockNext ON __SchemaNamePlaceholder__.NewTasks(TaskHub, LockExpiration, VisibleTime) + INCLUDE (SequenceNumber, LockedBy, DequeueCount) +GO diff --git a/src/common.props b/src/common.props index 7f63f5c..29f4887 100644 --- a/src/common.props +++ b/src/common.props @@ -16,7 +16,7 @@ 1 - 6 + 7 0 $(MajorVersion).$(MinorVersion).$(PatchVersion)