Skip to content

Commit 7933bc0

Browse files
committed
Revert "Flush Memoize cache when non-key parameters change"
This reverts commit f94edb0.
1 parent f94edb0 commit 7933bc0

File tree

9 files changed

+3
-142
lines changed

9 files changed

+3
-142
lines changed

src/backend/executor/nodeMemoize.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -367,37 +367,6 @@ remove_cache_entry(MemoizeState *mstate, MemoizeEntry *entry)
367367
pfree(key);
368368
}
369369

370-
/*
371-
* cache_purge_all
372-
* Remove all items from the cache
373-
*/
374-
static void
375-
cache_purge_all(MemoizeState *mstate)
376-
{
377-
uint64 evictions = mstate->hashtable->members;
378-
PlanState *pstate = (PlanState *) mstate;
379-
380-
/*
381-
* Likely the most efficient way to remove all items is to just reset the
382-
* memory context for the cache and then rebuild a fresh hash table. This
383-
* saves having to remove each item one by one and pfree each cached tuple
384-
*/
385-
MemoryContextReset(mstate->tableContext);
386-
387-
/* Make the hash table the same size as the original size */
388-
build_hash_table(mstate, ((Memoize *) pstate->plan)->est_entries);
389-
390-
/* reset the LRU list */
391-
dlist_init(&mstate->lru_list);
392-
mstate->last_tuple = NULL;
393-
mstate->entry = NULL;
394-
395-
mstate->mem_used = 0;
396-
397-
/* XXX should we add something new to track these purges? */
398-
mstate->stats.cache_evictions += evictions; /* Update Stats */
399-
}
400-
401370
/*
402371
* cache_reduce_memory
403372
* Evict older and less recently used items from the cache in order to
@@ -1010,7 +979,6 @@ ExecInitMemoize(Memoize *node, EState *estate, int eflags)
1010979
* getting the first tuple. This allows us to mark it as so.
1011980
*/
1012981
mstate->singlerow = node->singlerow;
1013-
mstate->keyparamids = node->keyparamids;
1014982

1015983
/*
1016984
* Record if the cache keys should be compared bit by bit, or logically
@@ -1114,12 +1082,6 @@ ExecReScanMemoize(MemoizeState *node)
11141082
if (outerPlan->chgParam == NULL)
11151083
ExecReScan(outerPlan);
11161084

1117-
/*
1118-
* Purge the entire cache if a parameter changed that is not part of the
1119-
* cache key.
1120-
*/
1121-
if (bms_nonempty_difference(outerPlan->chgParam, node->keyparamids))
1122-
cache_purge_all(node);
11231085
}
11241086

11251087
/*

src/backend/nodes/bitmapset.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,6 @@ bms_overlap_list(const Bitmapset *a, const List *b)
540540

541541
/*
542542
* bms_nonempty_difference - do sets have a nonempty difference?
543-
*
544-
* i.e., are any members set in 'a' that are not also set in 'b'.
545543
*/
546544
bool
547545
bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)

src/backend/optimizer/plan/createplan.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ static Material *make_material(Plan *lefttree);
280280
static Memoize *make_memoize(Plan *lefttree, Oid *hashoperators,
281281
Oid *collations, List *param_exprs,
282282
bool singlerow, bool binary_mode,
283-
uint32 est_entries, Bitmapset *keyparamids);
283+
uint32 est_entries);
284284
static WindowAgg *make_windowagg(List *tlist, Index winref,
285285
int partNumCols, AttrNumber *partColIdx, Oid *partOperators, Oid *partCollations,
286286
int ordNumCols, AttrNumber *ordColIdx, Oid *ordOperators, Oid *ordCollations,
@@ -1586,7 +1586,6 @@ static Memoize *
15861586
create_memoize_plan(PlannerInfo *root, MemoizePath *best_path, int flags)
15871587
{
15881588
Memoize *plan;
1589-
Bitmapset *keyparamids;
15901589
Plan *subplan;
15911590
Oid *operators;
15921591
Oid *collations;
@@ -1618,11 +1617,9 @@ create_memoize_plan(PlannerInfo *root, MemoizePath *best_path, int flags)
16181617
i++;
16191618
}
16201619

1621-
keyparamids = pull_paramids((Expr *) param_exprs);
1622-
16231620
plan = make_memoize(subplan, operators, collations, param_exprs,
16241621
best_path->singlerow, best_path->binary_mode,
1625-
best_path->est_entries, keyparamids);
1622+
best_path->est_entries);
16261623

