Skip to content

Commit 2d224b6

Browse files
committed
refactoring, extract 'Relation parent_rel' from append_child_relation(), use list_free_deep() instead of list_free()
1 parent 275d5aa commit 2d224b6

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

src/hooks.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,22 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
209209
/* Proceed iff relation 'rel' is partitioned */
210210
if ((prel = get_pathman_relation_info(rte->relid)) != NULL)
211211
{
212-
ListCell *lc;
213-
Oid *children;
214-
List *ranges,
215-
*wrappers,
216-
*rel_part_clauses = NIL;
212+
Relation parent_rel; /* parent's relation (heap */
213+
Oid *children; /* selected children oids */
214+
List *ranges, /* a list of IndexRanges */
215+
*wrappers, /* a list of WrapperNodes */
216+
*rel_part_clauses = NIL; /* clauses with part. column */
217217
PathKey *pathkeyAsc = NULL,
218218
*pathkeyDesc = NULL;
219-
double paramsel = 1.0;
219+
double paramsel = 1.0; /* default part selectivity */
220220
WalkerContext context;
221+
ListCell *lc;
221222
int i;
222223

223224
if (prel->parttype == PT_RANGE)
224225
{
225226
/*
226-
* Get pathkeys for ascending and descending sort by partition
227-
* column
227+
* Get pathkeys for ascending and descending sort by partitioned column.
228228
*/
229229
List *pathkeys;
230230
Var *var;
@@ -273,13 +273,12 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
273273
ranges = irange_list_intersect(ranges, wrap->rangeset);
274274
}
275275

276-
/*
277-
* Expand simple_rte_array and simple_rel_array
278-
*/
276+
/* Get number of selected partitions */
279277
len = irange_list_length(ranges);
280278
if (prel->enable_parent)
281-
len++;
279+
len++; /* add parent too */
282280

281+
/* Expand simple_rte_array and simple_rel_array */
283282
if (len > 0)
284283
{
285284
/* Expand simple_rel_array and simple_rte_array */
@@ -306,26 +305,32 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
306305
root->simple_rte_array = new_rte_array;
307306
}
308307

309-
/* Add parent if needed */
308+
/* Parent has already been locked by rewriter */
309+
parent_rel = heap_open(rte->relid, NoLock);
310+
311+
/* Add parent if asked to */
310312
if (prel->enable_parent)
311-
append_child_relation(root, rti, 0, rte->relid, NULL);
313+
append_child_relation(root, parent_rel, rti, 0, rte->relid, NULL);
312314

313315
/*
314-
* Iterate all indexes in rangeset and append corresponding child
315-
* relations.
316+
* Iterate all indexes in rangeset and append corresponding child relations.
316317
*/
317318
foreach(lc, ranges)
318319
{
319320
IndexRange irange = lfirst_irange(lc);
320321

321322
for (i = irange.ir_lower; i <= irange.ir_upper; i++)
322-
append_child_relation(root, rti, i, children[i], wrappers);
323+
append_child_relation(root, parent_rel, rti, i, children[i], wrappers);
323324
}
324325

325-
/* Clear old path list */
326-
list_free(rel->pathlist);
326+
/* Now close parent relation */
327+
heap_close(parent_rel, NoLock);
327328

329+
/* Clear path list and make it point to NIL */
330+
list_free_deep(rel->pathlist);
328331
rel->pathlist = NIL;
332+
333+
/* Generate new paths using the rels we've just added */
329334
set_append_rel_pathlist(root, rel, rti, pathkeyAsc, pathkeyDesc);
330335
set_append_rel_size_compat(root, rel, rti);
331336

@@ -342,6 +347,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
342347
if (!clause_contains_params((Node *) rel_part_clauses))
343348
return;
344349

350+
/* Generate Runtime[Merge]Append paths if needed */
345351
foreach (lc, rel->pathlist)
346352
{
347353
AppendPath *cur_path = (AppendPath *) lfirst(lc);

src/pathman.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ extern List *inheritance_disabled_relids;
123123
extern PathmanState *pmstate;
124124

125125

126-
int append_child_relation(PlannerInfo *root, Index parent_rti,
127-
int ir_index, Oid child_oid, List *wrappers);
126+
int append_child_relation(PlannerInfo *root, Relation parent_relation,
127+
Index parent_rti, int ir_index, Oid child_oid,
128+
List *wrappers);
128129

129130
search_rangerel_result search_range_partition_eq(const Datum value,
130131
FmgrInfo *cmp_func,

src/pg_pathman.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,15 +436,15 @@ make_inh_translation_list_simplified(Relation oldrelation,
436436
* NOTE: This code is partially based on the expand_inherited_rtentry() function.
437437
*/
438438
int
439-
append_child_relation(PlannerInfo *root, Index parent_rti,
440-
int ir_index, Oid child_oid, List *wrappers)
439+
append_child_relation(PlannerInfo *root, Relation parent_relation,
440+
Index parent_rti, int ir_index, Oid child_oid,
441+
List *wrappers)
441442
{
442443
RangeTblEntry *parent_rte,
443444
*child_rte;
444445
RelOptInfo *parent_rel,
445446
*child_rel;
446-
Relation parent_relation,
447-
child_relation;
447+
Relation child_relation;
448448
AppendRelInfo *appinfo;
449449
Index childRTindex;
450450
PlanRowMark *parent_rowmark,
@@ -455,8 +455,6 @@ append_child_relation(PlannerInfo *root, Index parent_rti,
455455
parent_rel = root->simple_rel_array[parent_rti];
456456
parent_rte = root->simple_rte_array[parent_rti];
457457

458-
/* Parent has already been locked by rewriter */
459-
parent_relation = heap_open(parent_rte->relid, NoLock);
460458
/* FIXME: acquire a suitable lock on partition */
461459
child_relation = heap_open(child_oid, NoLock);
462460

@@ -552,7 +550,6 @@ append_child_relation(PlannerInfo *root, Index parent_rti,
552550
parent_rel->tuples += child_rel->tuples;
553551

554552
/* Close child relations, but keep locks */
555-
heap_close(parent_relation, NoLock);
556553
heap_close(child_relation, NoLock);
557554

558555

@@ -600,6 +597,7 @@ wrapper_make_expression(WrapperNode *wrap, int index, bool *alwaysTrue)
600597
/* Return NULL for always true and always false. */
601598
if (!found)
602599
return NULL;
600+
603601
if (!lossy)
604602
{
605603
*alwaysTrue = true;

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