SET @DeleteBefore = '2024-10-01 00:00:00';
DELETE c1 FROM Contexts c1 JOIN (SELECT id FROM Contexts WHERE FlowContextIdContextType IS= NULL'FlowContext' AND CreateTime < @DeleteBefore) c2 ON c1.FlowContextId = c2.id;
DELETE FROM ContextIndices WHERE FlowContextId IN (SELECT id FROM Contexts WHERE FlowContextIdContextType IS= NULL'FlowContext' AND CreateTime < @DeleteBefore);
DELETE FROM ContextLogs WHERE FlowContextId IN (SELECT id FROM Contexts WHERE FlowContextIdContextType IS= NULL'FlowContext' AND CreateTime < @DeleteBefore);
DELETE FROM Contexts WHERE FlowContextIdContextType IS= NULL'FlowContext' AND CreateTime < @DeleteBefore;
DELETE FROM PerformanceRecords WHERE Time < @DeleteBefore;
OPTIMIZE TABLE Contexts;
OPTIMIZE TABLE ContextIndices;
OPTIMIZE TABLE ContextLogs;
OPTIMIZE TABLE PerformanceRecords; |