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
This commit is contained in:
David Rowley 2021-07-14 12:43:58 +12:00
parent d68a003912
commit 83f4fcc655
43 changed files with 594 additions and 605 deletions

View File

@ -1602,7 +1602,7 @@ SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 LEFT JOIN ft2 t2 ON (t1.c1 = t2.c1) FULL
20 | 0 | AAA020 20 | 0 | AAA020
(10 rows) (10 rows)
SET enable_resultcache TO off; SET enable_memoize TO off;
-- right outer join + left outer join -- right outer join + left outer join
EXPLAIN (VERBOSE, COSTS OFF) EXPLAIN (VERBOSE, COSTS OFF)
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; 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
20 | 0 | AAA020 20 | 0 | AAA020
(10 rows) (10 rows)
RESET enable_resultcache; RESET enable_memoize;
-- left outer join + right outer join -- left outer join + right outer join
EXPLAIN (VERBOSE, COSTS OFF) EXPLAIN (VERBOSE, COSTS OFF)
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; 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
Output: t1."C 1" Output: t1."C 1"
-> Index Scan using t1_pkey on "S 1"."T 1" t1 -> Index Scan using t1_pkey on "S 1"."T 1" t1
Output: t1."C 1", t1.c2, t1.c3, t1.c4, t1.c5, t1.c6, t1.c7, t1.c8 Output: t1."C 1", t1.c2, t1.c3, t1.c4, t1.c5, t1.c6, t1.c7, t1.c8
-> Result Cache -> Memoize
Cache Key: t1.c2 Cache Key: t1.c2
-> Subquery Scan on q -> Subquery Scan on q
-> HashAggregate -> HashAggregate

View File

@ -502,12 +502,12 @@ SELECT t1.c1, t2.c2, t3.c3 FROM ft2 t1 FULL JOIN ft2 t2 ON (t1.c1 = t2.c1) LEFT
EXPLAIN (VERBOSE, COSTS OFF) EXPLAIN (VERBOSE, COSTS OFF)
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; 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;
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; 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;
SET enable_resultcache TO off; SET enable_memoize TO off;
-- right outer join + left outer join -- right outer join + left outer join
EXPLAIN (VERBOSE, COSTS OFF) EXPLAIN (VERBOSE, COSTS OFF)
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; 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;
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; 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;
RESET enable_resultcache; RESET enable_memoize;
-- left outer join + right outer join -- left outer join + right outer join
EXPLAIN (VERBOSE, COSTS OFF) EXPLAIN (VERBOSE, COSTS OFF)
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; 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;

View File

@ -5018,15 +5018,15 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry id="guc-enable-resultcache" xreflabel="enable_resultcache"> <varlistentry id="guc-enable-memoize" xreflabel="enable_memoize">
<term><varname>enable_resultcache</varname> (<type>boolean</type>) <term><varname>enable_memoize</varname> (<type>boolean</type>)
<indexterm> <indexterm>
<primary><varname>enable_resultcache</varname> configuration parameter</primary> <primary><varname>enable_memoize</varname> configuration parameter</primary>
</indexterm> </indexterm>
</term> </term>
<listitem> <listitem>
<para> <para>
Enables or disables the query planner's use of result cache plans for Enables or disables the query planner's use of memoize plans for
caching results from parameterized scans inside nested-loop joins. caching results from parameterized scans inside nested-loop joins.
This plan type allows scans to the underlying plans to be skipped when This plan type allows scans to the underlying plans to be skipped when
the results for the current parameters are already in the cache. Less the results for the current parameters are already in the cache. Less

View File

