Определение моей таблицы:
Код: Выделить всё
CREATE TABLE [dbo].[testqueue] (
[id] [bigint] IDENTITY(1,1) NOT NULL,
[guid] [uniqueidentifier] NOT NULL,
[created] [datetime] NOT NULL,
[notbefore] [datetime] NOT NULL,
[status] [tinyint] NOT NULL,
[task] [nvarchar](255) NOT NULL,
[data] [nvarchar](max) NULL,
[completed] [datetime] NULL,
CONSTRAINT [PK_testqueue] PRIMARY KEY CLUSTERED ([id] ASC)
)
CREATE INDEX [ix_guid] ON [dbo].[testqueue] ([guid])
CREATE INDEX [ix_selector] ON [dbo].[testqueue] ([status],[notbefore])
< /code>
И это мой скрипт PHP: < /p>
$connection = new \PDO('sqlsrv:Server='.$server.';Database='.$db.';', $user, $pass);
$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$time = time();
$count = 0;
$query = '
WITH CTE AS (
SELECT TOP 1 *
FROM [dbo].[testqueue]
WHERE [status]=0
AND [notbefore]
Подробнее здесь: [url]https://stackoverflow.com/questions/79775969/why-does-this-query-slow-down-this-much-over-time[/url]