Skip to content

Commit 83f4fcc

Browse files
committed
Change the name of the Result Cache node to Memoize
"Result Cache" was never a great name for this node, but nobody managed to come up with another name that anyone liked enough. That was until David Johnston mentioned "Node Memoization", which Tom Lane revised to just "Memoize". People seem to like "Memoize", so let's do the rename. Reviewed-by: Justin Pryzby Discussion: https://postgr.es/m/20210708165145.GG1176@momjian.us Backpatch-through: 14, where Result Cache was introduced
1 parent d68a003 commit 83f4fcc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+595
-606
lines changed

contrib/postgres_fdw/expected/postgres_fdw.out

+3-3
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 LEFT JOIN ft2 t2 ON (t1.c1 = t2.c1) FULL
16021602
20 | 0 | AAA020
16031603
(10 rows)
16041604

1605-
SET enable_resultcache TO off;
1605+
SET enable_memoize TO off;
16061606
-- right outer join + left outer join
16071607
EXPLAIN (VERBOSE, COSTS OFF)
16081608
SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 RIGHT JOIN ft2 t2 ON (t1.c1 = t2.c1) LEFT JOIN ft4 t3 ON (t2.c1 = t3.c1) OFFSET 10 LIMIT 10;
@@ -1629,7 +1629,7 @@ SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 RIGHT JOIN ft2 t2 ON (t1.c1 = t2.c1) LEFT
16291629
20 | 0 | AAA020
16301630
(10 rows)
16311631