@ -109,8 +109,8 @@ static void show_sort_info(SortState *sortstate, ExplainState *es);
static void show_incremental_sort_info(IncrementalSortState *incrsortstate, static void show_incremental_sort_info(IncrementalSortState *incrsortstate,
ExplainState *es); ExplainState *es);
static void show_hash_info(HashState *hashstate, ExplainState *es); static void show_hash_info(HashState *hashstate, ExplainState *es);
static void show_resultcache_info(ResultCacheState *rcstate, List *ancestors, static void show_memoize_info(MemoizeState *mstate, List *ancestors,
ExplainState *es); ExplainState *es);
static void show_hashagg_info(AggState *hashstate, ExplainState *es); static void show_hashagg_info(AggState *hashstate, ExplainState *es);
static void show_tidbitmap_info(BitmapHeapScanState *planstate, static void show_tidbitmap_info(BitmapHeapScanState *planstate,
ExplainState *es); ExplainState *es);
@ -1298,8 +1298,8 @@ ExplainNode(PlanState *planstate, List *ancestors,
case T_Material: case T_Material:
pname = sname = "Materialize"; pname = sname = "Materialize";
break; break;
case T_ResultCache: case T_Memoize:
pname = sname = "Result Cache"; pname = sname = "Memoize";
break; break;
case T_Sort: case T_Sort:
pname = sname = "Sort"; pname = sname = "Sort";
@ -2013,9 +2013,9 @@ ExplainNode(PlanState *planstate, List *ancestors,
case T_Hash: case T_Hash:
show_hash_info(castNode(HashState, planstate), es); show_hash_info(castNode(HashState, planstate), es);
break; break;
case T_ResultCache: case T_Memoize:
show_resultcache_info(castNode(ResultCacheState, planstate), show_memoize_info(castNode(MemoizeState, planstate), ancestors,
ancestors, es); es);
break; break;
default: default:
break; break;
@ -3085,13 +3085,12 @@ show_hash_info(HashState *hashstate, ExplainState *es)
} }
/* /*
* Show information on result cache hits/misses/evictions and memory usage. * Show information on memoize hits/misses/evictions and memory usage.
*/ */
static void static void
show_resultcache_info(ResultCacheState *rcstate, List *ancestors, show_memoize_info(MemoizeState *mstate, List *ancestors, ExplainState *es)
ExplainState *es)
{ {
Plan *plan = ((PlanState *) rcstate)->plan; Plan *plan = ((PlanState *) mstate)->plan;
ListCell *lc; ListCell *lc;
List *context; List *context;
StringInfoData keystr; StringInfoData keystr;
@ -3102,7 +3101,7 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
initStringInfo(&keystr); initStringInfo(&keystr);
/* /*
* It's hard to imagine having a result cache with fewer than 2 RTEs, but * It's hard to imagine having a memoize node with fewer than 2 RTEs, but
* let's just keep the same useprefix logic as elsewhere in this file. * let's just keep the same useprefix logic as elsewhere in this file.
*/ */
useprefix = list_length(es->rtable) > 1 || es->verbose; useprefix = list_length(es->rtable) > 1 || es->verbose;
@ -3112,7 +3111,7 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
plan, plan,
ancestors); ancestors);
foreach(lc, ((ResultCache *) plan)->param_exprs) foreach(lc, ((Memoize *) plan)->param_exprs)
{ {
Node *expr = (Node *) lfirst(lc); Node *expr = (Node *) lfirst(lc);
@ -3138,23 +3137,23 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
if (!es->analyze) if (!es->analyze)
return; return;
if (rcstate->stats.cache_misses > 0) if (mstate->stats.cache_misses > 0)
{ {
/* /*
* mem_peak is only set when we freed memory, so we must use mem_used * mem_peak is only set when we freed memory, so we must use mem_used
* when mem_peak is 0. * when mem_peak is 0.
*/ */
if (rcstate->stats.mem_peak > 0) if (mstate->stats.mem_peak > 0)
memPeakKb = (rcstate->stats.mem_peak + 1023) / 1024; memPeakKb = (mstate->stats.mem_peak + 1023) / 1024;
else else
memPeakKb = (rcstate->mem_used + 1023) / 1024; memPeakKb = (mstate->mem_used + 1023) / 1024;
if (es->format != EXPLAIN_FORMAT_TEXT) if (es->format != EXPLAIN_FORMAT_TEXT)
{ {
ExplainPropertyInteger("Cache Hits", NULL, rcstate->stats.cache_hits, es); ExplainPropertyInteger("Cache Hits", NULL, mstate->stats.cache_hits, es);
ExplainPropertyInteger("Cache Misses", NULL, rcstate->stats.cache_misses, es); ExplainPropertyInteger("Cache Misses", NULL, mstate->stats.cache_misses, es);
ExplainPropertyInteger("Cache Evictions", NULL, rcstate->stats.cache_evictions, es); ExplainPropertyInteger("Cache Evictions", NULL, mstate->stats.cache_evictions, es);
ExplainPropertyInteger("Cache Overflows", NULL, rcstate->stats.cache_overflows, es); ExplainPropertyInteger("Cache Overflows", NULL, mstate->stats.cache_overflows, es);
ExplainPropertyInteger("Peak Memory Usage", "kB", memPeakKb, es); ExplainPropertyInteger("Peak Memory Usage", "kB", memPeakKb, es);
} }
else else
@ -3162,23 +3161,23 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
ExplainIndentText(es); ExplainIndentText(es);
appendStringInfo(es->str, appendStringInfo(es->str,
"Hits: " UINT64_FORMAT " Misses: " UINT64_FORMAT " Evictions: " UINT64_FORMAT " Overflows: " UINT64_FORMAT " Memory Usage: " INT64_FORMAT "kB\n", "Hits: " UINT64_FORMAT " Misses: " UINT64_FORMAT " Evictions: " UINT64_FORMAT " Overflows: " UINT64_FORMAT " Memory Usage: " INT64_FORMAT "kB\n",
rcstate->stats.cache_hits, mstate->stats.cache_hits,
rcstate->stats.cache_misses, mstate->stats.cache_misses,
rcstate->stats.cache_evictions, mstate->stats.cache_evictions,
rcstate->stats.cache_overflows, mstate->stats.cache_overflows,
memPeakKb); memPeakKb);
} }
} }
if (rcstate->shared_info == NULL) if (mstate->shared_info == NULL)
return; return;
/* Show details from parallel workers */ /* Show details from parallel workers */
for (int n = 0; n < rcstate->shared_info->num_workers; n++) for (int n = 0; n < mstate->shared_info->num_workers; n++)
{ {
ResultCacheInstrumentation *si; MemoizeInstrumentation *si;
si = &rcstate->shared_info->sinstrument[n]; si = &mstate->shared_info->sinstrument[n];
/* /*
* Skip workers that didn't do any work. We needn't bother checking * Skip workers that didn't do any work. We needn't bother checking
@ -3191,10 +3190,10 @@ show_resultcache_info(ResultCacheState *rcstate, List *ancestors,
ExplainOpenWorker(n, es); ExplainOpenWorker(n, es);
/* /*
* Since the worker's ResultCacheState.mem_used field is unavailable * Since the worker's MemoizeState.mem_used field is unavailable to
* to us, ExecEndResultCache will have set the * us, ExecEndMemoize will have set the
* ResultCacheInstrumentation.mem_peak field for us. No need to do * MemoizeInstrumentation.mem_peak field for us. No need to do the
* the zero checks like we did for the serial case above. * zero checks like we did for the serial case above.
*/ */
memPeakKb = (si->mem_peak + 1023) / 1024; memPeakKb = (si->mem_peak + 1023) / 1024;

View File

@ -53,6 +53,7 @@ OBJS = \
nodeLimit.o \ nodeLimit.o \
nodeLockRows.o \ nodeLockRows.o \
nodeMaterial.o \ nodeMaterial.o \
nodeMemoize.o \
nodeMergeAppend.o \ nodeMergeAppend.o \
nodeMergejoin.o \ nodeMergejoin.o \
nodeModifyTable.o \ nodeModifyTable.o \
@ -61,7 +62,6 @@ OBJS = \
nodeProjectSet.o \ nodeProjectSet.o \
nodeRecursiveunion.o \ nodeRecursiveunion.o \
nodeResult.o \ nodeResult.o \
nodeResultCache.o \
nodeSamplescan.o \ nodeSamplescan.o \
nodeSeqscan.o \ nodeSeqscan.o \
nodeSetOp.o \ nodeSetOp.o \

View File

@ -36,6 +36,7 @@
#include "executor/nodeLimit.h" #include "executor/nodeLimit.h"
#include "executor/nodeLockRows.h" #include "executor/nodeLockRows.h"
#include "executor/nodeMaterial.h" #include "executor/nodeMaterial.h"
#include "executor/nodeMemoize.h"
#include "executor/nodeMergeAppend.h" #include "executor/nodeMergeAppend.h"
#include "executor/nodeMergejoin.h" #include "executor/nodeMergejoin.h"
#include "executor/nodeModifyTable.h" #include "executor/nodeModifyTable.h"
@ -44,7 +45,6 @@
#include "executor/nodeProjectSet.h" #include "executor/nodeProjectSet.h"
#include "executor/nodeRecursiveunion.h" #include "executor/nodeRecursiveunion.h"
#include "executor/nodeResult.h" #include "executor/nodeResult.h"
#include "executor/nodeResultCache.h"
#include "executor/nodeSamplescan.h" #include "executor/nodeSamplescan.h"
#include "executor/nodeSeqscan.h" #include "executor/nodeSeqscan.h"
#include "executor/nodeSetOp.h" #include "executor/nodeSetOp.h"
@ -255,8 +255,8 @@ ExecReScan(PlanState *node)
ExecReScanMaterial((MaterialState *) node); ExecReScanMaterial((MaterialState *) node);
break; break;
case T_ResultCacheState: case T_MemoizeState:
ExecReScanResultCache((ResultCacheState *) node); ExecReScanMemoize((MemoizeState *) node);
break; break;
case T_SortState: case T_SortState:

View File

@ -35,7 +35,7 @@
#include "executor/nodeIncrementalSort.h" #include "executor/nodeIncrementalSort.h"
#include "executor/nodeIndexonlyscan.h" #include "executor/nodeIndexonlyscan.h"
#include "executor/nodeIndexscan.h" #include "executor/nodeIndexscan.h"
#include "executor/nodeResultCache.h" #include "executor/nodeMemoize.h"
#include "executor/nodeSeqscan.h" #include "executor/nodeSeqscan.h"
#include "executor/nodeSort.h" #include "executor/nodeSort.h"
#include "executor/nodeSubplan.h" #include "executor/nodeSubplan.h"
@ -293,9 +293,9 @@ ExecParallelEstimate(PlanState *planstate, ExecParallelEstimateContext *e)
/* even when not parallel-aware, for EXPLAIN ANALYZE */ /* even when not parallel-aware, for EXPLAIN ANALYZE */
ExecAggEstimate((AggState *) planstate, e->pcxt); ExecAggEstimate((AggState *) planstate, e->pcxt);
break; break;
case T_ResultCacheState: case T_MemoizeState:
/* even when not parallel-aware, for EXPLAIN ANALYZE */ /* even when not parallel-aware, for EXPLAIN ANALYZE */
ExecResultCacheEstimate((ResultCacheState *) planstate, e->pcxt); ExecMemoizeEstimate((MemoizeState *) planstate, e->pcxt);
break; break;
default: default:
break; break;
@ -517,9 +517,9 @@ ExecParallelInitializeDSM(PlanState *planstate,
/* even when not parallel-aware, for EXPLAIN ANALYZE */ /* even when not parallel-aware, for EXPLAIN ANALYZE */
ExecAggInitializeDSM((AggState *) planstate, d->pcxt); ExecAggInitializeDSM((AggState *) planstate, d->pcxt);
break; break;
case T_ResultCacheState: case T_MemoizeState:
/* even when not parallel-aware, for EXPLAIN ANALYZE */ /* even when not parallel-aware, for EXPLAIN ANALYZE */
ExecResultCacheInitializeDSM((ResultCacheState *) planstate, d->pcxt); ExecMemoizeInitializeDSM((MemoizeState *) planstate, d->pcxt);
break; break;
default: default:
break; break;
@ -997,7 +997,7 @@ ExecParallelReInitializeDSM(PlanState *planstate,
case T_HashState: case T_HashState:
case T_SortState: case T_SortState:
case T_IncrementalSortState: case T_IncrementalSortState:
case T_ResultCacheState: case T_MemoizeState:
/* these nodes have DSM state, but no reinitialization is required */ /* these nodes have DSM state, but no reinitialization is required */
break; break;
@ -1067,8 +1067,8 @@ ExecParallelRetrieveInstrumentation(PlanState *planstate,
case T_AggState: case T_AggState:
ExecAggRetrieveInstrumentation((AggState *) planstate); ExecAggRetrieveInstrumentation((AggState *) planstate);
break; break;
case T_ResultCacheState: case T_MemoizeState:
ExecResultCacheRetrieveInstrumentation((ResultCacheState *) planstate); ExecMemoizeRetrieveInstrumentation((MemoizeState *) planstate);
break; break;
default: default:
break; break;
@ -1362,10 +1362,9 @@ ExecParallelInitializeWorker(PlanState *planstate, ParallelWorkerContext *pwcxt)
/* even when not parallel-aware, for EXPLAIN ANALYZE */ /* even when not parallel-aware, for EXPLAIN ANALYZE */
ExecAggInitializeWorker((AggState *) planstate, pwcxt); ExecAggInitializeWorker((AggState *) planstate, pwcxt);
break; break;
case T_ResultCacheState: case T_MemoizeState:
/* even when not parallel-aware, for EXPLAIN ANALYZE */ /* even when not parallel-aware, for EXPLAIN ANALYZE */
ExecResultCacheInitializeWorker((ResultCacheState *) planstate, ExecMemoizeInitializeWorker((MemoizeState *) planstate, pwcxt);
pwcxt);
break; break;
default: default:
break; break;

View File

@ -94,6 +94,7 @@
#include "executor/nodeLimit.h" #include "executor/nodeLimit.h"
#include "executor/nodeLockRows.h" #include "executor/nodeLockRows.h"
#include "executor/nodeMaterial.h" #include "executor/nodeMaterial.h"
#include "executor/nodeMemoize.h"
#include "executor/nodeMergeAppend.h" #include "executor/nodeMergeAppend.h"
#include "executor/nodeMergejoin.h" #include "executor/nodeMergejoin.h"
#include "executor/nodeModifyTable.h" #include "executor/nodeModifyTable.h"
@ -102,7 +103,6 @@
#include "executor/nodeProjectSet.h" #include "executor/nodeProjectSet.h"
#include "executor/nodeRecursiveunion.h" #include "executor/nodeRecursiveunion.h"
#include "executor/nodeResult.h" #include "executor/nodeResult.h"
#include "executor/nodeResultCache.h"
#include "executor/nodeSamplescan.h" #include "executor/nodeSamplescan.h"
#include "executor/nodeSeqscan.h" #include "executor/nodeSeqscan.h"
#include "executor/nodeSetOp.h" #include "executor/nodeSetOp.h"
@ -326,9 +326,9 @@ ExecInitNode(Plan *node, EState *estate, int eflags)
estate, eflags); estate, eflags);
break; break;
case T_ResultCache: case T_Memoize:
result = (PlanState *) ExecInitResultCache((ResultCache *) node, result = (PlanState *) ExecInitMemoize((Memoize *) node, estate,
estate, eflags); eflags);
break; break;
case T_Group: case T_Group:
@ -720,8 +720,8 @@ ExecEndNode(PlanState *node)
ExecEndIncrementalSort((IncrementalSortState *) node); ExecEndIncrementalSort((IncrementalSortState *) node);
break; break;
case T_ResultCacheState: case T_MemoizeState:
ExecEndResultCache((ResultCacheState *) node); ExecEndMemoize((MemoizeState *) node);
break; break;
case T_GroupState: case T_GroupState:

View File

@ -950,12 +950,12 @@ _copyMaterial(const Material *from)
/* /*
* _copyResultCache * _copyMemoize
*/ */
static ResultCache * static Memoize *
_copyResultCache(const ResultCache *from) _copyMemoize(const Memoize *from)
{ {
ResultCache *newnode = makeNode(ResultCache); Memoize *newnode = makeNode(Memoize);
/* /*
* copy node superclass fields * copy node superclass fields
@ -5079,8 +5079,8 @@ copyObjectImpl(const void *from)
case T_Material: case T_Material:
retval = _copyMaterial(from); retval = _copyMaterial(from);
break; break;
case T_ResultCache: case T_Memoize:
retval = _copyResultCache(from); retval = _copyMemoize(from);
break; break;
case T_Sort: case T_Sort:
retval = _copySort(from); retval = _copySort(from);

View File

@ -848,9 +848,9 @@ _outMaterial(StringInfo str, const Material *node)
} }
static void static void
_outResultCache(StringInfo str, const ResultCache *node) _outMemoize(StringInfo str, const Memoize *node)
{ {
WRITE_NODE_TYPE("RESULTCACHE"); WRITE_NODE_TYPE("MEMOIZE");
_outPlanInfo(str, (const Plan *) node); _outPlanInfo(str, (const Plan *) node);
@ -1949,9 +1949,9 @@ _outMaterialPath(StringInfo str, const MaterialPath *node)
} }
static void static void
_outResultCachePath(StringInfo str, const ResultCachePath *node) _outMemoizePath(StringInfo str, const MemoizePath *node)
{ {
WRITE_NODE_TYPE("RESULTCACHEPATH"); WRITE_NODE_TYPE("MEMOIZEPATH");
_outPathInfo(str, (const Path *) node); _outPathInfo(str, (const Path *) node);
@ -3961,8 +3961,8 @@ outNode(StringInfo str, const void *obj)
case T_Material: case T_Material:
_outMaterial(str, obj); _outMaterial(str, obj);
break; break;
case T_ResultCache: case T_Memoize:
_outResultCache(str, obj); _outMemoize(str, obj);
break; break;
case T_Sort: case T_Sort:
_outSort(str, obj); _outSort(str, obj);
@ -4201,8 +4201,8 @@ outNode(StringInfo str, const void *obj)
case T_MaterialPath: case T_MaterialPath:
_outMaterialPath(str, obj); _outMaterialPath(str, obj);
break; break;
case T_ResultCachePath: case T_MemoizePath:
_outResultCachePath(str, obj); _outMemoizePath(str, obj);
break; break;
case T_UniquePath: case T_UniquePath:
_outUniquePath(str, obj); _outUniquePath(str, obj);

View File

@ -2216,12 +2216,12 @@ _readMaterial(void)
} }
/* /*
* _readResultCache * _readMemoize
*/ */
static ResultCache * static Memoize *
_readResultCache(void) _readMemoize(void)
{ {
READ_LOCALS(ResultCache); READ_LOCALS(Memoize);
ReadCommonPlan(&local_node->plan); ReadCommonPlan(&local_node->plan);
@ -2923,8 +2923,8 @@ parseNodeString(void)
return_value = _readHashJoin(); return_value = _readHashJoin();
else if (MATCH("MATERIAL", 8)) else if (MATCH("MATERIAL", 8))
return_value = _readMaterial(); return_value = _readMaterial();
else if (MATCH("RESULTCACHE", 11)) else if (MATCH("MEMOIZE", 7))
return_value = _readResultCache(); return_value = _readMemoize();
else if (MATCH("SORT", 4)) else if (MATCH("SORT", 4))
return_value = _readSort(); return_value = _readSort();
else if (MATCH("INCREMENTALSORT", 15)) else if (MATCH("INCREMENTALSORT", 15))

View File

@ -382,7 +382,7 @@ RelOptInfo - a relation or joined relations
MergeAppendPath - merge multiple subpaths, preserving their common sort order MergeAppendPath - merge multiple subpaths, preserving their common sort order
GroupResultPath - childless Result plan node (used for degenerate grouping) GroupResultPath - childless Result plan node (used for degenerate grouping)
MaterialPath - a Material plan node MaterialPath - a Material plan node
ResultCachePath - a result cache plan node for caching tuples from sub-paths MemoizePath - a Memoize plan node for caching tuples from sub-paths
UniquePath - remove duplicate rows (either by hashing or sorting) UniquePath - remove duplicate rows (either by hashing or sorting)
GatherPath - collect the results of parallel workers GatherPath - collect the results of parallel workers
GatherMergePath - collect parallel results, preserving their common sort order GatherMergePath - collect parallel results, preserving their common sort order

View File

@ -4031,9 +4031,9 @@ print_path(PlannerInfo *root, Path *path, int indent)
ptype = "Material"; ptype = "Material";
subpath = ((MaterialPath *) path)->subpath; subpath = ((MaterialPath *) path)->subpath;
break; break;
case T_ResultCachePath: case T_MemoizePath:
ptype = "ResultCache"; ptype = "Memoize";
subpath = ((ResultCachePath *) path)->subpath; subpath = ((MemoizePath *) path)->subpath;
break; break;
case T_UniquePath: case T_UniquePath:
ptype = "Unique"; ptype = "Unique";

View File

@ -79,7 +79,7 @@
#include "executor/executor.h" #include "executor/executor.h"
#include "executor/nodeAgg.h" #include "executor/nodeAgg.h"
#include "executor/nodeHash.h" #include "executor/nodeHash.h"
#include "executor/nodeResultCache.h" #include "executor/nodeMemoize.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h" #include "nodes/nodeFuncs.h"
@ -140,7 +140,7 @@ bool enable_incremental_sort = true;
bool enable_hashagg = true; bool enable_hashagg = true;
bool enable_nestloop = true; bool enable_nestloop = true;
bool enable_material = true; bool enable_material = true;
bool enable_resultcache = true; bool enable_memoize = true;
bool enable_mergejoin = true; bool enable_mergejoin = true;
bool enable_hashjoin = true; bool enable_hashjoin = true;
bool enable_gathermerge = true; bool enable_gathermerge = true;
@ -2405,8 +2405,8 @@ cost_material(Path *path,
} }
/* /*
* cost_resultcache_rescan * cost_memoize_rescan
* Determines the estimated cost of rescanning a ResultCache node. * Determines the estimated cost of rescanning a Memoize node.
* *
* In order to estimate this, we must gain knowledge of how often we expect to * In order to estimate this, we must gain knowledge of how often we expect to
* be called and how many distinct sets of parameters we are likely to be * be called and how many distinct sets of parameters we are likely to be
@ -2418,15 +2418,15 @@ cost_material(Path *path,
* hit and caching would be a complete waste of effort. * hit and caching would be a complete waste of effort.
*/ */
static void static void
cost_resultcache_rescan(PlannerInfo *root, ResultCachePath *rcpath, cost_memoize_rescan(PlannerInfo *root, MemoizePath *mpath,
Cost *rescan_startup_cost, Cost *rescan_total_cost) Cost *rescan_startup_cost, Cost *rescan_total_cost)
{ {
EstimationInfo estinfo; EstimationInfo estinfo;
Cost input_startup_cost = rcpath->subpath->startup_cost; Cost input_startup_cost = mpath->subpath->startup_cost;
Cost input_total_cost = rcpath->subpath->total_cost; Cost input_total_cost = mpath->subpath->total_cost;
double tuples = rcpath->subpath->rows; double tuples = mpath->subpath->rows;
double calls = rcpath->calls; double calls = mpath->calls;
int width = rcpath->subpath->pathtarget->width; int width = mpath->subpath->pathtarget->width;
double hash_mem_bytes; double hash_mem_bytes;
double est_entry_bytes; double est_entry_bytes;
@ -2455,16 +2455,16 @@ cost_resultcache_rescan(PlannerInfo *root, ResultCachePath *rcpath,
est_cache_entries = floor(hash_mem_bytes / est_entry_bytes); est_cache_entries = floor(hash_mem_bytes / est_entry_bytes);
/* estimate on the distinct number of parameter values */ /* estimate on the distinct number of parameter values */
ndistinct = estimate_num_groups(root, rcpath->param_exprs, calls, NULL, ndistinct = estimate_num_groups(root, mpath->param_exprs, calls, NULL,
&estinfo); &estinfo);
/* /*
* When the estimation fell back on using a default value, it's a bit too * When the estimation fell back on using a default value, it's a bit too
* risky to assume that it's ok to use a Result Cache. The use of a * risky to assume that it's ok to use a Memoize node. The use of a
* default could cause us to use a Result Cache when it's really * default could cause us to use a Memoize node when it's really
* inappropriate to do so. If we see that this has been done, then we'll * inappropriate to do so. If we see that this has been done, then we'll
* assume that every call will have unique parameters, which will almost * assume that every call will have unique parameters, which will almost
* certainly mean a ResultCachePath will never survive add_path(). * certainly mean a MemoizePath will never survive add_path().
*/ */
if ((estinfo.flags & SELFLAG_USED_DEFAULT) != 0) if ((estinfo.flags & SELFLAG_USED_DEFAULT) != 0)
ndistinct = calls; ndistinct = calls;
@ -2478,8 +2478,8 @@ cost_resultcache_rescan(PlannerInfo *root, ResultCachePath *rcpath,
* size itself. Really this is not the right place to do this, but it's * size itself. Really this is not the right place to do this, but it's
* convenient since everything is already calculated. * convenient since everything is already calculated.
*/ */
rcpath->est_entries = Min(Min(ndistinct, est_cache_entries), mpath->est_entries = Min(Min(ndistinct, est_cache_entries),
PG_UINT32_MAX); PG_UINT32_MAX);
/* /*
* When the number of distinct parameter values is above the amount we can * When the number of distinct parameter values is above the amount we can
@ -4285,10 +4285,10 @@ cost_rescan(PlannerInfo *root, Path *path,
*rescan_total_cost = run_cost; *rescan_total_cost = run_cost;
} }
break; break;
case T_ResultCache: case T_Memoize:
/* All the hard work is done by cost_resultcache_rescan */ /* All the hard work is done by cost_memoize_rescan */
cost_resultcache_rescan(root, (ResultCachePath *) path, cost_memoize_rescan(root, (MemoizePath *) path,
rescan_startup_cost, rescan_total_cost); rescan_startup_cost, rescan_total_cost);
break; break;
default: default:
*rescan_startup_cost = path->startup_cost; *rescan_startup_cost = path->startup_cost;

View File

@ -171,7 +171,7 @@ add_paths_to_joinrel(PlannerInfo *root,
case JOIN_ANTI: case JOIN_ANTI:
/* /*
* XXX it may be worth proving this to allow a ResultCache to be * XXX it may be worth proving this to allow a Memoize to be
* considered for Nested Loop Semi/Anti Joins. * considered for Nested Loop Semi/Anti Joins.
*/ */
extra.inner_unique = false; /* well, unproven */ extra.inner_unique = false; /* well, unproven */
@ -395,7 +395,7 @@ paraminfo_get_equal_hashops(PlannerInfo *root, ParamPathInfo *param_info,
OpExpr *opexpr; OpExpr *opexpr;
Node *expr; Node *expr;
/* can't use result cache without a valid hash equals operator */ /* can't use a memoize node without a valid hash equals operator */
if (!OidIsValid(rinfo->hasheqoperator) || if (!OidIsValid(rinfo->hasheqoperator) ||
!clause_sides_match_join(rinfo, outerrel, innerrel)) !clause_sides_match_join(rinfo, outerrel, innerrel))
{ {
@ -436,7 +436,7 @@ paraminfo_get_equal_hashops(PlannerInfo *root, ParamPathInfo *param_info,
typentry = lookup_type_cache(exprType(expr), typentry = lookup_type_cache(exprType(expr),
TYPECACHE_HASH_PROC | TYPECACHE_EQ_OPR); TYPECACHE_HASH_PROC | TYPECACHE_EQ_OPR);
/* can't use result cache without a valid hash equals operator */ /* can't use a memoize node without a valid hash equals operator */
if (!OidIsValid(typentry->hash_proc) || !OidIsValid(typentry->eq_opr)) if (!OidIsValid(typentry->hash_proc) || !OidIsValid(typentry->eq_opr))
{ {
list_free(*operators); list_free(*operators);
@ -448,27 +448,27 @@ paraminfo_get_equal_hashops(PlannerInfo *root, ParamPathInfo *param_info,
*param_exprs = lappend(*param_exprs, expr); *param_exprs = lappend(*param_exprs, expr);
} }
/* We're okay to use result cache */ /* We're okay to use memoize */
return true; return true;
} }
/* /*
* get_resultcache_path * get_memoize_path
* If possible, make and return a Result Cache path atop of 'inner_path'. * If possible, make and return a Memoize path atop of 'inner_path'.
* Otherwise return NULL. * Otherwise return NULL.
*/ */
static Path * static Path *
get_resultcache_path(PlannerInfo *root, RelOptInfo *innerrel, get_memoize_path(PlannerInfo *root, RelOptInfo *innerrel,
RelOptInfo *outerrel, Path *inner_path, RelOptInfo *outerrel, Path *inner_path,
Path *outer_path, JoinType jointype, Path *outer_path, JoinType jointype,
JoinPathExtraData *extra) JoinPathExtraData *extra)
{ {
List *param_exprs; List *param_exprs;
List *hash_operators; List *hash_operators;
ListCell *lc; ListCell *lc;
/* Obviously not if it's disabled */ /* Obviously not if it's disabled */
if (!enable_resultcache) if (!enable_memoize)
return NULL; return NULL;
/* /*
@ -481,7 +481,7 @@ get_resultcache_path(PlannerInfo *root, RelOptInfo *innerrel,
return NULL; return NULL;
/* /*
* We can only have a result cache when there's some kind of cache key, * We can only have a memoize node when there's some kind of cache key,
* either parameterized path clauses or lateral Vars. No cache key sounds * either parameterized path clauses or lateral Vars. No cache key sounds
* more like something a Materialize node might be more useful for. * more like something a Materialize node might be more useful for.
*/ */
@ -493,8 +493,8 @@ get_resultcache_path(PlannerInfo *root, RelOptInfo *innerrel,
/* /*
* Currently we don't do this for SEMI and ANTI joins unless they're * Currently we don't do this for SEMI and ANTI joins unless they're
* marked as inner_unique. This is because nested loop SEMI/ANTI joins * marked as inner_unique. This is because nested loop SEMI/ANTI joins
* don't scan the inner node to completion, which will mean result cache * don't scan the inner node to completion, which will mean memoize cannot
* cannot mark the cache entry as complete. * mark the cache entry as complete.
* *
* XXX Currently we don't attempt to mark SEMI/ANTI joins as inner_unique * XXX Currently we don't attempt to mark SEMI/ANTI joins as inner_unique
* = true. Should we? See add_paths_to_joinrel() * = true. Should we? See add_paths_to_joinrel()
@ -504,8 +504,8 @@ get_resultcache_path(PlannerInfo *root, RelOptInfo *innerrel,
return NULL; return NULL;
/* /*
* Result Cache normally marks cache entries as complete when it runs out * Memoize normally marks cache entries as complete when it runs out of
* of tuples to read from its subplan. However, with unique joins, Nested * tuples to read from its subplan. However, with unique joins, Nested
* Loop will skip to the next outer tuple after finding the first matching * Loop will skip to the next outer tuple after finding the first matching
* inner tuple. This means that we may not read the inner side of the * inner tuple. This means that we may not read the inner side of the
* join to completion which leaves no opportunity to mark the cache entry * join to completion which leaves no opportunity to mark the cache entry
@ -516,11 +516,11 @@ get_resultcache_path(PlannerInfo *root, RelOptInfo *innerrel,
* condition, we can't be sure which part of it causes the join to be * condition, we can't be sure which part of it causes the join to be
* unique. This means there are no guarantees that only 1 tuple will be * unique. This means there are no guarantees that only 1 tuple will be
* read. We cannot mark the cache entry as complete after reading the * read. We cannot mark the cache entry as complete after reading the
* first tuple without that guarantee. This means the scope of Result * first tuple without that guarantee. This means the scope of Memoize
* Cache's usefulness is limited to only outer rows that have no join * node's usefulness is limited to only outer rows that have no join
* partner as this is the only case where Nested Loop would exhaust the * partner as this is the only case where Nested Loop would exhaust the
* inner scan of a unique join. Since the scope is limited to that, we * inner scan of a unique join. Since the scope is limited to that, we
* just don't bother making a result cache path in this case. * just don't bother making a memoize path in this case.
* *
* Lateral vars needn't be considered here as they're not considered when * Lateral vars needn't be considered here as they're not considered when
* determining if the join is unique. * determining if the join is unique.
@ -536,7 +536,7 @@ get_resultcache_path(PlannerInfo *root, RelOptInfo *innerrel,
return NULL; return NULL;
/* /*
* We can't use a result cache if there are volatile functions in the * We can't use a memoize node if there are volatile functions in the
* inner rel's target list or restrict list. A cache hit could reduce the * inner rel's target list or restrict list. A cache hit could reduce the
* number of calls to these functions. * number of calls to these functions.
*/ */
@ -559,13 +559,13 @@ get_resultcache_path(PlannerInfo *root, RelOptInfo *innerrel,
&param_exprs, &param_exprs,
&hash_operators)) &hash_operators))
{ {
return (Path *) create_resultcache_path(root, return (Path *) create_memoize_path(root,
innerrel, innerrel,
inner_path, inner_path,
param_exprs, param_exprs,
hash_operators, hash_operators,
extra->inner_unique, extra->inner_unique,
outer_path->parent->rows); outer_path->parent->rows);
} }
return NULL; return NULL;
@ -1688,7 +1688,7 @@ match_unsorted_outer(PlannerInfo *root,
foreach(lc2, innerrel->cheapest_parameterized_paths) foreach(lc2, innerrel->cheapest_parameterized_paths)
{ {
Path *innerpath = (Path *) lfirst(lc2); Path *innerpath = (Path *) lfirst(lc2);
Path *rcpath; Path *mpath;
try_nestloop_path(root, try_nestloop_path(root,
joinrel, joinrel,
@ -1699,17 +1699,17 @@ match_unsorted_outer(PlannerInfo *root,
extra); extra);
/* /*
* Try generating a result cache path and see if that makes * Try generating a memoize path and see if that makes the
* the nested loop any cheaper. * nested loop any cheaper.
*/ */
rcpath = get_resultcache_path(root, innerrel, outerrel, mpath = get_memoize_path(root, innerrel, outerrel,
innerpath, outerpath, jointype, innerpath, outerpath, jointype,
extra); extra);
if (rcpath != NULL) if (mpath != NULL)
try_nestloop_path(root, try_nestloop_path(root,
joinrel, joinrel,
outerpath, outerpath,
rcpath, mpath,
merge_pathkeys, merge_pathkeys,
jointype, jointype,
extra); extra);
@ -1867,7 +1867,7 @@ consider_parallel_nestloop(PlannerInfo *root,
foreach(lc2, innerrel->cheapest_parameterized_paths) foreach(lc2, innerrel->cheapest_parameterized_paths)
{ {
Path *innerpath = (Path *) lfirst(lc2); Path *innerpath = (Path *) lfirst(lc2);
Path *rcpath; Path *mpath;
/* Can't join to an inner path that is not parallel-safe */ /* Can't join to an inner path that is not parallel-safe */
if (!innerpath->parallel_safe) if (!innerpath->parallel_safe)
@ -1894,14 +1894,14 @@ consider_parallel_nestloop(PlannerInfo *root,
pathkeys, jointype, extra); pathkeys, jointype, extra);
/* /*
* Try generating a result cache path and see if that makes the * Try generating a memoize path and see if that makes the nested
* nested loop any cheaper. * loop any cheaper.
*/ */
rcpath = get_resultcache_path(root, innerrel, outerrel, mpath = get_memoize_path(root, innerrel, outerrel,
innerpath, outerpath, jointype, innerpath, outerpath, jointype,
extra); extra);
if (rcpath != NULL) if (mpath != NULL)
try_partial_nestloop_path(root, joinrel, outerpath, rcpath, try_partial_nestloop_path(root, joinrel, outerpath, mpath,
pathkeys, jointype, extra); pathkeys, jointype, extra);
} }
} }

View File

@ -92,9 +92,8 @@ static Result *create_group_result_plan(PlannerInfo *root,
static ProjectSet *create_project_set_plan(PlannerInfo *root, ProjectSetPath *best_path); static ProjectSet *create_project_set_plan(PlannerInfo *root, ProjectSetPath *best_path);
static Material *create_material_plan(PlannerInfo *root, MaterialPath *best_path, static Material *create_material_plan(PlannerInfo *root, MaterialPath *best_path,
int flags); int flags);
static ResultCache *create_resultcache_plan(PlannerInfo *root, static Memoize *create_memoize_plan(PlannerInfo *root, MemoizePath *best_path,
ResultCachePath *best_path, int flags);
int flags);
static Plan *create_unique_plan(PlannerInfo *root, UniquePath *best_path, static Plan *create_unique_plan(PlannerInfo *root, UniquePath *best_path,
int flags); int flags);
static Gather *create_gather_plan(PlannerInfo *root, GatherPath *best_path); static Gather *create_gather_plan(PlannerInfo *root, GatherPath *best_path);
@ -278,11 +277,9 @@ static Sort *make_sort_from_groupcols(List *groupcls,
AttrNumber *grpColIdx, AttrNumber *grpColIdx,
Plan *lefttree); Plan *lefttree);
static Material *make_material(Plan *lefttree); static Material *make_material(Plan *lefttree);
static ResultCache *make_resultcache(Plan *lefttree, Oid *hashoperators, static Memoize *make_memoize(Plan *lefttree, Oid *hashoperators,
Oid *collations, Oid *collations, List *param_exprs,
List *param_exprs, bool singlerow, uint32 est_entries);
bool singlerow,
uint32 est_entries);
static WindowAgg *make_windowagg(List *tlist, Index winref, static WindowAgg *make_windowagg(List *tlist, Index winref,
int partNumCols, AttrNumber *partColIdx, Oid *partOperators, Oid *partCollations, int partNumCols, AttrNumber *partColIdx, Oid *partOperators, Oid *partCollations,
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations, int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
@ -459,10 +456,10 @@ create_plan_recurse(PlannerInfo *root, Path *best_path, int flags)
(MaterialPath *) best_path, (MaterialPath *) best_path,
flags); flags);
break; break;
case T_ResultCache: case T_Memoize:
plan = (Plan *) create_resultcache_plan(root, plan = (Plan *) create_memoize_plan(root,
(ResultCachePath *) best_path, (MemoizePath *) best_path,
flags); flags);
break; break;
case T_Unique: case T_Unique:
if (IsA(best_path, UpperUniquePath)) if (IsA(best_path, UpperUniquePath))
@ -1578,16 +1575,16 @@ create_material_plan(PlannerInfo *root, MaterialPath *best_path, int flags)
} }
/* /*
* create_resultcache_plan * create_memoize_plan
* Create a ResultCache plan for 'best_path' and (recursively) plans * Create a Memoize plan for 'best_path' and (recursively) plans for its
* for its subpaths. * subpaths.
* *
* Returns a Plan node. * Returns a Plan node.
*/ */
static ResultCache * static Memoize *
create_resultcache_plan(PlannerInfo *root, ResultCachePath *best_path, int flags) create_memoize_plan(PlannerInfo *root, MemoizePath *best_path, int flags)
{ {
ResultCache *plan; Memoize *plan;
Plan *subplan; Plan *subplan;
Oid *operators; Oid *operators;
Oid *collations; Oid *collations;
@ -1619,8 +1616,8 @@ create_resultcache_plan(PlannerInfo *root, ResultCachePath *best_path, int flags
i++; i++;
} }
plan = make_resultcache(subplan, operators, collations, param_exprs, plan = make_memoize(subplan, operators, collations, param_exprs,
best_path->singlerow, best_path->est_entries); best_path->singlerow, best_path->est_entries);
copy_generic_path_info(&plan->plan, (Path *) best_path); copy_generic_path_info(&plan->plan, (Path *) best_path);
@ -6417,11 +6414,11 @@ materialize_finished_plan(Plan *subplan)
return matplan; return matplan;
} }
static ResultCache * static Memoize *
make_resultcache(Plan *lefttree, Oid *hashoperators, Oid *collations, make_memoize(Plan *lefttree, Oid *hashoperators, Oid *collations,
List *param_exprs, bool singlerow, uint32 est_entries) List *param_exprs, bool singlerow, uint32 est_entries)
{ {
ResultCache *node = makeNode(ResultCache); Memoize *node = makeNode(Memoize);
Plan *plan = &node->plan; Plan *plan = &node->plan;
plan->targetlist = lefttree->targetlist; plan->targetlist = lefttree->targetlist;
@ -7035,7 +7032,7 @@ is_projection_capable_path(Path *path)
{ {
case T_Hash: case T_Hash:
case T_Material: case T_Material:
case T_ResultCache: case T_Memoize:
case T_Sort: case T_Sort:
case T_IncrementalSort: case T_IncrementalSort:
case T_Unique: case T_Unique:
@ -7085,7 +7082,7 @@ is_projection_capable_plan(Plan *plan)
{ {
case T_Hash: case T_Hash:
case T_Material: case T_Material:
case T_ResultCache: case T_Memoize:
case T_Sort: case T_Sort:
case T_Unique: case T_Unique:
case T_SetOp: case T_SetOp:

View File

@ -78,7 +78,7 @@ static bool check_equivalence_delay(PlannerInfo *root,
static bool check_redundant_nullability_qual(PlannerInfo *root, Node *clause); static bool check_redundant_nullability_qual(PlannerInfo *root, Node *clause);
static void check_mergejoinable(RestrictInfo *restrictinfo); static void check_mergejoinable(RestrictInfo *restrictinfo);
static void check_hashjoinable(RestrictInfo *restrictinfo); static void check_hashjoinable(RestrictInfo *restrictinfo);
static void check_resultcacheable(RestrictInfo *restrictinfo); static void check_memoizable(RestrictInfo *restrictinfo);
/***************************************************************************** /*****************************************************************************
@ -2212,10 +2212,10 @@ distribute_restrictinfo_to_rels(PlannerInfo *root,
/* /*
* Likewise, check if the clause is suitable to be used with a * Likewise, check if the clause is suitable to be used with a
* Result Cache node to cache inner tuples during a parameterized * Memoize node to cache inner tuples during a parameterized
* nested loop. * nested loop.
*/ */
check_resultcacheable(restrictinfo); check_memoizable(restrictinfo);
/* /*
* Add clause to the join lists of all the relevant relations. * Add clause to the join lists of all the relevant relations.
@ -2459,7 +2459,7 @@ build_implied_join_equality(PlannerInfo *root,
/* Set mergejoinability/hashjoinability flags */ /* Set mergejoinability/hashjoinability flags */
check_mergejoinable(restrictinfo); check_mergejoinable(restrictinfo);
check_hashjoinable(restrictinfo); check_hashjoinable(restrictinfo);
check_resultcacheable(restrictinfo); check_memoizable(restrictinfo);
return restrictinfo; return restrictinfo;
} }
@ -2709,13 +2709,13 @@ check_hashjoinable(RestrictInfo *restrictinfo)
} }
/* /*
* check_resultcacheable * check_memoizable
* If the restrictinfo's clause is suitable to be used for a Result Cache * If the restrictinfo's clause is suitable to be used for a Memoize node,
* node, set the hasheqoperator to the hash equality operator that will be * set the hasheqoperator to the hash equality operator that will be needed
* needed during caching. * during caching.
*/ */
static void static void
check_resultcacheable(RestrictInfo *restrictinfo) check_memoizable(RestrictInfo *restrictinfo)
{ {
TypeCacheEntry *typentry; TypeCacheEntry *typentry;
Expr *clause = restrictinfo->clause; Expr *clause = restrictinfo->clause;

View File

@ -752,19 +752,19 @@ set_plan_refs(PlannerInfo *root, Plan *plan, int rtoffset)
set_hash_references(root, plan, rtoffset); set_hash_references(root, plan, rtoffset);
break; break;
case T_ResultCache: case T_Memoize:
{ {
ResultCache *rcplan = (ResultCache *) plan; Memoize *mplan = (Memoize *) plan;
/* /*
* Result Cache does not evaluate its targetlist. It just * Memoize does not evaluate its targetlist. It just uses the
* uses the same targetlist from its outer subnode. * same targetlist from its outer subnode.
*/ */
set_dummy_tlist_references(plan, rtoffset); set_dummy_tlist_references(plan, rtoffset);
rcplan->param_exprs = fix_scan_list(root, rcplan->param_exprs, mplan->param_exprs = fix_scan_list(root, mplan->param_exprs,
rtoffset, rtoffset,
NUM_EXEC_TLIST(plan)); NUM_EXEC_TLIST(plan));
break; break;
} }

View File

@ -2745,8 +2745,8 @@ finalize_plan(PlannerInfo *root, Plan *plan,
/* rescan_param does *not* get added to scan_params */ /* rescan_param does *not* get added to scan_params */
break; break;
case T_ResultCache: case T_Memoize:
finalize_primnode((Node *) ((ResultCache *) plan)->param_exprs, finalize_primnode((Node *) ((Memoize *) plan)->param_exprs,
&context); &context);
break; break;

View File

@ -1577,20 +1577,19 @@ create_material_path(RelOptInfo *rel, Path *subpath)
} }
/* /*
* create_resultcache_path * create_memoize_path
* Creates a path corresponding to a ResultCache plan, returning the * Creates a path corresponding to a Memoize plan, returning the pathnode.
* pathnode.
*/ */
ResultCachePath * MemoizePath *
create_resultcache_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, create_memoize_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath,
List *param_exprs, List *hash_operators, List *param_exprs, List *hash_operators,
bool singlerow, double calls) bool singlerow, double calls)
{ {
ResultCachePath *pathnode = makeNode(ResultCachePath); MemoizePath *pathnode = makeNode(MemoizePath);
Assert(subpath->parent == rel); Assert(subpath->parent == rel);
pathnode->path.pathtype = T_ResultCache; pathnode->path.pathtype = T_Memoize;
pathnode->path.parent = rel; pathnode->path.parent = rel;
pathnode->path.pathtarget = rel->reltarget; pathnode->path.pathtarget = rel->reltarget;
pathnode->path.param_info = subpath->param_info; pathnode->path.param_info = subpath->param_info;
@ -1607,17 +1606,16 @@ create_resultcache_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath,
pathnode->calls = calls; pathnode->calls = calls;
/* /*
* For now we set est_entries to 0. cost_resultcache_rescan() does all * For now we set est_entries to 0. cost_memoize_rescan() does all the
* the hard work to determine how many cache entries there are likely to * hard work to determine how many cache entries there are likely to be,
* be, so it seems best to leave it up to that function to fill this field * so it seems best to leave it up to that function to fill this field in.
* in. If left at 0, the executor will make a guess at a good value. * If left at 0, the executor will make a guess at a good value.
*/ */
pathnode->est_entries = 0; pathnode->est_entries = 0;
/* /*
* Add a small additional charge for caching the first entry. All the * Add a small additional charge for caching the first entry. All the
* harder calculations for rescans are performed in * harder calculations for rescans are performed in cost_memoize_rescan().
* cost_resultcache_rescan().
*/ */
pathnode->path.startup_cost = subpath->startup_cost + cpu_tuple_cost; pathnode->path.startup_cost = subpath->startup_cost + cpu_tuple_cost;
pathnode->path.total_cost = subpath->total_cost + cpu_tuple_cost; pathnode->path.total_cost = subpath->total_cost + cpu_tuple_cost;
@ -3936,16 +3934,16 @@ reparameterize_path(PlannerInfo *root, Path *path,
apath->path.parallel_aware, apath->path.parallel_aware,
-1); -1);
} }
case T_ResultCache: case T_Memoize:
{ {
ResultCachePath *rcpath = (ResultCachePath *) path; MemoizePath *mpath = (MemoizePath *) path;
return (Path *) create_resultcache_path(root, rel, return (Path *) create_memoize_path(root, rel,
rcpath->subpath, mpath->subpath,
rcpath->param_exprs, mpath->param_exprs,
rcpath->hash_operators, mpath->hash_operators,
rcpath->singlerow, mpath->singlerow,
rcpath->calls); mpath->calls);
} }
default: default:
break; break;
@ -4165,13 +4163,13 @@ do { \
} }
break; break;
case T_ResultCachePath: case T_MemoizePath:
{ {
ResultCachePath *rcpath; MemoizePath *mpath;
FLAT_COPY_PATH(rcpath, path, ResultCachePath); FLAT_COPY_PATH(mpath, path, MemoizePath);
REPARAMETERIZE_CHILD_PATH(rcpath->subpath); REPARAMETERIZE_CHILD_PATH(mpath->subpath);
new_path = (Path *) rcpath; new_path = (Path *) mpath;
} }
break; break;

View File

@ -1058,12 +1058,12 @@ static struct config_bool ConfigureNamesBool[] =
NULL, NULL, NULL NULL, NULL, NULL
}, },
{ {
{"enable_resultcache", PGC_USERSET, QUERY_TUNING_METHOD, {"enable_memoize", PGC_USERSET, QUERY_TUNING_METHOD,
gettext_noop("Enables the planner's use of result caching."), gettext_noop("Enables the planner's use of memoization."),
NULL, NULL,
GUC_EXPLAIN GUC_EXPLAIN
}, },
&enable_resultcache, &enable_memoize,
true, true,
NULL, NULL, NULL NULL, NULL, NULL
}, },

View File

@ -367,7 +367,7 @@
#enable_indexscan = on #enable_indexscan = on
#enable_indexonlyscan = on #enable_indexonlyscan = on
#enable_material = on #enable_material = on
#enable_resultcache = on #enable_memoize = on
#enable_mergejoin = on #enable_mergejoin = on
#enable_nestloop = on #enable_nestloop = on
#enable_parallel_append = on #enable_parallel_append = on

View File

@ -0,0 +1,32 @@
/*-------------------------------------------------------------------------
*
* nodeMemoize.h
*
*
*
* Portions Copyright (c) 2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/executor/nodeMemoize.h
*
*-------------------------------------------------------------------------
*/
#ifndef NODEMEMOIZE_H
#define NODEMEMOIZE_H
#include "access/parallel.h"
#include "nodes/execnodes.h"
extern MemoizeState *ExecInitMemoize(Memoize *node, EState *estate, int eflags);
extern void ExecEndMemoize(MemoizeState *node);
extern void ExecReScanMemoize(MemoizeState *node);
extern double ExecEstimateCacheEntryOverheadBytes(double ntuples);
extern void ExecMemoizeEstimate(MemoizeState *node,
ParallelContext *pcxt);
extern void ExecMemoizeInitializeDSM(MemoizeState *node,
ParallelContext *pcxt);
extern void ExecMemoizeInitializeWorker(MemoizeState *node,
ParallelWorkerContext *pwcxt);
extern void ExecMemoizeRetrieveInstrumentation(MemoizeState *node);
#endif /* NODEMEMOIZE_H */

View File

@ -1,32 +0,0 @@
/*-------------------------------------------------------------------------
*
* nodeResultCache.h
*
*
*
* Portions Copyright (c) 2021, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* src/include/executor/nodeResultCache.h
*
*-------------------------------------------------------------------------
*/
#ifndef NODERESULTCACHE_H
#define NODERESULTCACHE_H
#include "access/parallel.h"
#include "nodes/execnodes.h"
extern ResultCacheState *ExecInitResultCache(ResultCache *node, EState *estate, int eflags);
extern void ExecEndResultCache(ResultCacheState *node);
extern void ExecReScanResultCache(ResultCacheState *node);
extern double ExecEstimateCacheEntryOverheadBytes(double ntuples);
extern void ExecResultCacheEstimate(ResultCacheState *node,
ParallelContext *pcxt);
extern void ExecResultCacheInitializeDSM(ResultCacheState *node,
ParallelContext *pcxt);
extern void ExecResultCacheInitializeWorker(ResultCacheState *node,
ParallelWorkerContext *pwcxt);
extern void ExecResultCacheRetrieveInstrumentation(ResultCacheState *node);
#endif /* NODERESULTCACHE_H */

View File

@ -2046,11 +2046,11 @@ typedef struct MaterialState
Tuplestorestate *tuplestorestate; Tuplestorestate *tuplestorestate;
} MaterialState; } MaterialState;
struct ResultCacheEntry; struct MemoizeEntry;
struct ResultCacheTuple; struct MemoizeTuple;
struct ResultCacheKey; struct MemoizeKey;
typedef struct ResultCacheInstrumentation typedef struct MemoizeInstrumentation
{ {
uint64 cache_hits; /* number of rescans where we've found the uint64 cache_hits; /* number of rescans where we've found the
* scan parameter values to be cached */ * scan parameter values to be cached */
@ -2063,31 +2063,31 @@ typedef struct ResultCacheInstrumentation
* able to free enough space to store the * able to free enough space to store the
* current scan's tuples. */ * current scan's tuples. */
uint64 mem_peak; /* peak memory usage in bytes */ uint64 mem_peak; /* peak memory usage in bytes */
} ResultCacheInstrumentation; } MemoizeInstrumentation;
/* ---------------- /* ----------------
* Shared memory container for per-worker resultcache information * Shared memory container for per-worker memoize information
* ---------------- * ----------------
*/ */
typedef struct SharedResultCacheInfo typedef struct SharedMemoizeInfo
{ {
int num_workers; int num_workers;
ResultCacheInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]; MemoizeInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER];
} SharedResultCacheInfo; } SharedMemoizeInfo;
/* ---------------- /* ----------------
* ResultCacheState information * MemoizeState information
* *
* resultcache nodes are used to cache recent and commonly seen results * memoize nodes are used to cache recent and commonly seen results from
* from a parameterized scan. * a parameterized scan.
* ---------------- * ----------------
*/ */
typedef struct ResultCacheState typedef struct MemoizeState
{ {
ScanState ss; /* its first field is NodeTag */ ScanState ss; /* its first field is NodeTag */
int rc_status; /* value of ExecResultCache state machine */ int mstatus; /* value of ExecMemoize state machine */
int nkeys; /* number of cache keys */ int nkeys; /* number of cache keys */
struct resultcache_hash *hashtable; /* hash table for cache entries */ struct memoize_hash *hashtable; /* hash table for cache entries */
TupleDesc hashkeydesc; /* tuple descriptor for cache keys */ TupleDesc hashkeydesc; /* tuple descriptor for cache keys */
TupleTableSlot *tableslot; /* min tuple slot for existing cache entries */ TupleTableSlot *tableslot; /* min tuple slot for existing cache entries */
TupleTableSlot *probeslot; /* virtual slot used for hash lookups */ TupleTableSlot *probeslot; /* virtual slot used for hash lookups */
@ -2100,17 +2100,17 @@ typedef struct ResultCacheState
uint64 mem_limit; /* memory limit in bytes for the cache */ uint64 mem_limit; /* memory limit in bytes for the cache */
MemoryContext tableContext; /* memory context to store cache data */ MemoryContext tableContext; /* memory context to store cache data */
dlist_head lru_list; /* least recently used entry list */ dlist_head lru_list; /* least recently used entry list */
struct ResultCacheTuple *last_tuple; /* Used to point to the last tuple struct MemoizeTuple *last_tuple; /* Used to point to the last tuple
* returned during a cache hit and * returned during a cache hit and the
* the tuple we last stored when * tuple we last stored when
* populating the cache. */ * populating the cache. */
struct ResultCacheEntry *entry; /* the entry that 'last_tuple' belongs to struct MemoizeEntry *entry; /* the entry that 'last_tuple' belongs to or
* or NULL if 'last_tuple' is NULL. */ * NULL if 'last_tuple' is NULL. */
bool singlerow; /* true if the cache entry is to be marked as bool singlerow; /* true if the cache entry is to be marked as
* complete after caching the first tuple. */ * complete after caching the first tuple. */
ResultCacheInstrumentation stats; /* execution statistics */ MemoizeInstrumentation stats; /* execution statistics */
SharedResultCacheInfo *shared_info; /* statistics for parallel workers */ SharedMemoizeInfo *shared_info; /* statistics for parallel workers */
} ResultCacheState; } MemoizeState;
/* ---------------- /* ----------------
* When performing sorting by multiple keys, it's possible that the input * When performing sorting by multiple keys, it's possible that the input

View File

@ -74,7 +74,7 @@ typedef enum NodeTag
T_MergeJoin, T_MergeJoin,
T_HashJoin, T_HashJoin,
T_Material, T_Material,
T_ResultCache, T_Memoize,
T_Sort, T_Sort,
T_IncrementalSort, T_IncrementalSort,
T_Group, T_Group,
@ -133,7 +133,7 @@ typedef enum NodeTag
T_MergeJoinState, T_MergeJoinState,
T_HashJoinState, T_HashJoinState,
T_MaterialState, T_MaterialState,
T_ResultCacheState, T_MemoizeState,
T_SortState, T_SortState,
T_IncrementalSortState, T_IncrementalSortState,
T_GroupState, T_GroupState,
@ -244,7 +244,7 @@ typedef enum NodeTag
T_MergeAppendPath, T_MergeAppendPath,
T_GroupResultPath, T_GroupResultPath,
T_MaterialPath, T_MaterialPath,
T_ResultCachePath, T_MemoizePath,
T_UniquePath, T_UniquePath,
T_GatherPath, T_GatherPath,
T_GatherMergePath, T_GatherMergePath,

View File

@ -1495,11 +1495,11 @@ typedef struct MaterialPath
} MaterialPath; } MaterialPath;
/* /*
* ResultCachePath represents a ResultCache plan node, i.e., a cache that * MemoizePath represents a Memoize plan node, i.e., a cache that caches
* caches tuples from parameterized paths to save the underlying node from * tuples from parameterized paths to save the underlying node from having to
* having to be rescanned for parameter values which are already cached. * be rescanned for parameter values which are already cached.
*/ */
typedef struct ResultCachePath typedef struct MemoizePath
{ {
Path path; Path path;
Path *subpath; /* outerpath to cache tuples from */ Path *subpath; /* outerpath to cache tuples from */
@ -1511,7 +1511,7 @@ typedef struct ResultCachePath
uint32 est_entries; /* The maximum number of entries that the uint32 est_entries; /* The maximum number of entries that the
* planner expects will fit in the cache, or 0 * planner expects will fit in the cache, or 0
* if unknown */ * if unknown */
} ResultCachePath; } MemoizePath;
/* /*
* UniquePath represents elimination of distinct rows from the output of * UniquePath represents elimination of distinct rows from the output of
@ -2111,7 +2111,7 @@ typedef struct RestrictInfo
Selectivity left_mcvfreq; /* left side's most common val's freq */ Selectivity left_mcvfreq; /* left side's most common val's freq */
Selectivity right_mcvfreq; /* right side's most common val's freq */ Selectivity right_mcvfreq; /* right side's most common val's freq */
/* hash equality operator used for result cache, else InvalidOid */ /* hash equality operator used for memoize nodes, else InvalidOid */
Oid hasheqoperator; Oid hasheqoperator;
} RestrictInfo; } RestrictInfo;

View File

@ -781,10 +781,10 @@ typedef struct Material
} Material; } Material;
/* ---------------- /* ----------------
* result cache node * memoize node
* ---------------- * ----------------
*/ */
typedef struct ResultCache typedef struct Memoize
{ {
Plan plan; Plan plan;
@ -799,7 +799,7 @@ typedef struct ResultCache
uint32 est_entries; /* The maximum number of entries that the uint32 est_entries; /* The maximum number of entries that the
* planner expects will fit in the cache, or 0 * planner expects will fit in the cache, or 0
* if unknown */ * if unknown */
} ResultCache; } Memoize;
/* ---------------- /* ----------------
* sort node * sort node

View File

@ -57,7 +57,7 @@ extern PGDLLIMPORT bool enable_incremental_sort;
extern PGDLLIMPORT bool enable_hashagg; extern PGDLLIMPORT bool enable_hashagg;
extern PGDLLIMPORT bool enable_nestloop; extern PGDLLIMPORT bool enable_nestloop;
extern PGDLLIMPORT bool enable_material; extern PGDLLIMPORT bool enable_material;
extern PGDLLIMPORT bool enable_resultcache; extern PGDLLIMPORT bool enable_memoize;
extern PGDLLIMPORT bool enable_mergejoin; extern PGDLLIMPORT bool enable_mergejoin;
extern PGDLLIMPORT bool enable_hashjoin; extern PGDLLIMPORT bool enable_hashjoin;
extern PGDLLIMPORT bool enable_gathermerge; extern PGDLLIMPORT bool enable_gathermerge;

View File

@ -82,13 +82,13 @@ extern GroupResultPath *create_group_result_path(PlannerInfo *root,
PathTarget *target, PathTarget *target,
List *havingqual); List *havingqual);
extern MaterialPath *create_material_path(RelOptInfo *rel, Path *subpath); extern MaterialPath *create_material_path(RelOptInfo *rel, Path *subpath);
extern ResultCachePath *create_resultcache_path(PlannerInfo *root, extern MemoizePath *create_memoize_path(PlannerInfo *root,
RelOptInfo *rel, RelOptInfo *rel,
Path *subpath, Path *subpath,
List *param_exprs, List *param_exprs,
List *hash_operators, List *hash_operators,
bool singlerow, bool singlerow,
double calls); double calls);
extern UniquePath *create_unique_path(PlannerInfo *root, RelOptInfo *rel, extern UniquePath *create_unique_path(PlannerInfo *root, RelOptInfo *rel,
Path *subpath, SpecialJoinInfo *sjinfo); Path *subpath, SpecialJoinInfo *sjinfo);
extern GatherPath *create_gather_path(PlannerInfo *root, extern GatherPath *create_gather_path(PlannerInfo *root,

View File

@ -2584,7 +2584,7 @@ select v||'a', case when v||'a' = 'aa' then 1 else 0 end, count(*)
-- Make sure that generation of HashAggregate for uniqification purposes -- Make sure that generation of HashAggregate for uniqification purposes
-- does not lead to array overflow due to unexpected duplicate hash keys -- does not lead to array overflow due to unexpected duplicate hash keys
-- see CAFeeJoKKu0u+A_A9R9316djW-YW3-+Gtgvy3ju655qRHR3jtdA@mail.gmail.com -- see CAFeeJoKKu0u+A_A9R9316djW-YW3-+Gtgvy3ju655qRHR3jtdA@mail.gmail.com
set enable_resultcache to off; set enable_memoize to off;
explain (costs off) explain (costs off)
select 1 from tenk1 select 1 from tenk1
where (hundred, thousand) in (select twothousand, twothousand from onek); where (hundred, thousand) in (select twothousand, twothousand from onek);
@ -2600,7 +2600,7 @@ explain (costs off)
-> Seq Scan on onek -> Seq Scan on onek
(8 rows) (8 rows)
reset enable_resultcache; reset enable_memoize;
-- --
-- Hash Aggregation Spill tests -- Hash Aggregation Spill tests
-- --

View File

@ -2536,7 +2536,7 @@ reset enable_nestloop;
-- --
set work_mem to '64kB'; set work_mem to '64kB';
set enable_mergejoin to off; set enable_mergejoin to off;
set enable_resultcache to off; set enable_memoize to off;
explain (costs off) explain (costs off)
select count(*) from tenk1 a, tenk1 b select count(*) from tenk1 a, tenk1 b
where a.hundred = b.thousand and (b.fivethous % 10) < 10; where a.hundred = b.thousand and (b.fivethous % 10) < 10;
@ -2560,7 +2560,7 @@ select count(*) from tenk1 a, tenk1 b
reset work_mem; reset work_mem;
reset enable_mergejoin; reset enable_mergejoin;
reset enable_resultcache; reset enable_memoize;
-- --
-- regression test for 8.2 bug with improper re-ordering of left joins -- regression test for 8.2 bug with improper re-ordering of left joins
-- --
@ -3684,7 +3684,7 @@ where t1.unique1 = 1;
Recheck Cond: (t1.hundred = hundred) Recheck Cond: (t1.hundred = hundred)
-> Bitmap Index Scan on tenk1_hundred -> Bitmap Index Scan on tenk1_hundred
Index Cond: (hundred = t1.hundred) Index Cond: (hundred = t1.hundred)
-> Result Cache -> Memoize
Cache Key: t2.thousand Cache Key: t2.thousand
-> Index Scan using tenk1_unique2 on tenk1 t3 -> Index Scan using tenk1_unique2 on tenk1 t3
Index Cond: (unique2 = t2.thousand) Index Cond: (unique2 = t2.thousand)
@ -3706,7 +3706,7 @@ where t1.unique1 = 1;
Recheck Cond: (t1.hundred = hundred) Recheck Cond: (t1.hundred = hundred)
-> Bitmap Index Scan on tenk1_hundred -> Bitmap Index Scan on tenk1_hundred
Index Cond: (hundred = t1.hundred) Index Cond: (hundred = t1.hundred)
-> Result Cache -> Memoize
Cache Key: t2.thousand Cache Key: t2.thousand
-> Index Scan using tenk1_unique2 on tenk1 t3 -> Index Scan using tenk1_unique2 on tenk1 t3
Index Cond: (unique2 = t2.thousand) Index Cond: (unique2 = t2.thousand)
@ -4235,7 +4235,7 @@ where t1.f1 = ss.f1;
-> Seq Scan on public.int8_tbl i8 -> Seq Scan on public.int8_tbl i8
Output: i8.q1, i8.q2 Output: i8.q1, i8.q2
Filter: (i8.q2 = 123) Filter: (i8.q2 = 123)
-> Result Cache -> Memoize
Output: (i8.q1), t2.f1 Output: (i8.q1), t2.f1
Cache Key: i8.q1 Cache Key: i8.q1
-> Limit -> Limit
@ -4279,14 +4279,14 @@ where t1.f1 = ss2.f1;
-> Seq Scan on public.int8_tbl i8 -> Seq Scan on public.int8_tbl i8
Output: i8.q1, i8.q2 Output: i8.q1, i8.q2
Filter: (i8.q2 = 123) Filter: (i8.q2 = 123)
-> Result Cache -> Memoize
Output: (i8.q1), t2.f1 Output: (i8.q1), t2.f1
Cache Key: i8.q1 Cache Key: i8.q1
-> Limit -> Limit
Output: (i8.q1), t2.f1 Output: (i8.q1), t2.f1
-> Seq Scan on public.text_tbl t2 -> Seq Scan on public.text_tbl t2
Output: i8.q1, t2.f1 Output: i8.q1, t2.f1
-> Result Cache -> Memoize
Output: ((i8.q1)), (t2.f1) Output: ((i8.q1)), (t2.f1)
Cache Key: (i8.q1), t2.f1 Cache Key: (i8.q1), t2.f1
-> Limit -> Limit
@ -4339,7 +4339,7 @@ where tt1.f1 = ss1.c0;
-> Seq Scan on public.text_tbl tt4 -> Seq Scan on public.text_tbl tt4
Output: tt4.f1 Output: tt4.f1
Filter: (tt4.f1 = 'foo'::text) Filter: (tt4.f1 = 'foo'::text)
-> Result Cache -> Memoize
Output: ss1.c0 Output: ss1.c0
Cache Key: tt4.f1 Cache Key: tt4.f1
-> Subquery Scan on ss1 -> Subquery Scan on ss1
@ -5028,7 +5028,7 @@ explain (costs off)
Aggregate Aggregate
-> Nested Loop -> Nested Loop
-> Seq Scan on tenk1 a -> Seq Scan on tenk1 a
-> Result Cache -> Memoize
Cache Key: a.two Cache Key: a.two
-> Function Scan on generate_series g -> Function Scan on generate_series g
(6 rows) (6 rows)
@ -5040,7 +5040,7 @@ explain (costs off)
Aggregate Aggregate
-> Nested Loop -> Nested Loop
-> Seq Scan on tenk1 a -> Seq Scan on tenk1 a
-> Result Cache -> Memoize
Cache Key: a.two Cache Key: a.two
-> Function Scan on generate_series g -> Function Scan on generate_series g
(6 rows) (6 rows)
@ -5053,7 +5053,7 @@ explain (costs off)
Aggregate Aggregate
-> Nested Loop -> Nested Loop
-> Seq Scan on tenk1 a -> Seq Scan on tenk1 a
-> Result Cache -> Memoize
Cache Key: a.two Cache Key: a.two
-> Function Scan on generate_series g -> Function Scan on generate_series g
(6 rows) (6 rows)
@ -5115,7 +5115,7 @@ explain (costs off)
-> Nested Loop -> Nested Loop
-> Index Only Scan using tenk1_unique1 on tenk1 a -> Index Only Scan using tenk1_unique1 on tenk1 a
-> Values Scan on "*VALUES*" -> Values Scan on "*VALUES*"
-> Result Cache -> Memoize
Cache Key: "*VALUES*".column1 Cache Key: "*VALUES*".column1
-> Index Only Scan using tenk1_unique2 on tenk1 b -> Index Only Scan using tenk1_unique2 on tenk1 b
Index Cond: (unique2 = "*VALUES*".column1) Index Cond: (unique2 = "*VALUES*".column1)

View File

@ -1,9 +1,9 @@
-- Perform tests on the Result Cache node. -- Perform tests on the Memoize node.
-- The cache hits/misses/evictions from the Result Cache node can vary between -- The cache hits/misses/evictions from the Memoize node can vary between
-- machines. Let's just replace the number with an 'N'. In order to allow us -- machines. Let's just replace the number with an 'N'. In order to allow us
-- to perform validation when the measure was zero, we replace a zero value -- to perform validation when the measure was zero, we replace a zero value
-- with "Zero". All other numbers are replaced with 'N'. -- with "Zero". All other numbers are replaced with 'N'.
create function explain_resultcache(query text, hide_hitmiss bool) returns setof text create function explain_memoize(query text, hide_hitmiss bool) returns setof text
language plpgsql as language plpgsql as
$$ $$
declare declare
@ -28,21 +28,21 @@ begin
end loop; end loop;
end; end;
$$; $$;
-- Ensure we get a result cache on the inner side of the nested loop -- Ensure we get a memoize node on the inner side of the nested loop
SET enable_hashjoin TO off; SET enable_hashjoin TO off;
SET enable_bitmapscan TO off; SET enable_bitmapscan TO off;
SELECT explain_resultcache(' SELECT explain_memoize('
SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1
INNER JOIN tenk1 t2 ON t1.unique1 = t2.twenty INNER JOIN tenk1 t2 ON t1.unique1 = t2.twenty
WHERE t2.unique1 < 1000;', false); WHERE t2.unique1 < 1000;', false);
explain_resultcache explain_memoize
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
Aggregate (actual rows=1 loops=N) Aggregate (actual rows=1 loops=N)
-> Nested Loop (actual rows=1000 loops=N) -> Nested Loop (actual rows=1000 loops=N)
-> Seq Scan on tenk1 t2 (actual rows=1000 loops=N) -> Seq Scan on tenk1 t2 (actual rows=1000 loops=N)
Filter: (unique1 < 1000) Filter: (unique1 < 1000)
Rows Removed by Filter: 9000 Rows Removed by Filter: 9000
-> Result Cache (actual rows=1 loops=N) -> Memoize (actual rows=1 loops=N)
Cache Key: t2.twenty Cache Key: t2.twenty
Hits: 980 Misses: 20 Evictions: Zero Overflows: 0 Memory Usage: NkB Hits: 980 Misses: 20 Evictions: Zero Overflows: 0 Memory Usage: NkB
-> Index Only Scan using tenk1_unique1 on tenk1 t1 (actual rows=1 loops=N) -> Index Only Scan using tenk1_unique1 on tenk1 t1 (actual rows=1 loops=N)
@ -60,18 +60,18 @@ WHERE t2.unique1 < 1000;
(1 row) (1 row)
-- Try with LATERAL joins -- Try with LATERAL joins
SELECT explain_resultcache(' SELECT explain_memoize('
SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1, SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2 LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2
WHERE t1.unique1 < 1000;', false); WHERE t1.unique1 < 1000;', false);
explain_resultcache explain_memoize
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
Aggregate (actual rows=1 loops=N) Aggregate (actual rows=1 loops=N)
-> Nested Loop (actual rows=1000 loops=N) -> Nested Loop (actual rows=1000 loops=N)
-> Seq Scan on tenk1 t1 (actual rows=1000 loops=N) -> Seq Scan on tenk1 t1 (actual rows=1000 loops=N)
Filter: (unique1 < 1000) Filter: (unique1 < 1000)
Rows Removed by Filter: 9000 Rows Removed by Filter: 9000
-> Result Cache (actual rows=1 loops=N) -> Memoize (actual rows=1 loops=N)
Cache Key: t1.twenty Cache Key: t1.twenty
Hits: 980 Misses: 20 Evictions: Zero Overflows: 0 Memory Usage: NkB Hits: 980 Misses: 20 Evictions: Zero Overflows: 0 Memory Usage: NkB
-> Index Only Scan using tenk1_unique1 on tenk1 t2 (actual rows=1 loops=N) -> Index Only Scan using tenk1_unique1 on tenk1 t2 (actual rows=1 loops=N)
@ -94,18 +94,18 @@ SET enable_mergejoin TO off;
-- Ensure we get some evictions. We're unable to validate the hits and misses -- Ensure we get some evictions. We're unable to validate the hits and misses
-- here as the number of entries that fit in the cache at once will vary -- here as the number of entries that fit in the cache at once will vary
-- between different machines. -- between different machines.
SELECT explain_resultcache(' SELECT explain_memoize('
SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1
INNER JOIN tenk1 t2 ON t1.unique1 = t2.thousand INNER JOIN tenk1 t2 ON t1.unique1 = t2.thousand
WHERE t2.unique1 < 1200;', true); WHERE t2.unique1 < 1200;', true);
explain_resultcache explain_memoize
------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------
Aggregate (actual rows=1 loops=N) Aggregate (actual rows=1 loops=N)
-> Nested Loop (actual rows=1200 loops=N) -> Nested Loop (actual rows=1200 loops=N)
-> Seq Scan on tenk1 t2 (actual rows=1200 loops=N) -> Seq Scan on tenk1 t2 (actual rows=1200 loops=N)
Filter: (unique1 < 1200) Filter: (unique1 < 1200)
Rows Removed by Filter: 8800 Rows Removed by Filter: 8800
-> Result Cache (actual rows=1 loops=N) -> Memoize (actual rows=1 loops=N)
Cache Key: t2.thousand Cache Key: t2.thousand
Hits: N Misses: N Evictions: N Overflows: 0 Memory Usage: NkB Hits: N Misses: N Evictions: N Overflows: 0 Memory Usage: NkB
-> Index Only Scan using tenk1_unique1 on tenk1 t1 (actual rows=1 loops=N) -> Index Only Scan using tenk1_unique1 on tenk1 t1 (actual rows=1 loops=N)
@ -117,7 +117,7 @@ RESET enable_mergejoin;
RESET work_mem; RESET work_mem;
RESET enable_bitmapscan; RESET enable_bitmapscan;
RESET enable_hashjoin; RESET enable_hashjoin;
-- Test parallel plans with Result Cache. -- Test parallel plans with Memoize
SET min_parallel_table_scan_size TO 0; SET min_parallel_table_scan_size TO 0;
SET parallel_setup_cost TO 0; SET parallel_setup_cost TO 0;
SET parallel_tuple_cost TO 0; SET parallel_tuple_cost TO 0;
@ -138,7 +138,7 @@ WHERE t1.unique1 < 1000;
Recheck Cond: (unique1 < 1000) Recheck Cond: (unique1 < 1000)
-> Bitmap Index Scan on tenk1_unique1 -> Bitmap Index Scan on tenk1_unique1
Index Cond: (unique1 < 1000) Index Cond: (unique1 < 1000)
-> Result Cache -> Memoize
Cache Key: t1.twenty Cache Key: t1.twenty
-> Index Only Scan using tenk1_unique1 on tenk1 t2 -> Index Only Scan using tenk1_unique1 on tenk1 t2
Index Cond: (unique1 = t1.twenty) Index Cond: (unique1 = t1.twenty)

View File

@ -2085,7 +2085,7 @@ create index ab_a3_b2_a_idx on ab_a3_b2 (a);
create index ab_a3_b3_a_idx on ab_a3_b3 (a); create index ab_a3_b3_a_idx on ab_a3_b3 (a);
set enable_hashjoin = 0; set enable_hashjoin = 0;
set enable_mergejoin = 0; set enable_mergejoin = 0;
set enable_resultcache = 0; set enable_memoize = 0;
select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in(0, 0, 1)'); select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in(0, 0, 1)');
explain_parallel_append explain_parallel_append
-------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------
@ -2254,7 +2254,7 @@ select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on
reset enable_hashjoin; reset enable_hashjoin;
reset enable_mergejoin; reset enable_mergejoin;
reset enable_resultcache; reset enable_memoize;
reset parallel_setup_cost; reset parallel_setup_cost;
reset parallel_tuple_cost; reset parallel_tuple_cost;
reset min_parallel_table_scan_size; reset min_parallel_table_scan_size;

View File

@ -1097,7 +1097,7 @@ where o.ten = 1;
-> Nested Loop -> Nested Loop
-> Seq Scan on onek o -> Seq Scan on onek o
Filter: (ten = 1) Filter: (ten = 1)
-> Result Cache -> Memoize
Cache Key: o.four Cache Key: o.four
-> CTE Scan on x -> CTE Scan on x
CTE x CTE x

View File

@ -104,6 +104,7 @@ select name, setting from pg_settings where name like 'enable%';
enable_indexonlyscan | on enable_indexonlyscan | on
enable_indexscan | on enable_indexscan | on
enable_material | on enable_material | on
enable_memoize | on
enable_mergejoin | on enable_mergejoin | on
enable_nestloop | on enable_nestloop | on
enable_parallel_append | on enable_parallel_append | on
@ -111,7 +112,6 @@ select name, setting from pg_settings where name like 'enable%';
enable_partition_pruning | on enable_partition_pruning | on
enable_partitionwise_aggregate | off enable_partitionwise_aggregate | off
enable_partitionwise_join | off enable_partitionwise_join | off
enable_resultcache | on
enable_seqscan | on enable_seqscan | on
enable_sort | on enable_sort | on
enable_tidscan | on enable_tidscan | on

View File

@ -120,7 +120,7 @@ test: plancache limit plpgsql copy2 temp domain rangefuncs prepare conversion tr
# ---------- # ----------
# Another group of parallel tests # Another group of parallel tests
# ---------- # ----------
test: partition_join partition_prune reloptions hash_part indexing partition_aggregate partition_info tuplesort explain compression resultcache test: partition_join partition_prune reloptions hash_part indexing partition_aggregate partition_info tuplesort explain compression memoize
# event triggers cannot run concurrently with any test that runs DDL # event triggers cannot run concurrently with any test that runs DDL
# oidjoins is read-only, though, and should run late for best coverage # oidjoins is read-only, though, and should run late for best coverage

View File

@ -1098,11 +1098,11 @@ select v||'a', case when v||'a' = 'aa' then 1 else 0 end, count(*)
-- Make sure that generation of HashAggregate for uniqification purposes -- Make sure that generation of HashAggregate for uniqification purposes
-- does not lead to array overflow due to unexpected duplicate hash keys -- does not lead to array overflow due to unexpected duplicate hash keys
-- see CAFeeJoKKu0u+A_A9R9316djW-YW3-+Gtgvy3ju655qRHR3jtdA@mail.gmail.com -- see CAFeeJoKKu0u+A_A9R9316djW-YW3-+Gtgvy3ju655qRHR3jtdA@mail.gmail.com
set enable_resultcache to off; set enable_memoize to off;
explain (costs off) explain (costs off)
select 1 from tenk1 select 1 from tenk1
where (hundred, thousand) in (select twothousand, twothousand from onek); where (hundred, thousand) in (select twothousand, twothousand from onek);
reset enable_resultcache; reset enable_memoize;
-- --
-- Hash Aggregation Spill tests -- Hash Aggregation Spill tests

View File

@ -550,7 +550,7 @@ reset enable_nestloop;
set work_mem to '64kB'; set work_mem to '64kB';
set enable_mergejoin to off; set enable_mergejoin to off;
set enable_resultcache to off; set enable_memoize to off;
explain (costs off) explain (costs off)
select count(*) from tenk1 a, tenk1 b select count(*) from tenk1 a, tenk1 b
@ -560,7 +560,7 @@ select count(*) from tenk1 a, tenk1 b
reset work_mem; reset work_mem;
reset enable_mergejoin; reset enable_mergejoin;
reset enable_resultcache; reset enable_memoize;
-- --
-- regression test for 8.2 bug with improper re-ordering of left joins -- regression test for 8.2 bug with improper re-ordering of left joins

View File

@ -1,10 +1,10 @@
-- Perform tests on the Result Cache node. -- Perform tests on the Memoize node.
-- The cache hits/misses/evictions from the Result Cache node can vary between -- The cache hits/misses/evictions from the Memoize node can vary between
-- machines. Let's just replace the number with an 'N'. In order to allow us -- machines. Let's just replace the number with an 'N'. In order to allow us
-- to perform validation when the measure was zero, we replace a zero value -- to perform validation when the measure was zero, we replace a zero value
-- with "Zero". All other numbers are replaced with 'N'. -- with "Zero". All other numbers are replaced with 'N'.
create function explain_resultcache(query text, hide_hitmiss bool) returns setof text create function explain_memoize(query text, hide_hitmiss bool) returns setof text
language plpgsql as language plpgsql as
$$ $$
declare declare
@ -30,11 +30,11 @@ begin
end; end;
$$; $$;
-- Ensure we get a result cache on the inner side of the nested loop -- Ensure we get a memoize node on the inner side of the nested loop
SET enable_hashjoin TO off; SET enable_hashjoin TO off;
SET enable_bitmapscan TO off; SET enable_bitmapscan TO off;
SELECT explain_resultcache(' SELECT explain_memoize('
SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1
INNER JOIN tenk1 t2 ON t1.unique1 = t2.twenty INNER JOIN tenk1 t2 ON t1.unique1 = t2.twenty
WHERE t2.unique1 < 1000;', false); WHERE t2.unique1 < 1000;', false);
@ -45,7 +45,7 @@ INNER JOIN tenk1 t2 ON t1.unique1 = t2.twenty
WHERE t2.unique1 < 1000; WHERE t2.unique1 < 1000;
-- Try with LATERAL joins -- Try with LATERAL joins
SELECT explain_resultcache(' SELECT explain_memoize('
SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1, SELECT COUNT(*),AVG(t2.unique1) FROM tenk1 t1,
LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2 LATERAL (SELECT t2.unique1 FROM tenk1 t2 WHERE t1.twenty = t2.unique1) t2
WHERE t1.unique1 < 1000;', false); WHERE t1.unique1 < 1000;', false);
@ -61,7 +61,7 @@ SET enable_mergejoin TO off;
-- Ensure we get some evictions. We're unable to validate the hits and misses -- Ensure we get some evictions. We're unable to validate the hits and misses
-- here as the number of entries that fit in the cache at once will vary -- here as the number of entries that fit in the cache at once will vary
-- between different machines. -- between different machines.
SELECT explain_resultcache(' SELECT explain_memoize('
SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1 SELECT COUNT(*),AVG(t1.unique1) FROM tenk1 t1
INNER JOIN tenk1 t2 ON t1.unique1 = t2.thousand INNER JOIN tenk1 t2 ON t1.unique1 = t2.thousand
WHERE t2.unique1 < 1200;', true); WHERE t2.unique1 < 1200;', true);
@ -70,7 +70,7 @@ RESET work_mem;
RESET enable_bitmapscan; RESET enable_bitmapscan;
RESET enable_hashjoin; RESET enable_hashjoin;
-- Test parallel plans with Result Cache. -- Test parallel plans with Memoize
SET min_parallel_table_scan_size TO 0; SET min_parallel_table_scan_size TO 0;
SET parallel_setup_cost TO 0; SET parallel_setup_cost TO 0;
SET parallel_tuple_cost TO 0; SET parallel_tuple_cost TO 0;

View File

@ -515,7 +515,7 @@ create index ab_a3_b3_a_idx on ab_a3_b3 (a);
set enable_hashjoin = 0; set enable_hashjoin = 0;
set enable_mergejoin = 0; set enable_mergejoin = 0;
set enable_resultcache = 0; set enable_memoize = 0;
select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in(0, 0, 1)'); select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on ab.a = a.a where a.a in(0, 0, 1)');
@ -534,7 +534,7 @@ select explain_parallel_append('select avg(ab.a) from ab inner join lprt_a a on
reset enable_hashjoin; reset enable_hashjoin;
reset enable_mergejoin; reset enable_mergejoin;
reset enable_resultcache; reset enable_memoize;
reset parallel_setup_cost; reset parallel_setup_cost;
reset parallel_tuple_cost; reset parallel_tuple_cost;
reset min_parallel_table_scan_size; reset min_parallel_table_scan_size;

View File

@ -1421,6 +1421,13 @@ Material
MaterialPath MaterialPath
MaterialState MaterialState
MdfdVec MdfdVec
Memoize
MemoizeEntry
MemoizeInstrumentation
MemoizeKey
MemoizePath
MemoizeState
MemoizeTuple
MemoryContext MemoryContext
MemoryContextCallback MemoryContextCallback
MemoryContextCallbackFunction MemoryContextCallbackFunction
@ -2222,13 +2229,6 @@ RestoreOptions
RestorePass RestorePass
RestrictInfo RestrictInfo
Result Result
ResultCache
ResultCacheEntry
ResultCacheInstrumentation
ResultCacheKey
ResultCachePath
ResultCacheState
ResultCacheTuple
ResultRelInfo ResultRelInfo
ResultState ResultState
ReturnSetInfo ReturnSetInfo
@ -2384,10 +2384,10 @@ SharedInvalSmgrMsg
SharedInvalSnapshotMsg SharedInvalSnapshotMsg
SharedInvalidationMessage SharedInvalidationMessage
SharedJitInstrumentation SharedJitInstrumentation
SharedMemoizeInfo
SharedRecordTableEntry SharedRecordTableEntry
SharedRecordTableKey SharedRecordTableKey
SharedRecordTypmodRegistry SharedRecordTypmodRegistry
SharedResultCacheInfo
SharedSortInfo SharedSortInfo
SharedTuplestore SharedTuplestore
SharedTuplestoreAccessor SharedTuplestoreAccessor
@ -3272,6 +3272,8 @@ mbcharacter_incrementer
mbdisplaylen_converter mbdisplaylen_converter
mblen_converter mblen_converter
mbstr_verifier mbstr_verifier
memoize_hash
memoize_iterator
metastring metastring
mix_data_t mix_data_t
mixedStruct mixedStruct
@ -3478,8 +3480,6 @@ remoteDep
rendezvousHashEntry rendezvousHashEntry
replace_rte_variables_callback replace_rte_variables_callback
replace_rte_variables_context replace_rte_variables_context
resultcache_hash
resultcache_iterator
ret_type ret_type
rewind_source rewind_source
rewrite_event rewrite_event