From 438dde9c48a4f7372a765cc7ec69eb5bdd9a9edc Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Thu, 20 Apr 2017 17:05:04 +0300 Subject: [PATCH] add support for vacuum/analyze --- online_analyze.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/online_analyze.c b/online_analyze.c index b710d47..c70b1bb 100644 --- a/online_analyze.c +++ b/online_analyze.c @@ -83,7 +83,9 @@ typedef enum CmdKind CK_DELETE = CMD_DELETE, CK_TRUNCATE, CK_FASTTRUNCATE, - CK_CREATE + CK_CREATE, + CK_ANALYZE, + CK_VACUUM } CmdKind; @@ -442,6 +444,18 @@ makeAnalyze(Oid relOid, CmdKind operation, int64 naffected) rstat->tableid = relOid; newTable = true; } + else if (operation == CK_VACUUM) + { + /* force reread becouse vacuum could change n_tuples */ + rstat->rereadStat = true; + return; + } + else if (operation == CK_ANALYZE) + { + /* only analyze */ + rstat->changes_since_analyze = 0; + return; + } Assert(rstat->tableid == relOid); @@ -772,6 +786,20 @@ onlineAnalyzeHookerUtility( tblnames = list_copy(((TruncateStmt*)parsetree)->relations); op = CK_TRUNCATE; } + else if (IsA(parsetree, VacuumStmt)) + { + VacuumStmt *vac = (VacuumStmt*)parsetree; + + tblnames = list_make1(vac->relation); + + if (vac->options & (VACOPT_VACUUM | VACOPT_FULL | VACOPT_FREEZE)) + /* optionally with analyze */ + op = CK_VACUUM; + else if (vac->options & VACOPT_ANALYZE) + op = CK_ANALYZE; + else + tblnames = NIL; + } } #if PG_VERSION_NUM >= 100000 -- 2.46.1