16271624
copy_generic_path_info(&plan->plan, (Path *) best_path);
16281625

@@ -6422,7 +6419,7 @@ materialize_finished_plan(Plan *subplan)
64226419
static Memoize *
64236420
make_memoize(Plan *lefttree, Oid *hashoperators, Oid *collations,
64246421
List *param_exprs, bool singlerow, bool binary_mode,
6425-
uint32 est_entries, Bitmapset *keyparamids)
6422+
uint32 est_entries)
64266423
{
64276424
Memoize *node = makeNode(Memoize);
64286425
Plan *plan = &node->plan;
@@ -6439,7 +6436,6 @@ make_memoize(Plan *lefttree, Oid *hashoperators, Oid *collations,
64396436
node->singlerow = singlerow;
64406437
node->binary_mode = binary_mode;
64416438
node->est_entries = est_entries;
6442-
node->keyparamids = keyparamids;
64436439

64446440
return node;
64456441
}

src/backend/optimizer/util/clauses.c

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ static Query *substitute_actual_srf_parameters(Query *expr,
152152
int nargs, List *args);
153153
static Node *substitute_actual_srf_parameters_mutator(Node *node,
154154
substitute_actual_srf_parameters_context *context);
155-
static bool pull_paramids_walker(Node *node, Bitmapset **context);
156155

157156

158157
/*****************************************************************************
@@ -5168,33 +5167,3 @@ substitute_actual_srf_parameters_mutator(Node *node,
51685167
substitute_actual_srf_parameters_mutator,
51695168
(void *) context);
51705169
}
5171-
5172-
/*
5173-
* pull_paramids
5174-
* Returns a Bitmapset containing the paramids of all Params in 'expr'.
5175-
*/
5176-
Bitmapset *
5177-
pull_paramids(Expr *expr)
5178-
{
5179-
Bitmapset *result = NULL;
5180-
5181-
(void) pull_paramids_walker((Node *) expr, &result);
5182-
5183-
return result;
5184-
}
5185-
5186-
static bool
5187-
pull_paramids_walker(Node *node, Bitmapset **context)
5188-
{
5189-
if (node == NULL)
5190-
return false;
5191-
if (IsA(node, Param))
5192-
{
5193-
Param *param = (Param *)node;
5194-
5195-
*context = bms_add_member(*context, param->paramid);
5196-
return false;
5197-
}
5198-
return expression_tree_walker(node, pull_paramids_walker,
5199-
(void *) context);
5200-
}

src/include/nodes/execnodes.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,8 +2112,6 @@ typedef struct MemoizeState
21122112
* by bit, false when using hash equality ops */
21132113
MemoizeInstrumentation stats; /* execution statistics */
21142114
SharedMemoizeInfo *shared_info; /* statistics for parallel workers */
2115-
Bitmapset *keyparamids; /* Param->paramids of expressions belonging to
2116-
* param_exprs */
21172115
} MemoizeState;
21182116

21192117
/* ----------------

src/include/nodes/plannodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,6 @@ typedef struct Memoize
801801
uint32 est_entries; /* The maximum number of entries that the
802802
* planner expects will fit in the cache, or 0
803803
* if unknown */
804-
Bitmapset *keyparamids; /* paramids from param_exprs */
805804
} Memoize;
806805

