Retire MemoryContextResetAndDeleteChildren() macro.
authorNathan Bossart <[email protected]>
Wed, 15 Nov 2023 19:42:30 +0000 (13:42 -0600)
committerNathan Bossart <[email protected]>
Wed, 15 Nov 2023 19:42:30 +0000 (13:42 -0600)
As of commit eaa5808e8e, MemoryContextResetAndDeleteChildren() is
just a backwards compatibility macro for MemoryContextReset().  Now
that some time has passed, this macro seems more likely to create
confusion.

This commit removes the macro and replaces all remaining uses with
calls to MemoryContextReset().  Any third-party code that use this
macro will need to be adjusted to call MemoryContextReset()
instead.  Since the two have behaved the same way since v9.5, such
adjustments won't produce any behavior changes for all
currently-supported versions of PostgreSQL.

Reviewed-by: Amul Sul, Tom Lane, Alvaro Herrera, Dagfinn Ilmari Mannsåker
Discussion: https://postgr.es/m/20231113185950.GA1668018%40nathanxps13

18 files changed:
src/backend/access/brin/brin.c
src/backend/access/gin/ginscan.c
src/backend/access/transam/xact.c
src/backend/commands/analyze.c
src/backend/executor/nodeRecursiveunion.c
src/backend/executor/nodeSetOp.c
src/backend/executor/nodeWindowAgg.c
src/backend/executor/spi.c
src/backend/postmaster/autovacuum.c
src/backend/postmaster/bgwriter.c
src/backend/postmaster/checkpointer.c
src/backend/postmaster/walwriter.c
src/backend/replication/logical/worker.c
src/backend/statistics/extended_stats.c
src/backend/tcop/postgres.c
src/backend/utils/cache/evtcache.c
src/backend/utils/error/elog.c
src/include/utils/memutils.h

index 25338a90e2926676339c8d0988b6d810e24e91c6..f0eac078e0b2effae7441494b30e9f0c5d74d884 100644 (file)
@@ -297,7 +297,7 @@ brininsert(Relation idxRel, Datum *values, bool *nulls,
                                                           samepage))
                        {
                                /* no luck; start over */
-                               MemoryContextResetAndDeleteChildren(tupcxt);
+                               MemoryContextReset(tupcxt);
                                continue;
                        }
                }
@@ -533,7 +533,7 @@ bringetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
 
                CHECK_FOR_INTERRUPTS();
 
-               MemoryContextResetAndDeleteChildren(perRangeCxt);
+               MemoryContextReset(perRangeCxt);
 
                tup = brinGetTupleForHeapBlock(opaque->bo_rmAccess, heapBlk, &buf,
                                                                           &off, &size, BUFFER_LOCK_SHARE);
index ae7b0e9bb87ef2f8299d2ab038cdf6a6af7984c9..f719577695a11a668ec78902fda9049ee3201cf1 100644 (file)
@@ -251,7 +251,7 @@ ginFreeScanKeys(GinScanOpaque so)
                        tbm_free(entry->matchBitmap);
        }
 
-       MemoryContextResetAndDeleteChildren(so->keyCtx);
+       MemoryContextReset(so->keyCtx);
 
        so->keys = NULL;
        so->nkeys = 0;
index 8fad8ffa1ebd4831fcef80575254e9765b8d4d34..536edb3792ff54508b8558d22a48666e3de59bca 100644 (file)
@@ -1933,7 +1933,7 @@ AtCleanup_Memory(void)
         * Clear the special abort context for next time.
         */
        if (TransactionAbortContext != NULL)
-               MemoryContextResetAndDeleteChildren(TransactionAbortContext);
+               MemoryContextReset(TransactionAbortContext);
 
        /*
         * Release all transaction-local memory.
@@ -1969,7 +1969,7 @@ AtSubCleanup_Memory(void)
         * Clear the special abort context for next time.
         */
        if (TransactionAbortContext != NULL)
