Skip to content

Commit

Permalink
Add ancillary indexes to improve deletion. (#4508)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
blkt authored Sep 17, 2024
1 parent ff4b6d9 commit cf38df6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions database/migrations/000106_ancillary_evaluation_indexes.down.sql
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions database/migrations/000106_ancillary_evaluation_indexes.up.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit cf38df6

Please sign in to comment.