From 9d95466e09f4ed842ddf45d0377d6eda290a8d25 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sat, 16 Jun 2018 21:43:58 +0200 Subject: [PATCH] [db] Use ANALYZE instead of PRAGMA optimize (reverts commit cd96ec5) Turns out PRAGMA optimize does not analyze tables on a fresh install, which means that sqlite_stat1 is not available for the query planner, which means that wrong indexes are used. See https://www.raspberrypi.org/forums/viewtopic.php?f=66&t=49928&sid=1e5d1d418315d7565ae027d751dd94a0&start=1350#p1328964 --- src/db.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/db.c b/src/db.c index 327a100b..cdc2e2dc 100644 --- a/src/db.c +++ b/src/db.c @@ -1102,7 +1102,7 @@ db_exec(const char *query, char **errmsg) static void db_pragma_optimize(void) { - const char *query = "PRAGMA optimize;"; + const char *query = "ANALYZE;"; char *errmsg; int ret; @@ -1111,7 +1111,7 @@ db_pragma_optimize(void) ret = db_exec(query, &errmsg); if (ret != SQLITE_OK) { - DPRINTF(E_LOG, L_DB, "PRAGMA optimize failed: %s\n", errmsg); + DPRINTF(E_LOG, L_DB, "ANALYZE failed: %s\n", errmsg); sqlite3_free(errmsg); }