From 3ce4df22c2dfd8baa8bf0ef186af072364524a9c Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Wed, 10 May 2017 19:09:55 +0300 Subject: [PATCH] cleanup local hash on drop table command --- online_analyze.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/online_analyze.c b/online_analyze.c index 90755e2..9c7fe20 100644 --- a/online_analyze.c +++ b/online_analyze.c @@ -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; -- 2.46.1