From 1c8d024477ec3268e7c20cbf3777174530fad1c5 Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Fri, 21 Jul 2017 17:05:28 +0300 Subject: [PATCH] Fix crashing on database-wide vacuum/analyze --- online_analyze.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/online_analyze.c b/online_analyze.c index 53ffd20..b6ccf68 100644 --- a/online_analyze.c +++ b/online_analyze.c @@ -847,13 +847,38 @@ onlineAnalyzeHookerUtility( { VacuumStmt *vac = (VacuumStmt*)parsetree; - tblnames = list_make1(vac->relation); + if (vac->relation) + tblnames = list_make1(vac->relation); if (vac->options & (VACOPT_VACUUM | VACOPT_FULL | VACOPT_FREEZE)) + { /* optionally with analyze */ op = CK_VACUUM; + + /* drop all collected stat */ + if (tblnames == NIL) + relstatsInit(); + } else if (vac->options & VACOPT_ANALYZE) + { op = CK_ANALYZE; + + /* should reset all counters */ + if (tblnames == NIL) + { + HASH_SEQ_STATUS hs; + OnlineAnalyzeTableStat *rstat; + TimestampTz now = GetCurrentTimestamp(); + + hash_seq_init(&hs, relstats); + + while((rstat = hash_seq_search(&hs)) != NULL) + { + rstat->changes_since_analyze = 0; + rstat->analyze_timestamp = now; + } + } + } else tblnames = NIL; } -- 2.46.1