-               MemoryContextResetAndDeleteChildren(TransactionAbortContext);
+               MemoryContextReset(TransactionAbortContext);
 
        /*
         * Delete the subxact local memory contexts. Its CurTransactionContext can
index 206d1689ef98e7196c11ac2fa5e512577f8aecc7..e264ffdcf2883efc3f6fdfb4f30a470f40e36a05 100644 (file)
@@ -583,7 +583,7 @@ do_analyze_rel(Relation onerel, VacuumParams *params,
                                        stats->stadistinct = n_distinct;
                        }
 
-                       MemoryContextResetAndDeleteChildren(col_context);
+                       MemoryContextReset(col_context);
                }
 
                if (nindexes > 0)
@@ -972,7 +972,7 @@ compute_index_stats(Relation onerel, double totalrows,
                                                                         numindexrows,
                                                                         totalindexrows);
 
-                               MemoryContextResetAndDeleteChildren(col_context);
+                               MemoryContextReset(col_context);
                        }
                }
 
@@ -981,7 +981,7 @@ compute_index_stats(Relation onerel, double totalrows,
 
                ExecDropSingleTupleTableSlot(slot);
                FreeExecutorState(estate);
-               MemoryContextResetAndDeleteChildren(ind_context);
+               MemoryContextReset(ind_context);
        }
 
        MemoryContextSwitchTo(old_context);
index e781003934129b2c866b3f270e0d36888f6ce3ac..3207643156ebb9efd6f5c3887cf3f921501bbf44 100644 (file)
@@ -317,7 +317,7 @@ ExecReScanRecursiveUnion(RecursiveUnionState *node)
 
        /* Release any hashtable storage */
        if (node->tableContext)
-               MemoryContextResetAndDeleteChildren(node->tableContext);
+               MemoryContextReset(node->tableContext);
 
        /* Empty hashtable if needed */
        if (plan->numCols > 0)
index 98c1b84d43638011536da78ddd35a4b7fa078adc..5a84969cf8178b6993a6672a2c323b58c2edbfa3 100644 (file)
@@ -631,7 +631,7 @@ ExecReScanSetOp(SetOpState *node)
 
        /* Release any hashtable storage */
        if (node->tableContext)
-               MemoryContextResetAndDeleteChildren(node->tableContext);
+               MemoryContextReset(node->tableContext);
 
        /* And rebuild empty hashtable if needed */
        if (((SetOp *) node->ps.plan)->strategy == SETOP_HASHED)
index 77724a6daaffe4caa859f3db2dca673a2c889c9f..3258305f57fbb79788c5315c623de3d26d5d5bec 100644 (file)
@@ -216,7 +216,7 @@ initialize_windowaggregate(WindowAggState *winstate,
         * it, so we must leave it to the caller to reset at an appropriate time.
         */
        if (peraggstate->aggcontext != winstate->aggcontext)
-               MemoryContextResetAndDeleteChildren(peraggstate->aggcontext);
+               MemoryContextReset(peraggstate->aggcontext);
 
        if (peraggstate->initValueIsNull)
                peraggstate->transValue = peraggstate->initValue;
@@ -875,7 +875,7 @@ eval_windowaggregates(WindowAggState *winstate)
         * result for it, else we'll leak memory.
         */
        if (numaggs_restart > 0)
-               MemoryContextResetAndDeleteChildren(winstate->aggcontext);
+               MemoryContextReset(winstate->aggcontext);
        for (i = 0; i < numaggs; i++)
        {
                peraggstate = &winstate->peragg[i];
@@ -1351,12 +1351,12 @@ release_partition(WindowAggState *winstate)
         * any aggregate temp data).  We don't rely on retail pfree because some
         * aggregates might have allocated data we don't have direct pointers to.
         */
-       MemoryContextResetAndDeleteChildren(winstate->partcontext);
-       MemoryContextResetAndDeleteChildren(winstate->aggcontext);
+       MemoryContextReset(winstate->partcontext);
+       MemoryContextReset(winstate->aggcontext);
        for (i = 0; i < winstate->numaggs; i++)
        {
                if (winstate->peragg[i].aggcontext != winstate->aggcontext)
-                       MemoryContextResetAndDeleteChildren(winstate->peragg[i].aggcontext);
+                       MemoryContextReset(winstate->peragg[i].aggcontext);
        }
 
        if (winstate->buffer)
index 33975687b3828a752a8f8006ca05338e6b58ae2a..0e46c59d25d9aee208da2f5a5379d7cab07a94eb 100644 (file)
@@ -547,7 +547,7 @@ AtEOSubXact_SPI(bool isCommit, SubTransactionId mySubid)
                if (_SPI_current->execSubid >= mySubid)
                {
                        _SPI_current->execSubid = InvalidSubTransactionId;
-                       MemoryContextResetAndDeleteChildren(_SPI_current->execCxt);
+                       MemoryContextReset(_SPI_current->execCxt);
                }
 
                /* throw away any tuple tables created within current subxact */
@@ -3083,7 +3083,7 @@ _SPI_end_call(bool use_exec)
                /* mark Executor context no longer in use */
                _SPI_current->execSubid = InvalidSubTransactionId;
                /* and free Executor memory */
-               MemoryContextResetAndDeleteChildren(_SPI_current->execCxt);
+               MemoryContextReset(_SPI_current->execCxt);
        }
 
        return 0;
