[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
This commit is contained in:
ejurgensen 2018-06-16 21:43:58 +02:00
parent cf6813f2e4
commit 9d95466e09

View File

@ -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);
}