From a168a7f84b2292cbe3cdd4f751d98196e46bfffc Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 25 Jul 2023 10:41:58 -0400 Subject: [PATCH] xunit delete: Testcase message performance improvements I found that deleting an xunit from the database was very, very slow. This patch addresses the issue by adding additional indexes on the testcases table to make it easier to find messages that are still in use. I also rework the `cleanup_testcase_messages` trigger to only check messageids that were used by the deleted testcase. Signed-off-by: Anna Schumaker --- xfstestsdb/scripts/upgrade-v2.sql | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/xfstestsdb/scripts/upgrade-v2.sql b/xfstestsdb/scripts/upgrade-v2.sql index c45856c..14a5f65 100644 --- a/xfstestsdb/scripts/upgrade-v2.sql +++ b/xfstestsdb/scripts/upgrade-v2.sql @@ -1,3 +1,30 @@ /* Copyright 2023 (c) Anna Schumaker */ PRAGMA user_version = 2; + +/* + * The original `cleanup_testcase_messages` trigger was very slow. We can + * do a few things to improve upon it: + * 1. Add indexes on the testcases table to make it easier to check + * if specific messageids are still in use. + * 2. Rewrite the `cleanup_testcase_messages` trigger to only operate + * on the messageids associated with the deleted testcase. + */ +CREATE INDEX testcases_messageid_index ON testcases (messageid); +CREATE INDEX testcases_stdoutid_index ON testcases (stdoutid); +CREATE INDEX testcases_stderrid_index ON testcases (stderrid); + +DROP TRIGGER cleanup_testcase_messages; +CREATE TRIGGER cleanup_testcase_messages + AFTER DELETE ON testcases + BEGIN + DELETE FROM messages + WHERE (messageid = OLD.messageid + OR messageid = OLD.stdoutid + OR messageid = OLD.stderrid) + AND NOT EXISTS + (SELECT 1 FROM testcases WHERE + messageid = messages.messageid + OR stdoutid = messages.messageid + OR stderrid = messages.messageid); + END;