Skip to content

Commit 62b3945

Browse files
committed
restore_selectivities: avoid links to restrictinfo selectivity field: it can be freed or changed externally
1 parent b3bb11f commit 62b3945

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

postprocessing.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ restore_selectivities(List *clauselist, List *relidslist, JoinType join_type,
176176
int nargs;
177177
int *args_hash;
178178
int *eclass_hash;
179-
double *cur_sel;
180179
int cur_hash;
181180
int cur_relid;
182181

@@ -191,30 +190,29 @@ restore_selectivities(List *clauselist, List *relidslist, JoinType join_type,
191190
foreach(l, clauselist)
192191
{
193192
RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
193+
Selectivity *cur_sel = NULL;
194194

195-
cur_sel = NULL;
196195
if (parametrized_sel)
197196
{
198197
cur_hash = get_clause_hash(rinfo->clause, nargs,
199198
args_hash, eclass_hash);
200199
cur_sel = selectivity_cache_find_global_relid(cur_hash, cur_relid);
201-
if (cur_sel == NULL)
202-
{
203-
if (join_type == JOIN_INNER)
204-
cur_sel = &rinfo->norm_selec;
205-
else
206-
cur_sel = &rinfo->outer_selec;
207-
}
208200
}
209-
else if (join_type == JOIN_INNER)
210-
cur_sel = &rinfo->norm_selec;
211-
else
212-
cur_sel = &rinfo->outer_selec;
213201

214-
if (*cur_sel < 0)
215-
*cur_sel = 0;
202+
if (cur_sel == NULL)
203+
{
204+
cur_sel = palloc(sizeof(double));
205+
206+
if (join_type == JOIN_INNER)
207+
*cur_sel = rinfo->norm_selec;
208+
else
209+
*cur_sel = rinfo->outer_selec;
210+
211+
if (*cur_sel < 0)
212+
*cur_sel = 0;
213+
}
216214

217-
Assert(cur_sel > 0);
215+
Assert(*cur_sel >= 0);
218216

219217
lst = lappend(lst, cur_sel);
220218
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy