Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 31e2328

Browse files
committed
Fix wrong usage of RegisterXactCallback()
1 parent 3ce4df2 commit 31e2328

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

online_analyze.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -649,8 +649,7 @@ isFastTruncateCall(QueryDesc *queryDesc)
649649
queryDesc->operation == CMD_SELECT &&
650650
queryDesc->plannedstmt->planTree &&
651651
queryDesc->plannedstmt->planTree->targetlist &&
652-
list_length(queryDesc->plannedstmt->planTree->targetlist) == 1 &&
653-
IsA(linitial(queryDesc->plannedstmt->planTree->targetlist), TargetEntry)
652+
list_length(queryDesc->plannedstmt->planTree->targetlist) == 1
654653
))
655654
return NULL;
656655

@@ -667,8 +666,7 @@ isFastTruncateCall(QueryDesc *queryDesc)
667666
fe->funcretset == false &&
668667
fe->funcresulttype == VOIDOID &&
669668
fe->funcvariadic == false &&
670-
list_length(fe->args) == 1 &&
671-
IsA(linitial(fe->args), Const)
669+
list_length(fe->args) == 1
672670
))
673671
return NULL;
674672

@@ -685,7 +683,6 @@ isFastTruncateCall(QueryDesc *queryDesc)
685683
}
686684

687685

688-
689686
extern PGDLLIMPORT void onlineAnalyzeHooker(QueryDesc *queryDesc);
690687
void
691688
onlineAnalyzeHooker(QueryDesc *queryDesc)
@@ -753,21 +750,34 @@ onlineAnalyzeHooker(QueryDesc *queryDesc)
753750
standard_ExecutorEnd(queryDesc);
754751
}
755752

753+
static List *toremove = NIL;
754+
755+
/*
756+
* removeTable called on transaction end, see call RegisterXactCallback() below
757+
*/
756758
static void
757759
removeTable(XactEvent event, void *arg)
758760
{
759-
List *toremove = arg;
760761
ListCell *cell;
761762

762-
if (event != XACT_EVENT_COMMIT)
763-
return;
763+
switch(event)
764+
{
765+
case XACT_EVENT_COMMIT:
766+
break;
767+
case XACT_EVENT_ABORT:
768+
toremove = NIL;
769+
default:
770+
return;
771+
}
764772

765773
foreach(cell, toremove)
766774
{
767775
Oid relOid = lfirst_oid(cell);
768776

769777
hash_search(relstats, &relOid, HASH_REMOVE, NULL);
770778
}
779+
780+
toremove = NIL;
771781
}
772782

773783

@@ -816,7 +826,6 @@ onlineAnalyzeHookerUtility(
816826
((DropStmt*)parsetree)->removeType == OBJECT_TABLE)
817827
{
818828
ListCell *cell;
819-
List *toremove = NIL;
820829

821830
foreach(cell, ((DropStmt*)parsetree)->objects)
822831
{
@@ -833,9 +842,6 @@ onlineAnalyzeHookerUtility(
833842
MemoryContextSwitchTo(ctx);
834843
}
835844
}
836-
837-
if (list_length(toremove) > 0)
838-
RegisterXactCallback(removeTable, toremove);
839845
}
840846
else if (IsA(parsetree, VacuumStmt))
841847
{
@@ -1178,6 +1184,7 @@ _PG_init(void)
11781184
NULL
11791185
);
11801186

1187+
RegisterXactCallback(removeTable, NULL);
11811188
}
11821189

11831190
void _PG_fini(void);

0 commit comments

Comments
 (0)