From 20bdce68a3a62807ab91f1370649861c479a9dbe Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Sun, 20 Dec 2020 01:36:17 +0100 Subject: [PATCH] Add two new indexes to DB for faster querying --- projects/project-3/backend/db_init.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/projects/project-3/backend/db_init.py b/projects/project-3/backend/db_init.py index 9ad85d0..14d44bc 100644 --- a/projects/project-3/backend/db_init.py +++ b/projects/project-3/backend/db_init.py @@ -95,9 +95,21 @@ def init_database(): def create_indexes(): LOG.info("Try to create indexes") conn = sqlite3.connect(DB_NAME, timeout=300) + LOG.info("Starting to build index: idx_date_of_start_date") conn.execute("""CREATE INDEX IF NOT EXISTS idx_date_of_start_date ON usage_stats (date(start_date, "unixepoch"))""") conn.commit() + LOG.info("Created index: idx_date_of_start_date") + LOG.info("Starting to build index: idx_end_station_id_date_of_start_date") + conn.execute("""CREATE INDEX IF NOT EXISTS "idx_end_station_id_date_of_start_date" + ON "usage_stats" ("end_station_id" ASC, date(start_date, "unixepoch"))""") + conn.commit() + LOG.info("Created index: idx_end_station_id_date_of_start_date") + LOG.info("Starting to build index: idx_start_station_id_date_of_start_date") + conn.execute("""CREATE INDEX IF NOT EXISTS "idx_start_station_id_date_of_start_date" + ON "usage_stats" ("start_station_id" ASC, date("start_date", "unixepoch"))""") + conn.commit() + LOG.info("Created index: idx_start_station_id_date_of_start_date") conn.close() LOG.info("Indexes created")