1632-
RESET enable_resultcache;
1632+
RESET enable_memoize;
16331633
-- left outer join + right outer join
16341634
EXPLAIN (VERBOSE, COSTS OFF)
16351635
SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 LEFT JOIN ft2 t2 ON (t1.c1 = t2.c1) RIGHT JOIN ft4 t3 ON (t2.c1 = t3.c1) OFFSET 10 LIMIT 10;
@@ -2149,7 +2149,7 @@ SELECT t1."C 1" FROM "S 1"."T 1" t1, LATERAL (SELECT DISTINCT t2.c1, t3.c1 FROM
21492149
Output: t1."C 1"
21502150
-> Index Scan using t1_pkey on "S 1"."T 1" t1
21512151
Output: t1."C 1", t1.c2, t1.c3, t1.c4, t1.c5, t1.c6, t1.c7, t1.c8
2152-
-> Result Cache
2152+
-> Memoize
21532153
Cache Key: t1.c2
21542154
-> Subquery Scan on q
21552155
-> HashAggregate

contrib/postgres_fdw/sql/postgres_fdw.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,12 @@ SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 FULL JOIN ft2 t2 ON (t1.c1 = t2.c1) LEFT
502502
EXPLAIN (VERBOSE, COSTS OFF)
503503
SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 LEFT JOIN ft2 t2 ON (t1.c1 = t2.c1) FULL JOIN ft4 t3 ON (t2.c1 = t3.c1) OFFSET 10 LIMIT 10;
504504
SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 LEFT JOIN ft2 t2 ON (t1.c1 = t2.c1) FULL JOIN ft4 t3 ON (t2.c1 = t3.c1) OFFSET 10 LIMIT 10;
505-
SET enable_resultcache TO off;
505+
SET enable_memoize TO off;
506506
-- right outer join + left outer join
507507
EXPLAIN (VERBOSE, COSTS OFF)
508508
SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 RIGHT JOIN ft2 t2 ON (t1.c1 = t2.c1) LEFT JOIN ft4 t3 ON (t2.c1 = t3.c1) OFFSET 10 LIMIT 10;
509509
SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 RIGHT JOIN ft2 t2 ON (t1.c1 = t2.c1) LEFT JOIN ft4 t3 ON (t2.c1 = t3.c1) OFFSET 10 LIMIT 10;
510-
RESET enable_resultcache;
510+
RESET enable_memoize;
511511
-- left outer join + right outer join
512512
EXPLAIN (VERBOSE, COSTS OFF)
513513
SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 LEFT JOIN ft2 t2 ON (t1.c1 = t2.c1) RIGHT JOIN ft4 t3 ON (t2.c1 = t3.c1) OFFSET 10 LIMIT 10;

doc/src/sgml/config.sgml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5018,15 +5018,15 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
50185018
</listitem>
50195019
</varlistentry>
50205020

5021-
<varlistentry id="guc-enable-resultcache" xreflabel="enable_resultcache">
5022-
<term><varname>enable_resultcache</varname> (<type>boolean</type>)
5021+
<varlistentry id="guc-enable-memoize" xreflabel="enable_memoize">
5022+
<term><varname>enable_memoize</varname> (<type>boolean</type>)
50235023
<indexterm>
5024-
<primary><varname>enable_resultcache</varname> configuration parameter</primary>
5024+
<primary><varname>enable_memoize</varname> configuration parameter</primary>
50255025
</indexterm>
50265026
</term>
50275027
<listitem>
50285028
<para>
5029-
Enables or disables the query planner's use of result cache plans for
5029+
Enables or disables the query planner's use of memoize plans for
50305030
caching results from parameterized scans inside nested-loop joins.
50315031
This plan type allows scans to the underlying plans to be skipped when
50325032
the results for the current parameters are already in the cache. Less

src/backend/commands/explain.c

+32-33
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ static void show_sort_info(SortState *sortstate, ExplainState *es);
109109
static void show_incremental_sort_info(IncrementalSortState *incrsortstate,
110110
ExplainState *es);
111111
static void show_hash_info(HashState *hashstate, ExplainState *es);
112-
static void show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
113-
ExplainState *es);
112+
static void show_memoize_info(MemoizeState *mstate, List *ancestors,
113+
ExplainState *es);
114114
static void show_hashagg_info(AggState *hashstate, ExplainState *es);
115115
static void show_tidbitmap_info(BitmapHeapScanState *planstate,
116116
ExplainState *es);
@@ -1298,8 +1298,8 @@ ExplainNode(PlanState *planstate, List *ancestors,
12981298
case T_Material:
12991299
pname = sname = "Materialize";
13001300
break;
1301-
case T_ResultCache:
1302-
pname = sname = "Result Cache";
1301+
case T_Memoize:
1302+
pname = sname = "Memoize";
13031303
break;
13041304
case T_Sort:
13051305
pname = sname = "Sort";
@@ -2013,9 +2013,9 @@ ExplainNode(PlanState *planstate, List *ancestors,
20132013
case T_Hash:
20142014
show_hash_info(castNode(HashState, planstate), es);
20152015
break;
2016-
case T_ResultCache:
2017-
show_resultcache_info(castNode(ResultCacheState, planstate),
2018-
ancestors, es);
2016+
case T_Memoize:
2017+
show_memoize_info(castNode(MemoizeState, planstate), ancestors,
2018+
es);
20192019
break;
20202020
default:
20212021
break;
@@ -3085,13 +3085,12 @@ show_hash_info(HashState *hashstate, ExplainState *es)
30853085
}
30863086

30873087
/*
3088-
* Show information on result cache hits/misses/evictions and memory usage.
3088+
* Show information on memoize hits/misses/evictions and memory usage.
30893089
*/
30903090
static void
3091-
show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
3092-
ExplainState *es)
3091+
show_memoize_info(MemoizeState *mstate, List *ancestors, ExplainState *es)
30933092
{
3094-
Plan *plan = ((PlanState *) rcstate)->plan;
3093+
Plan *plan = ((PlanState *) mstate)->plan;
30953094
ListCell *lc;
30963095
List *context;
30973096
StringInfoData keystr;
@@ -3102,7 +3101,7 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
31023101
initStringInfo(&keystr);
31033102

31043103
/*
3105-
* It's hard to imagine having a result cache with fewer than 2 RTEs, but
3104+
* It's hard to imagine having a memoize node with fewer than 2 RTEs, but
31063105
* let's just keep the same useprefix logic as elsewhere in this file.
31073106
*/
31083107
useprefix = list_length(es->rtable) > 1 || es->verbose;
@@ -3112,7 +3111,7 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
31123111
plan,
31133112
ancestors);
31143113

