From 2a0da3dec1f999b4e2b50284acf31eb178e41f03 Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Mon, 11 Mar 2024 10:47:09 +0100 Subject: [PATCH] Add a correct composite `INDEX` for the history table --- schema/mysql/schema.sql | 2 +- schema/mysql/upgrades/1.1.2.sql | 3 +++ schema/pgsql/schema.sql | 4 ++-- schema/pgsql/upgrades/1.1.2.sql | 5 +++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index 26ae3940..2cc10cc8 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -1289,7 +1289,7 @@ CREATE TABLE history ( CONSTRAINT fk_history_notification_history FOREIGN KEY (notification_history_id) REFERENCES notification_history (id) ON DELETE CASCADE, CONSTRAINT fk_history_state_history FOREIGN KEY (state_history_id) REFERENCES state_history (id) ON DELETE CASCADE, - INDEX idx_history_event_time (event_time) COMMENT 'History filtered/ordered by event_time', + INDEX idx_history_event_time_event_type (event_time, event_type) COMMENT 'History filtered/ordered by event_time/event_type', INDEX idx_history_acknowledgement (acknowledgement_history_id), INDEX idx_history_comment (comment_history_id), INDEX idx_history_downtime (downtime_history_id), diff --git a/schema/mysql/upgrades/1.1.2.sql b/schema/mysql/upgrades/1.1.2.sql index 9f5edd5f..80f4af24 100644 --- a/schema/mysql/upgrades/1.1.2.sql +++ b/schema/mysql/upgrades/1.1.2.sql @@ -1 +1,4 @@ UPDATE icingadb_schema SET timestamp = UNIX_TIMESTAMP(timestamp / 1000) * 1000 WHERE timestamp > 20000000000000000; + +ALTER TABLE history ADD INDEX idx_history_event_time_event_type (event_time, event_type) COMMENT 'History filtered/ordered by event_time/event_type'; +ALTER TABLE history DROP INDEX idx_history_event_time; diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index 13021031..ea87325f 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -2074,7 +2074,7 @@ ALTER TABLE history ALTER COLUMN comment_history_id SET STORAGE PLAIN; ALTER TABLE history ALTER COLUMN flapping_history_id SET STORAGE PLAIN; ALTER TABLE history ALTER COLUMN acknowledgement_history_id SET STORAGE PLAIN; -CREATE INDEX idx_history_event_time ON history(event_time); +CREATE INDEX idx_history_event_time_event_type ON history(event_time, event_type); CREATE INDEX idx_history_acknowledgement ON history(acknowledgement_history_id); CREATE INDEX idx_history_comment ON history(comment_history_id); CREATE INDEX idx_history_downtime ON history(downtime_history_id); @@ -2095,7 +2095,7 @@ COMMENT ON COLUMN history.comment_history_id IS 'comment_history.comment_id'; COMMENT ON COLUMN history.flapping_history_id IS 'flapping_history.id'; COMMENT ON COLUMN history.acknowledgement_history_id IS 'acknowledgement_history.id'; -COMMENT ON INDEX idx_history_event_time IS 'History filtered/ordered by event_time'; +COMMENT ON INDEX idx_history_event_time_event_type IS 'History filtered/ordered by event_time/event_type'; COMMENT ON INDEX idx_history_host_service_id IS 'Host/service history detail filter'; CREATE TABLE sla_history_state ( diff --git a/schema/pgsql/upgrades/1.1.2.sql b/schema/pgsql/upgrades/1.1.2.sql index ea619ec4..701fea00 100644 --- a/schema/pgsql/upgrades/1.1.2.sql +++ b/schema/pgsql/upgrades/1.1.2.sql @@ -137,3 +137,8 @@ BEGIN RETURN (100 * (total_time - problem_time)::decimal / total_time)::decimal(7, 4); END; $$; + +CREATE INDEX CONCURRENTLY idx_history_event_time_event_type ON history(event_time, event_type); +COMMENT ON INDEX idx_history_event_time_event_type IS 'History filtered/ordered by event_time/event_type'; + +DROP INDEX idx_history_event_time;