From aecf95864eaf2c2d9a939bdca7336c88d05f4ac8 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Fri, 14 Oct 2022 13:26:41 +0800 Subject: [PATCH] Add index for maintenance tables --- db/patch-maintenance-table2.sql | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/db/patch-maintenance-table2.sql b/db/patch-maintenance-table2.sql index 766445969..24f6da8c3 100644 --- a/db/patch-maintenance-table2.sql +++ b/db/patch-maintenance-table2.sql @@ -24,7 +24,14 @@ CREATE TABLE [maintenance] ( [interval_day] INTEGER ); -CREATE INDEX [maintenance_user_id] ON [maintenance]([user_id]); +CREATE INDEX [manual_active] ON [maintenance] ( + [strategy], + [active] +); + +CREATE INDEX [active] ON [maintenance] ([active]); + +CREATE INDEX [maintenance_user_id] ON [maintenance] ([user_id]); -- maintenance_status_page CREATE TABLE maintenance_status_page ( @@ -35,6 +42,12 @@ CREATE TABLE maintenance_status_page ( CONSTRAINT FK_status_page FOREIGN KEY (status_page_id) REFERENCES status_page (id) ON DELETE CASCADE ON UPDATE CASCADE ); +CREATE INDEX [status_page_id_index] + ON [maintenance_status_page]([status_page_id]); + +CREATE INDEX [maintenance_id_index] + ON [maintenance_status_page]([maintenance_id]); + -- maintenance_timeslot CREATE TABLE [maintenance_timeslot] ( [id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, @@ -44,6 +57,14 @@ CREATE TABLE [maintenance_timeslot] ( [generated_next] BOOLEAN DEFAULT 0 ); +CREATE INDEX [maintenance_id] ON [maintenance_timeslot] ([maintenance_id] DESC); + +CREATE INDEX [active_timeslot_index] ON [maintenance_timeslot] ( + [maintenance_id] DESC, + [start_date] DESC, + [end_date] DESC +); + -- monitor_maintenance CREATE TABLE monitor_maintenance ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, @@ -53,4 +74,8 @@ CREATE TABLE monitor_maintenance ( CONSTRAINT FK_monitor FOREIGN KEY (monitor_id) REFERENCES monitor (id) ON DELETE CASCADE ON UPDATE CASCADE ); +CREATE INDEX [maintenance_id_index2] ON [monitor_maintenance]([maintenance_id]); + +CREATE INDEX [monitor_id_index] ON [monitor_maintenance]([monitor_id]); + COMMIT;