diff --git a/src/postgres/src/backend/commands/trigger.c b/src/postgres/src/backend/commands/trigger.c index 917de6fde23b..f0256656457b 100644 --- a/src/postgres/src/backend/commands/trigger.c +++ b/src/postgres/src/backend/commands/trigger.c @@ -1930,8 +1930,19 @@ RelationBuildTriggers(Relation relation) SysScanDesc tgscan; HeapTuple htup; MemoryContext oldContext; + MemoryContext ybSavedContext; + MemoryContext ybTriggerContext; int i; + if (IsYugaByteEnabled()) + { + ybTriggerContext = + AllocSetContextCreate(CurrentMemoryContext, + "RelationBuildTriggers context", + ALLOCSET_DEFAULT_SIZES); + ybSavedContext = MemoryContextSwitchTo(ybTriggerContext); + } + /* * Allocate a working array to hold the triggers (the array is extended if * necessary) @@ -2047,6 +2058,11 @@ RelationBuildTriggers(Relation relation) if (numtrigs == 0) { pfree(triggers); + if (IsYugaByteEnabled()) + { + MemoryContextSwitchTo(ybSavedContext); + MemoryContextDelete(ybTriggerContext); + } return; } @@ -2064,6 +2080,12 @@ RelationBuildTriggers(Relation relation) /* Release working memory */ FreeTriggerDesc(trigdesc); + + if (IsYugaByteEnabled()) + { + MemoryContextSwitchTo(ybSavedContext); + MemoryContextDelete(ybTriggerContext); + } } /*