Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r2cAE-0002ak-1T for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Nov 2023 19:00:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1r2cAA-000ISI-W0 for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Nov 2023 18:59:58 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1r2cAA-000ISA-DG for pgsql-hackers@lists.postgresql.org; Mon, 13 Nov 2023 18:59:58 +0000 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1r2cA6-005PGI-OH for pgsql-hackers@postgresql.org; Mon, 13 Nov 2023 18:59:56 +0000 Received: by mail-io1-xd2d.google.com with SMTP id ca18e2360f4ac-7b017766ac8so56433939f.1 for ; Mon, 13 Nov 2023 10:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699901993; x=1700506793; darn=postgresql.org; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=wYfpC/oZMTB3/SU6cattQquV5WtONUQWKJPEMVs8waQ=; b=VRgIykbN+bsTp5thFW86ton9ndwExnnQcmS3br4pqUyQaXBlt0RGrjaFGEBfEDWu3+ 5I4Sl2+/2IwMsV5h+bIIFe57h6pzewbeQpIgoGW0cSGq0WTPHxpHnTUKHqqq8bLE6AzY cakvxixZ/rjA+/1izxpXZQWZ90nA/6rEtHfsD5IWc8JrgmWDRgFNSvdOep3AUAEbmsym HcMkbjXnIAlbQKe3p+lhkatot5Sdht/0tsPQ/QAPhAcpmd+eUu92iHEzUbKi00D7s8ps ugtHIeHcGRG+2BXkLomOjx8NW+so8fKtzbur9bVWkeBZxxBDnOsmPApky7pwX88PiHqw IJhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699901993; x=1700506793; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wYfpC/oZMTB3/SU6cattQquV5WtONUQWKJPEMVs8waQ=; b=r8B6V8p3UItse9Q9VsCQOl9oeuQ+fQk2/du7SWpe38tQUjfcd8PQ8Az6+JvO0w0hyg kasKx7QWhPdxhXDd2aSNwrGCGLzwAXvq9Swf2O5QZ7pvPIhvDWeOdzywn2s/WuBPWv9P OmQMTopQ4iSVRxP545tbMS7vjYsfhK10E/2CauI6tw82arxvDnqa1hRR1pSu3+ZWYjBZ ctbW4ge5EHjAO6hz1qFCoZI+ui2ewunzi8NZVwixQ72G2OmhLrFK8XswBY6//DjG96ga RuDUeEckI2IT8BqP9en3SKJpii1ZLLp9PoPbE665K2etfp4hPCTvyeElIR/roS1lYmAv qjDw== X-Gm-Message-State: AOJu0Yws5H0CdqEGrgva2MipZh7ns8Siss/yyQYiD1vLyQec1Szd/MNf O1Pb2jvKNt/irEFUYcD4XHcl8fzvjmk= X-Google-Smtp-Source: AGHT+IH2alCMCuIDhgQTo1yUGt443WSnKnRE6viIdDTcAL5AvLv8kBgJXbNoTQRGXf+KjT+kb4EskQ== X-Received: by 2002:a05:6602:360d:b0:7b0:2664:ba1f with SMTP id bc13-20020a056602360d00b007b02664ba1fmr7739865iob.2.1699901992991; Mon, 13 Nov 2023 10:59:52 -0800 (PST) Received: from nathanxps13 (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id v13-20020a056638250d00b00463ffa38f99sm1764811jat.179.2023.11.13.10.59.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Nov 2023 10:59:52 -0800 (PST) Date: Mon, 13 Nov 2023 12:59:50 -0600 From: Nathan Bossart To: pgsql-hackers@postgresql.org Subject: retire MemoryContextResetAndDeleteChildren backwards compatibility macro Message-ID: <20231113185950.GA1668018@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="UlVJffcvxoiEqYs2" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --UlVJffcvxoiEqYs2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I just found myself researching the difference between MemoryContextReset() and MemoryContextResetAndDeleteChildren(), and it turns out that as of commit eaa5808 (2015), there is none. MemoryContextResetAndDeleteChildren() is just a backwards compatibility macro for MemoryContextReset(). I found this surprising because it sounds like they do very different things. Shall we retire this backwards compatibility macro at this point? A search of https://codesearch.debian.net/ does reveal a few external uses, so we could alternatively leave it around and just update Postgres to stop using it, but I don't think it would be too burdensome for extension authors to fix if we removed it completely. Patch attached. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --UlVJffcvxoiEqYs2 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="retire_compatibility_macro_v1.patch" diff --git a/src/backend/access/brin/brin.c b/src/backend/access/brin/brin.c index 25338a90e2..f0eac078e0 100644 --- a/src/backend/access/brin/brin.c +++ b/src/backend/access/brin/brin.c @@ -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); diff --git a/src/backend/access/gin/ginscan.c b/src/backend/access/gin/ginscan.c index ae7b0e9bb8..f719577695 100644 --- a/src/backend/access/gin/ginscan.c +++ b/src/backend/access/gin/ginscan.c @@ -251,7 +251,7 @@ ginFreeScanKeys(GinScanOpaque so) tbm_free(entry->matchBitmap); } - MemoryContextResetAndDeleteChildren(so->keyCtx); + MemoryContextReset(so->keyCtx); so->keys = NULL; so->nkeys = 0; diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 74ce5f9491..7f0c5bf43d 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -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 diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 206d1689ef..e264ffdcf2 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -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); diff --git a/src/backend/executor/nodeRecursiveunion.c b/src/backend/executor/nodeRecursiveunion.c index e781003934..3207643156 100644 --- a/src/backend/executor/nodeRecursiveunion.c +++ b/src/backend/executor/nodeRecursiveunion.c @@ -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) diff --git a/src/backend/executor/nodeSetOp.c b/src/backend/executor/nodeSetOp.c index 98c1b84d43..5a84969cf8 100644 --- a/src/backend/executor/nodeSetOp.c +++ b/src/backend/executor/nodeSetOp.c @@ -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) diff --git a/src/backend/executor/nodeWindowAgg.c b/src/backend/executor/nodeWindowAgg.c index 77724a6daa..3258305f57 100644 --- a/src/backend/executor/nodeWindowAgg.c +++ b/src/backend/executor/nodeWindowAgg.c @@ -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) diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 33975687b3..0e46c59d25 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -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; diff --git a/src/backend/postmaster/autovacuum.c b/src/backend/postmaster/autovacuum.c index 3a6f24a023..86a3b3d8be 100644 --- a/src/backend/postmaster/autovacuum.c +++ b/src/backend/postmaster/autovacuum.c @@ -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(); diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.c index f2e4f23d9f..d02dc17b9c 100644 --- a/src/backend/postmaster/bgwriter.c +++ b/src/backend/postmaster/bgwriter.c @@ -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); diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index a3c1aba24e..42c807d352 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -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(); diff --git a/src/backend/postmaster/walwriter.c b/src/backend/postmaster/walwriter.c index 266fbc2339..48bc92205b 100644 --- a/src/backend/postmaster/walwriter.c +++ b/src/backend/postmaster/walwriter.c @@ -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(); diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 52a9f136ab..21abf34ef7 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -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. */ diff --git a/src/backend/statistics/extended_stats.c b/src/backend/statistics/extended_stats.c index 9f67a57724..7f014a0cbb 100644 --- a/src/backend/statistics/extended_stats.c +++ b/src/backend/statistics/extended_stats.c @@ -2237,7 +2237,7 @@ compute_expr_stats(Relation onerel, double totalrows, ExecDropSingleTupleTableSlot(slot); FreeExecutorState(estate); - MemoryContextResetAndDeleteChildren(expr_context); + MemoryContextReset(expr_context); } MemoryContextSwitchTo(old_context); diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index 6a070b5d8c..e415cf1f34 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -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); diff --git a/src/backend/utils/cache/evtcache.c b/src/backend/utils/cache/evtcache.c index 5a721a4046..879c6d87c3 100644 --- a/src/backend/utils/cache/evtcache.c +++ b/src/backend/utils/cache/evtcache.c @@ -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; } diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index eeb238331e..6aeb855e49 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -1833,7 +1833,7 @@ FlushErrorState(void) errordata_stack_depth = -1; recursion_depth = 0; /* Delete all data in ErrorContext */ - MemoryContextResetAndDeleteChildren(ErrorContext); + MemoryContextReset(ErrorContext); } /* diff --git a/src/include/utils/memutils.h b/src/include/utils/memutils.h index 21640d62a6..d14e8546a6 100644 --- a/src/include/utils/memutils.h +++ b/src/include/utils/memutils.h @@ -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 --UlVJffcvxoiEqYs2--