index 3a6f24a023762976ada232a5921201d7c872608d..86a3b3d8be2ac2a04110981dfc148373a55fef5e 100644 (file)
@@ -555,7 +555,7 @@ AutoVacLauncherMain(int argc, char *argv[])
                FlushErrorState();
 
                /* Flush any leaked data in the top-level context */
-               MemoryContextResetAndDeleteChildren(AutovacMemCxt);
+               MemoryContextReset(AutovacMemCxt);
 
                /* don't leave dangling pointers to freed memory */
                DatabaseListCxt = NULL;
@@ -2521,7 +2521,7 @@ do_autovacuum(void)
 
 
                /* clean up memory before each iteration */
-               MemoryContextResetAndDeleteChildren(PortalContext);
+               MemoryContextReset(PortalContext);
 
                /*
                 * Save the relation name for a possible error message, to avoid a
@@ -2576,7 +2576,7 @@ do_autovacuum(void)
                        /* this resets ProcGlobal->statusFlags[i] too */
                        AbortOutOfAnyTransaction();
                        FlushErrorState();
-                       MemoryContextResetAndDeleteChildren(PortalContext);
+                       MemoryContextReset(PortalContext);
 
                        /* restart our transaction for the following operations */
                        StartTransactionCommand();
@@ -2718,7 +2718,7 @@ perform_work_item(AutoVacuumWorkItem *workitem)
        autovac_report_workitem(workitem, cur_nspname, cur_relname);
 
        /* clean up memory before each work item */
-       MemoryContextResetAndDeleteChildren(PortalContext);
+       MemoryContextReset(PortalContext);
 
        /*
         * We will abort the current work item if something errors out, and
@@ -2770,7 +2770,7 @@ perform_work_item(AutoVacuumWorkItem *workitem)
                /* this resets ProcGlobal->statusFlags[i] too */
                AbortOutOfAnyTransaction();
                FlushErrorState();
-               MemoryContextResetAndDeleteChildren(PortalContext);
+               MemoryContextReset(PortalContext);
 
                /* restart our transaction for the following operations */
                StartTransactionCommand();
index f2e4f23d9fc90efa8d5f65f28075b0c51499bfd7..d02dc17b9c1770e2bd4e0b38f5346ea1fa1f2fd3 100644 (file)
@@ -182,7 +182,7 @@ BackgroundWriterMain(void)
                FlushErrorState();
 
                /* Flush any leaked data in the top-level context */
-               MemoryContextResetAndDeleteChildren(bgwriter_context);
+               MemoryContextReset(bgwriter_context);
 
                /* re-initialize to avoid repeated errors causing problems */
                WritebackContextInit(&wb_context, &bgwriter_flush_after);
index a3c1aba24eae055014122a442a983ff2f69f7f8b..42c807d3528f74a392be9e7cc96f43a7d1ef7928 100644 (file)
@@ -290,7 +290,7 @@ CheckpointerMain(void)
                FlushErrorState();
 
                /* Flush any leaked data in the top-level context */
-               MemoryContextResetAndDeleteChildren(checkpointer_context);
+               MemoryContextReset(checkpointer_context);
 
                /* Now we can allow interrupts again */
                RESUME_INTERRUPTS();
