From d315c79aa0035f270b0e995c9d5096e2693cf8d9 Mon Sep 17 00:00:00 2001 From: Michelangelo Mori Date: Tue, 17 Sep 2024 14:07:09 +0200 Subject: [PATCH] Add ancillary indexes to improve deletion. Provider deletion, or entity deletion in general, runs into performance problems without this indexes as two triggers for constraint were executing full table scans on pretty crowded tables. These two indexes solve that problem. --- ...0106_ancillary_evaluation_indexes.down.sql | 22 +++++++++++++++++++ ...000106_ancillary_evaluation_indexes.up.sql | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 database/migrations/000106_ancillary_evaluation_indexes.down.sql create mode 100644 database/migrations/000106_ancillary_evaluation_indexes.up.sql diff --git a/database/migrations/000106_ancillary_evaluation_indexes.down.sql b/database/migrations/000106_ancillary_evaluation_indexes.down.sql new file mode 100644 index 0000000000..bf5136dd01 --- /dev/null +++ b/database/migrations/000106_ancillary_evaluation_indexes.down.sql @@ -0,0 +1,22 @@ +-- Copyright 2024 Stacklok, Inc +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +BEGIN; + +-- The following two indexes on alert_events and remediation_events +-- are necessary to optimize deletions. +DROP INDEX alert_events_evaluation_id_fk_idx; +DROP INDEX remediation_events_evaluation_id_fk_idx; + +COMMIT; diff --git a/database/migrations/000106_ancillary_evaluation_indexes.up.sql b/database/migrations/000106_ancillary_evaluation_indexes.up.sql new file mode 100644 index 0000000000..7fa9c6f153 --- /dev/null +++ b/database/migrations/000106_ancillary_evaluation_indexes.up.sql @@ -0,0 +1,22 @@ +-- Copyright 2024 Stacklok, Inc +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. + +BEGIN; + +-- The following two indexes on alert_events and remediation_events +-- are necessary to optimize deletions. +CREATE INDEX alert_events_evaluation_id_fk_idx ON alert_events (evaluation_id); +CREATE INDEX remediation_events_evaluation_id_fk_idx ON remediation_events (evaluation_id); + +COMMIT;