cleanup local hash on drop table command n_tuples_limit
authorTeodor Sigaev <teodor@sigaev.ru>
Wed, 10 May 2017 16:09:55 +0000 (19:09 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Wed, 10 May 2017 16:09:55 +0000 (19:09 +0300)
online_analyze.c

index 90755e2..9c7fe20 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "pgstat.h"
 #include "access/transam.h"
+#include "access/xact.h"
 #include "catalog/namespace.h"
 #include "commands/vacuum.h"
 #include "executor/executor.h"
@@ -752,6 +753,24 @@ onlineAnalyzeHooker(QueryDesc *queryDesc)
                standard_ExecutorEnd(queryDesc);
 }
 
+static void
+removeTable(XactEvent event, void *arg)
+{
+       List            *toremove = arg;
+       ListCell        *cell;
+
+       if (event != XACT_EVENT_COMMIT)
+               return;
+
+       foreach(cell, toremove)
+       {
+               Oid     relOid = lfirst_oid(cell);
+
+               hash_search(relstats, &relOid, HASH_REMOVE, NULL);
+       }
+}
+
+
 #if PG_VERSION_NUM >= 90200
 static void
 onlineAnalyzeHookerUtility(
@@ -793,6 +812,31 @@ onlineAnalyzeHookerUtility(
                        tblnames = list_copy(((TruncateStmt*)parsetree)->relations);
                        op = CK_TRUNCATE;
                }
+               else if (IsA(parsetree, DropStmt) &&
+                                ((DropStmt*)parsetree)->removeType == OBJECT_TABLE)
+               {
+                       ListCell        *cell;
+                       List            *toremove = NIL;
+
+                       foreach(cell, ((DropStmt*)parsetree)->objects)
+                       {
+                               List            *relname = (List *) lfirst(cell);
+                               RangeVar        *rel = makeRangeVarFromNameList(relname);
+                               Oid                     relOid = RangeVarGetRelid(rel, NoLock, true);
+
+                               if (OidIsValid(relOid))
+                               {
+                                       MemoryContext   ctx;
+
+                                       ctx = MemoryContextSwitchTo(TopTransactionContext);
+                                       toremove = lappend_oid(toremove, relOid);
+                                       MemoryContextSwitchTo(ctx);
+                               }
+                       }
+
+                       if (list_length(toremove) > 0)
+                               RegisterXactCallback(removeTable, toremove);
+               }
                else if (IsA(parsetree, VacuumStmt))
                {
                        VacuumStmt      *vac = (VacuumStmt*)parsetree;