807806
/* ----------------

src/include/optimizer/clauses.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,4 @@ extern void CommuteOpExpr(OpExpr *clause);
5353
extern Query *inline_set_returning_function(PlannerInfo *root,
5454
RangeTblEntry *rte);
5555

56-
extern Bitmapset *pull_paramids(Expr *expr);
57-
5856
#endif /* CLAUSES_H */

src/test/regress/expected/memoize.out

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -196,45 +196,6 @@ SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.t >= s2.t;', false);
196196
(8 rows)
197197

198198
DROP TABLE strtest;
199-
-- Exercise Memoize code that flushes the cache when a parameter changes which
200-
-- is not part of the cache key.
201-
-- Ensure we get a Memoize plan
202-
EXPLAIN (COSTS OFF)
203-
SELECT UNIQUE1 FROM tenk1 t0
204-
WHERE unique1 < 3
205-
AND EXISTS (
206-
SELECT 1 FROM tenk1 t1
207-
INNER JOIN tenk2 t2 ON t1.unique1 = t2.hundred
208-
WHERE t0.ten = t1.twenty AND t0.two <> t2.four OFFSET 0);
209-
QUERY PLAN
210-
----------------------------------------------------------------
211-
Index Scan using tenk1_unique1 on tenk1 t0
212-
Index Cond: (unique1 < 3)
213-
Filter: (SubPlan 1)
214-
SubPlan 1
215-
-> Nested Loop
216-
-> Index Scan using tenk2_hundred on tenk2 t2
217-
Filter: (t0.two <> four)
218-
-> Memoize
219-
Cache Key: t2.hundred
220-
Cache Mode: logical
221-
-> Index Scan using tenk1_unique1 on tenk1 t1
222-
Index Cond: (unique1 = t2.hundred)
223-
Filter: (t0.ten = twenty)
224-
(13 rows)
225-
226-
-- Ensure the above query returns the correct result
227-
SELECT UNIQUE1 FROM tenk1 t0
228-
WHERE unique1 < 3
229-
AND EXISTS (
230-
SELECT 1 FROM tenk1 t1
231-
INNER JOIN tenk2 t2 ON t1.unique1 = t2.hundred
232-
WHERE t0.ten = t1.twenty AND t0.two <> t2.four OFFSET 0);
233-
unique1
234-
---------
235-
2
236-
(1 row)
237-
238199
RESET enable_seqscan;
239200
RESET enable_mergejoin;
240201
RESET work_mem;

src/test/regress/sql/memoize.sql

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,6 @@ SELECT * FROM strtest s1 INNER JOIN strtest s2 ON s1.t >= s2.t;', false);
103103

104104
DROP TABLE strtest;
105105

106-
-- Exercise Memoize code that flushes the cache when a parameter changes which
107-
-- is not part of the cache key.
108-
109-
-- Ensure we get a Memoize plan
110-
EXPLAIN (COSTS OFF)
111-
SELECT UNIQUE1 FROM tenk1 t0
112-
WHERE unique1 < 3
113-
AND EXISTS (
114-
SELECT 1 FROM tenk1 t1
115-
INNER JOIN tenk2 t2 ON t1.unique1 = t2.hundred
116-
WHERE t0.ten = t1.twenty AND t0.two <> t2.four OFFSET 0);
117-
118-
-- Ensure the above query returns the correct result
119-
SELECT UNIQUE1 FROM tenk1 t0
120-
WHERE unique1 < 3
121-
AND EXISTS (
122-
SELECT 1 FROM tenk1 t1
123-
INNER JOIN tenk2 t2 ON t1.unique1 = t2.hundred
124-
WHERE t0.ten = t1.twenty AND t0.two <> t2.four OFFSET 0);
125-
126106
RESET enable_seqscan;
127107
RESET enable_mergejoin;
128108
RESET work_mem;

0 commit comments

Comments
 (0)