3115-
foreach(lc, ((ResultCache *) plan)->param_exprs)
3114+
foreach(lc, ((Memoize *) plan)->param_exprs)
31163115
{
31173116
Node *expr = (Node *) lfirst(lc);
31183117

@@ -3138,47 +3137,47 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
31383137
if (!es->analyze)
31393138
return;
31403139

3141-
if (rcstate->stats.cache_misses > 0)
3140+
if (mstate->stats.cache_misses > 0)
31423141
{
31433142
/*
31443143
* mem_peak is only set when we freed memory, so we must use mem_used
31453144
* when mem_peak is 0.
31463145
*/
3147-
if (rcstate->stats.mem_peak > 0)
3148-
memPeakKb = (rcstate->stats.mem_peak + 1023) / 1024;
3146+
if (mstate->stats.mem_peak > 0)
3147+
memPeakKb = (mstate->stats.mem_peak + 1023) / 1024;
31493148
else
3150-
memPeakKb = (rcstate->mem_used + 1023) / 1024;
3149+
memPeakKb = (mstate->mem_used + 1023) / 1024;
31513150

31523151
if (es->format != EXPLAIN_FORMAT_TEXT)
31533152
{
3154-
ExplainPropertyInteger("Cache Hits", NULL, rcstate->stats.cache_hits, es);
3155-
ExplainPropertyInteger("Cache Misses", NULL, rcstate->stats.cache_misses, es);
3156-
ExplainPropertyInteger("Cache Evictions", NULL, rcstate->stats.cache_evictions, es);
3157-
ExplainPropertyInteger("Cache Overflows", NULL, rcstate->stats.cache_overflows, es);
3153+
ExplainPropertyInteger("Cache Hits", NULL, mstate->stats.cache_hits, es);
3154+
ExplainPropertyInteger("Cache Misses", NULL, mstate->stats.cache_misses, es);
3155+
ExplainPropertyInteger("Cache Evictions", NULL, mstate->stats.cache_evictions, es);
3156+
ExplainPropertyInteger("Cache Overflows", NULL, mstate->stats.cache_overflows, es);
31583157
ExplainPropertyInteger("Peak Memory Usage", "kB", memPeakKb, es);
31593158
}
31603159
else
31613160
{
31623161
ExplainIndentText(es);
31633162
appendStringInfo(es->str,
31643163
"Hits: " UINT64_FORMAT " Misses: " UINT64_FORMAT " Evictions: " UINT64_FORMAT " Overflows: " UINT64_FORMAT " Memory Usage: " INT64_FORMAT "kB\n",
3165-
rcstate->stats.cache_hits,
3166-
rcstate->stats.cache_misses,
3167-
rcstate->stats.cache_evictions,
3168-
rcstate->stats.cache_overflows,
3164+
mstate->stats.cache_hits,
3165+
mstate->stats.cache_misses,
3166+
mstate->stats.cache_evictions,
3167+
mstate->stats.cache_overflows,
31693168
memPeakKb);
31703169
}
31713170
}
31723171

3173-
if (rcstate->shared_info == NULL)
3172+
if (mstate->shared_info == NULL)
31743173
return;
31753174

31763175
/* Show details from parallel workers */
3177-
for (int n = 0; n < rcstate->shared_info->num_workers; n++)
3176+
for (int n = 0; n < mstate->shared_info->num_workers; n++)
31783177
{
3179-
ResultCacheInstrumentation *si;
3178+
MemoizeInstrumentation *si;
31803179

3181-
si = &rcstate->shared_info->sinstrument[n];
3180+
si = &mstate->shared_info->sinstrument[n];
31823181

31833182
/*
31843183
* Skip workers that didn't do any work. We needn't bother checking
@@ -3191,10 +3190,10 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
31913190
ExplainOpenWorker(n, es);
31923191

31933192
/*
3194-
* Since the worker's ResultCacheState.mem_used field is unavailable
3195-
* to us, ExecEndResultCache will have set the
3196-
* ResultCacheInstrumentation.mem_peak field for us. No need to do
3197-
* the zero checks like we did for the serial case above.
3193+
* Since the worker's MemoizeState.mem_used field is unavailable to
3194+
* us, ExecEndMemoize will have set the
3195+
* MemoizeInstrumentation.mem_peak field for us. No need to do the
3196+
* zero checks like we did for the serial case above.
31983197
*/
31993198
memPeakKb = (si->mem_peak + 1023) / 1024;
32003199

src/backend/executor/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ OBJS = \
5353
nodeLimit.o \
5454
nodeLockRows.o \
5555
nodeMaterial.o \
56+
nodeMemoize.o \
5657
nodeMergeAppend.o \
5758
nodeMergejoin.o \
5859
nodeModifyTable.o \
@@ -61,7 +62,6 @@ OBJS = \
6162
nodeProjectSet.o \
6263
nodeRecursiveunion.o \
6364
nodeResult.o \
64-
nodeResultCache.o \
6565
nodeSamplescan.o \
6666
nodeSeqscan.o \
6767
nodeSetOp.o \

src/backend/executor/execAmi.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "executor/nodeLimit.h"
3737
#include "executor/nodeLockRows.h"
3838
#include "executor/nodeMaterial.h"
39+
#include "executor/nodeMemoize.h"
3940
#include "executor/nodeMergeAppend.h"
4041
#include "executor/nodeMergejoin.h"
4142
#include "executor/nodeModifyTable.h"
@@ -44,7 +45,6 @@
4445
#include "executor/nodeProjectSet.h"
4546
#include "executor/nodeRecursiveunion.h"
4647
#include "executor/nodeResult.h"
47-
#include "executor/nodeResultCache.h"
4848
#include "executor/nodeSamplescan.h"
4949
#include "executor/nodeSeqscan.h"
5050
#include "executor/nodeSetOp.h"
@@ -255,8 +255,8 @@ ExecReScan(PlanState *node)
255255
ExecReScanMaterial((MaterialState *) node);
256256
break;
257257

258-
case T_ResultCacheState:
259-
ExecReScanResultCache((ResultCacheState *) node);
258+
case T_MemoizeState:
259+
ExecReScanMemoize((MemoizeState *) node);
260260
break;
261261

262262
case T_SortState:

src/backend/executor/execParallel.c

+10-11
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "executor/nodeIncrementalSort.h"
3636
#include "executor/nodeIndexonlyscan.h"
3737
#include "executor/nodeIndexscan.h"
38-
#include "executor/nodeResultCache.h"
38+
#include "executor/nodeMemoize.h"
3939
#include "executor/nodeSeqscan.h"
4040
#include "executor/nodeSort.h"
4141
#include "executor/nodeSubplan.h"
@@ -293,9 +293,9 @@ ExecParallelEstimate(PlanState *planstate, ExecParallelEstimateContext *e)
293293
/* even when not parallel-aware, for EXPLAIN ANALYZE */
294294
ExecAggEstimate((AggState *) planstate, e->pcxt);
295295
break;
296-
case T_ResultCacheState:
296+
case T_MemoizeState:
297297
/* even when not parallel-aware, for EXPLAIN ANALYZE */
298-
ExecResultCacheEstimate((ResultCacheState *) planstate, e->pcxt);
298+
ExecMemoizeEstimate((MemoizeState *) planstate, e->pcxt);
299299
break;
300300
default:
301301
break;
@@ -517,9 +517,9 @@ ExecParallelInitializeDSM(PlanState *planstate,
517517
/* even when not parallel-aware, for EXPLAIN ANALYZE */
518518
ExecAggInitializeDSM((AggState *) planstate, d->pcxt);
519519
break;
520-
case T_ResultCacheState:
520+
case T_MemoizeState:
521521
/* even when not parallel-aware, for EXPLAIN ANALYZE */
522-
ExecResultCacheInitializeDSM((ResultCacheState *) planstate, d->pcxt);
522+
ExecMemoizeInitializeDSM((MemoizeState *) planstate, d->pcxt);
523523
break;
524524
default:
525525
break;
@@ -997,7 +997,7 @@ ExecParallelReInitializeDSM(PlanState *planstate,
997997
case T_HashState:
998998
case T_SortState:
999999
case T_IncrementalSortState:
1000-
case T_ResultCacheState:
1000+
case T_MemoizeState:
10011001
/* these nodes have DSM state, but no reinitialization is required */
10021002
break;
10031003

@@ -1067,8 +1067,8 @@ ExecParallelRetrieveInstrumentation(PlanState *planstate,
10671067
case T_AggState:
10681068
ExecAggRetrieveInstrumentation((AggState *) planstate);
10691069
break;
1070-
case T_ResultCacheState:
1071-
ExecResultCacheRetrieveInstrumentation((ResultCacheState *) planstate);
1070+
case T_MemoizeState:
1071+
ExecMemoizeRetrieveInstrumentation((MemoizeState *) planstate);
10721072
break;
10731073
default:
10741074
break;
@@ -1362,10 +1362,9 @@ ExecParallelInitializeWorker(PlanState *planstate, ParallelWorkerContext *pwcxt)
13621362
/* even when not parallel-aware, for EXPLAIN ANALYZE */
13631363
ExecAggInitializeWorker((AggState *) planstate, pwcxt);
13641364
break;
1365-
case T_ResultCacheState:
1365+
case T_MemoizeState:
13661366
/* even when not parallel-aware, for EXPLAIN ANALYZE */
1367-
ExecResultCacheInitializeWorker((ResultCacheState *) planstate,
1368-
pwcxt);
1367+
ExecMemoizeInitializeWorker((MemoizeState *) planstate, pwcxt);
13691368
break;
13701369
default:
13711370
break;

src/backend/executor/execProcnode.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#include "executor/nodeLimit.h"
9595
#include "executor/nodeLockRows.h"
9696
#include "executor/nodeMaterial.h"
97+
#include "executor/nodeMemoize.h"
9798
#include "executor/nodeMergeAppend.h"
9899
#include "executor/nodeMergejoin.h"
99100
#include "executor/nodeModifyTable.h"
@@ -102,7 +103,6 @@
102103
#include "executor/nodeProjectSet.h"
103104
#include "executor/nodeRecursiveunion.h"
104105
#include "executor/nodeResult.h"
105-
#include "executor/nodeResultCache.h"
106106
#include "executor/nodeSamplescan.h"
107107
#include "executor/nodeSeqscan.h"
108108
#include "executor/nodeSetOp.h"
@@ -326,9 +326,9 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
326326
estate, eflags);
327327
break;
328328

329-
case T_ResultCache:
330-
result = (PlanState *) ExecInitResultCache((ResultCache *) node,
331-
estate, eflags);
329+
case T_Memoize:
330+
result = (PlanState *) ExecInitMemoize((Memoize *) node, estate,
331+
eflags);
332332
break;
333333

334334
case T_Group:
@@ -720,8 +720,8 @@ ExecEndNode(PlanState *node)
720720
ExecEndIncrementalSort((IncrementalSortState *) node);
721721
break;
722722

723-
case T_ResultCacheState:
724-
ExecEndResultCache((ResultCacheState *) node);
723+
case T_MemoizeState:
724+
ExecEndMemoize((MemoizeState *) node);
725725
break;
726726

727727
case T_GroupState:

0 commit comments

Comments
 (0)