From: Teodor Sigaev Date: Wed, 14 Jun 2017 12:22:11 +0000 (+0300) Subject: Fix wrong usage of RegisterXactCallback() X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=31e2328fdeefe0e5710680e704a3c78a9cadffa4;p=online_analyze.git Fix wrong usage of RegisterXactCallback() --- diff --git a/online_analyze.c b/online_analyze.c index 9c7fe20..53ffd20 100644 --- a/online_analyze.c +++ b/online_analyze.c @@ -649,8 +649,7 @@ isFastTruncateCall(QueryDesc *queryDesc) queryDesc->operation == CMD_SELECT && queryDesc->plannedstmt->planTree && queryDesc->plannedstmt->planTree->targetlist && - list_length(queryDesc->plannedstmt->planTree->targetlist) == 1 && - IsA(linitial(queryDesc->plannedstmt->planTree->targetlist), TargetEntry) + list_length(queryDesc->plannedstmt->planTree->targetlist) == 1 )) return NULL; @@ -667,8 +666,7 @@ isFastTruncateCall(QueryDesc *queryDesc) fe->funcretset == false && fe->funcresulttype == VOIDOID && fe->funcvariadic == false && - list_length(fe->args) == 1 && - IsA(linitial(fe->args), Const) + list_length(fe->args) == 1 )) return NULL; @@ -685,7 +683,6 @@ isFastTruncateCall(QueryDesc *queryDesc) } - extern PGDLLIMPORT void onlineAnalyzeHooker(QueryDesc *queryDesc); void onlineAnalyzeHooker(QueryDesc *queryDesc) @@ -753,14 +750,25 @@ onlineAnalyzeHooker(QueryDesc *queryDesc) standard_ExecutorEnd(queryDesc); } +static List *toremove = NIL; + +/* + * removeTable called on transaction end, see call RegisterXactCallback() below + */ static void removeTable(XactEvent event, void *arg) { - List *toremove = arg; ListCell *cell; - if (event != XACT_EVENT_COMMIT) - return; + switch(event) + { + case XACT_EVENT_COMMIT: + break; + case XACT_EVENT_ABORT: + toremove = NIL; + default: + return; + } foreach(cell, toremove) { @@ -768,6 +776,8 @@ removeTable(XactEvent event, void *arg) hash_search(relstats, &relOid, HASH_REMOVE, NULL); } + + toremove = NIL; } @@ -816,7 +826,6 @@ onlineAnalyzeHookerUtility( ((DropStmt*)parsetree)->removeType == OBJECT_TABLE) { ListCell *cell; - List *toremove = NIL; foreach(cell, ((DropStmt*)parsetree)->objects) { @@ -833,9 +842,6 @@ onlineAnalyzeHookerUtility( MemoryContextSwitchTo(ctx); } } - - if (list_length(toremove) > 0) - RegisterXactCallback(removeTable, toremove); } else if (IsA(parsetree, VacuumStmt)) { @@ -1178,6 +1184,7 @@ _PG_init(void) NULL ); + RegisterXactCallback(removeTable, NULL); } void _PG_fini(void);