Fix wrong usage of RegisterXactCallback()
authorTeodor Sigaev <teodor@sigaev.ru>
Wed, 14 Jun 2017 12:22:11 +0000 (15:22 +0300)
committerTeodor Sigaev <teodor@sigaev.ru>
Wed, 14 Jun 2017 12:22:11 +0000 (15:22 +0300)
online_analyze.c

index 9c7fe20..53ffd20 100644 (file)
@@ -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);