From c411b001ebd161cce4aa922415744a7c1046d5dc Mon Sep 17 00:00:00 2001 From: g-hodgson-tup Date: Thu, 15 May 2025 20:44:54 +0200 Subject: [PATCH] perf(sqlite): Create indices to fix performance issue (#1106) * introduce sqlite indices to fix performance issue * Update storage/store/sql/specific_sqlite.go --------- Co-authored-by: Gary Hodgson Co-authored-by: TwiN --- storage/store/sql/specific_sqlite.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/storage/store/sql/specific_sqlite.go b/storage/store/sql/specific_sqlite.go index 0fe7fa54..4dae436b 100644 --- a/storage/store/sql/specific_sqlite.go +++ b/storage/store/sql/specific_sqlite.go @@ -79,6 +79,25 @@ func (s *Store) createSQLiteSchema() error { UNIQUE(endpoint_id, configuration_checksum) ) `) + if err != nil { + return err + } + // Create indices for performance reasons + _, err = s.db.Exec(` + CREATE INDEX IF NOT EXISTS endpoint_results_endpoint_id_idx ON endpoint_results (endpoint_id); + `) + if err != nil { + return err + } + _, err = s.db.Exec(` + CREATE INDEX IF NOT EXISTS endpoint_uptimes_endpoint_id_idx ON endpoint_uptimes (endpoint_id); + `) + if err != nil { + return err + } + _, err = s.db.Exec(` + CREATE INDEX IF NOT EXISTS endpoint_result_conditions_endpoint_result_id_idx ON endpoint_result_conditions (endpoint_result_id); + `) // Silent table modifications TODO: Remove this in v6.0.0 _, _ = s.db.Exec(`ALTER TABLE endpoint_results ADD domain_expiration INTEGER NOT NULL DEFAULT 0`) return err