From 997bfe51df63715beae88f9d0a22086e6735ab75 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 8 May 2026 03:54:25 +0000 Subject: [PATCH 1/2] Initial plan From 3c00675d5a539af072eab1bc35dd20c24aee873f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 8 May 2026 03:57:50 +0000 Subject: [PATCH 2/2] Remove forced PK_NewTasks index hint from _LockNextTask and add covering index Agent-Logs-Url: https://github.com/microsoft/durabletask-mssql/sessions/8ca0a940-d65f-45e4-96c8-2f6de7571ad6 Co-authored-by: berndverst <4535280+berndverst@users.noreply.github.com> --- src/DurableTask.SqlServer/Scripts/logic.sql | 3 +-- .../Scripts/schema-1.7.0.sql | 17 +++++++++++++++++ src/common.props | 2 +- 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 src/DurableTask.SqlServer/Scripts/schema-1.7.0.sql 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)