对于大型数据集,在SQL Server中进行连接和处理太慢

时间:2018-09-08 14:38:14

标签: json sql-server join large-data

我们发现以下查询大约需要一个小时才能加载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;

0 个答案:

没有答案