add support for vacuum/analyze
authorTeodor Sigaev <teodor@sigaev.ru>
Thu, 20 Apr 2017 14:05:04 +0000 (17:05 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Thu, 20 Apr 2017 14:05:04 +0000 (17:05 +0300)
online_analyze.c

index b710d47..c70b1bb 100644 (file)
@@ -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