We experienced some very long running SQL queries on MySQL 5.5 server:
DELETE FROM IndexFilePage WHERE ixIndexFile IN (SELECT ixIndexFile FROM IndexFile WHERE ixLastGeneration < xxxx OR ixLastGeneration < ixFirstGeneration);
DELETE FROM Attachment WHERE ixAttachment IN (SELECT ixAttachment FROM AttachmentReference WHERE ixBugEvent = xxxx);
Due to the use of IN MySQL does a full table scan w/o using an index so this resulted in an overall slow FogBugz system.
Our solution was to modify two procedures in Wasabi files.
CBugEvent.was procedure DeleteExistingAttachments()
cmd = GetCmd("SELECT ixAttachment FROM AttachmentReference WHERE ixBugEvent = ?", "I")
cmd.SetParam 1, ixBugEvent
Dim rs = cmd.ExecuteKeyset
Dim cmdDelete
While Not rs.EOF
' Delete the actual attachments
cmdDelete = GetCmd( "DELETE FROM Attachment WHERE ixAttachment = ?", "I" )
cmdDelete.SetParam 1, rs("ixAttachment")
cmdDelete.ExecuteNonQuery
rs.MoveNext
Wend
CloseRS rs
CIndexFile.was procedure DeleteOldIndexFiles
Dim cmd = GetCmd("SELECT ixIndexFile FROM IndexFile WHERE ixLastGeneration < ? OR ixLastGeneration < ixFirstGeneration", "I")
cmd.SetParam 1, ixOldestGenerationAllowed
Dim rs = cmd.ExecuteKeyset
Dim cmdDelete
While Not rs.EOF
' Delete the actual attachments
cmdDelete = GetCmd( "DELETE FROM IndexFilePage WHERE ixIndexFile = ?", "I" )
cmdDelete.SetParam 1, rs("ixIndexFile")
cmdDelete.ExecuteNonQuery
rs.MoveNext
Wend
CloseRS rs
This worked for us in FogBugz 8.4.87 (DB 780, Build 1).
Disclaimer: USE AT YOUR OWN RISK! Please understand that you modify the Wasabi source code of FogBugz and that nobody can be held responsible for any data loss. Please make reliable backups first! I REPEAT: USE AT YOUR OWN RISK!