-
-
Save danielrolfe/4c594513a0ce4c41af93c9980fa07faf to your computer and use it in GitHub Desktop.
declare @CleanupList table(ArchivalId uniqueidentifier) | |
declare @ArchivalId uniqueidentifier | |
insert into @CleanupList(ArchivalId) | |
select ArchivalId | |
from dbo.Archive | |
where ArchiveName = 'recyclebin' | |
while(1 = 1) | |
begin | |
set @ArchivalId = NULL | |
select top (1) @ArchivalId = ArchivalId | |
from @CleanupList | |
if @ArchivalId IS NULL | |
break | |
delete from dbo.ArchivedFields where ArchivalId = @ArchivalId | |
delete from dbo.ArchivedItems where ArchivalId = @ArchivalId | |
delete from dbo.ArchivedVersions where ArchivalId = @ArchivalId | |
delete from dbo.Archive where ArchivalId = @ArchivalId | |
delete top(1) from @CleanupList | |
end |
I have a question. What about Blobs table? Whey looking at "Query Performance Insight" I see the following queries being very heavy:
Query 1:
(@archiveName nvarchar(10))DELETE FROM [Blobs] WHERE [BlobId] IN ( SELECT [Blobs].[BlobId] FROM [ArchivedFields], [Blobs] WHERE [ArchivalId] IN (SELECT [ArchivalId] FROM [Archive] WHERE [ArchiveName] = @archiveName AND [Value] LIKE [Blobs].[BlobId]))
Query 2
(@archivalId uniqueidentifier)DELETE FROM [Blobs] WHERE CONVERT(nvarchar(36), [BlobId]) IN (SELECT [Blobs].[BlobId] FROM [ArchivedFields], [Blobs] WHERE [ArchivalId] = @archivalId AND [Value] LIKE [Blobs].[BlobId])
(In my case, empty Recycle Bin button click caused timeout, and first query is the one bein mentioned).
I am just wondering - if I delete Archival entries, would not orphaned blobs still hang around and take space (for recycled image items I presume)
@sansani4 The cleanup database option in administration tools is what removes orphaned blobs from the blob table. :)
Database and Operations --> Database Cleanup
Thank you @ezlateva