我们发现以下查询大约需要一个小时才能加载1000多个记录。在表“ q”和表文件中有300万条记录,f大约有200万。关于如何加快速度的任何建议?
Select
q.Id, vStorageId,vRootId, q.vPath, p.[FileName],
p.Original, p.[User],
IsNull(p.[Size], 0) as FileSize, p.[Extension], p.Encode,
p.[IsPicture], p.IsUploaded,
(Case when p.IsDirectory=1 then GetUtcDate() else p.Time end) as [Modified],
IsNull(p.[Created], getUTCDate()) as [Created],
IsNull(p.IsDirectory,0) as IsDirectory
from
Ques q
cross apply
openJson(Request,'$.created')
WITH([Message] nvarchar(255) '$.message',
[FileName] nvarchar (1024) '$.name',
Original nvarchar (1024) '$.name',
[User] nvarchar (1024) '$.user',
[Size] bigint '$.size', [Extension] nvarchar (255) '$.ext',
Encode bit '$.encode', [IsPicture] bit '$.picture',
IsUploaded bit '$.uploaded',
[Time] DateTime2 '$.time', [Created] DateTime2 '$.created',
IsDirectory int '$.dir') p
left join
dbo.Files f on f.[vPath] = q.[vPath]
and f.[FileName] = p.[FileName]
and q.vStorageID = f.StorageID
where
topic = 'Scan'
and State = 4
and f.Id is null;