index 266fbc23399545984f187bb01ded15c8442fa106..48bc92205b5a3b003bb2d704b5cf831dc4ee33d6 100644 (file)
@@ -178,7 +178,7 @@ WalWriterMain(void)
                FlushErrorState();
 
                /* Flush any leaked data in the top-level context */
-               MemoryContextResetAndDeleteChildren(walwriter_context);
+               MemoryContextReset(walwriter_context);
 
                /* Now we can allow interrupts again */
                RESUME_INTERRUPTS();
index 52a9f136ab90456f874036aa1b50ccc66755d072..21abf34ef7a7f02973f70d666c7df78d6e6b6243 100644 (file)
@@ -3647,7 +3647,7 @@ LogicalRepApplyLoop(XLogRecPtr last_received)
                }
 
                /* Cleanup the memory. */
-               MemoryContextResetAndDeleteChildren(ApplyMessageContext);
+               MemoryContextReset(ApplyMessageContext);
                MemoryContextSwitchTo(TopMemoryContext);
 
                /* Check if we need to exit the streaming loop. */
index 9f67a577244a365eaa2b9a0e478a0f123443c541..7f014a0cbba938f452a2ce4da289e09e836ff9fd 100644 (file)
@@ -2237,7 +2237,7 @@ compute_expr_stats(Relation onerel, double totalrows,
 
                ExecDropSingleTupleTableSlot(slot);
                FreeExecutorState(estate);
-               MemoryContextResetAndDeleteChildren(expr_context);
+               MemoryContextReset(expr_context);
        }
 
        MemoryContextSwitchTo(old_context);
index 6a070b5d8cb468f25910f3139dda75a01ea5c941..e415cf1f34a31e83df70544af0edf2f35e5da974 100644 (file)
@@ -4457,7 +4457,7 @@ PostgresMain(const char *dbname, const char *username)
                 * query input buffer in the cleared MessageContext.
                 */
                MemoryContextSwitchTo(MessageContext);
-               MemoryContextResetAndDeleteChildren(MessageContext);
+               MemoryContextReset(MessageContext);
 
                initStringInfo(&input_message);
 
index 5a721a4046d49316ae82d150fe7b6caa43a3c019..879c6d87c3229ba1fe3814741c6ac5cfaa530c2a 100644 (file)
@@ -91,7 +91,7 @@ BuildEventTriggerCache(void)
                 * This can happen either because a previous rebuild failed, or
                 * because an invalidation happened before the rebuild was complete.
                 */
-               MemoryContextResetAndDeleteChildren(EventTriggerCacheContext);
+               MemoryContextReset(EventTriggerCacheContext);
        }
        else
        {
@@ -262,7 +262,7 @@ InvalidateEventCacheCallback(Datum arg, int cacheid, uint32 hashvalue)
         */
        if (EventTriggerCacheState == ETCS_VALID)
        {
-               MemoryContextResetAndDeleteChildren(EventTriggerCacheContext);
+               MemoryContextReset(EventTriggerCacheContext);
                EventTriggerCache = NULL;
        }
 
index eeb238331e4b2b2a366d30c99d107793c25dac98..6aeb855e491bd650e5db9994aa28bc564f1afd48 100644 (file)
@@ -1833,7 +1833,7 @@ FlushErrorState(void)
        errordata_stack_depth = -1;
        recursion_depth = 0;
        /* Delete all data in ErrorContext */
-       MemoryContextResetAndDeleteChildren(ErrorContext);
+       MemoryContextReset(ErrorContext);
 }
 
 /*
index 21640d62a647d23a4bfd3f12922b615d9cc03e97..d14e8546a6056c0d39fb230fbdb3a5be7ef0fc43 100644 (file)
@@ -66,9 +66,6 @@ extern PGDLLIMPORT MemoryContext CurTransactionContext;
 /* This is a transient link to the active portal's memory context: */
 extern PGDLLIMPORT MemoryContext PortalContext;
 
-/* Backwards compatibility macro */
-#define MemoryContextResetAndDeleteChildren(ctx) MemoryContextReset(ctx)
-
 
 /*
  * Memory-context-type-independent functions in mcxt.c