Skip to content

Commit c78ee4e

Browse files
committed
include parent into Runtime[Merge]Append's plan if asked to, introduce macro PrelParentRelid
1 parent 7423e87 commit c78ee4e

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

src/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ fill_prel_with_partitions(const Oid *partitions,
373373
DisablePathman(); /* disable pg_pathman since config is broken */
374374
ereport(ERROR,
375375
(errmsg("Unknown partitioning type for relation \"%s\"",
376-
get_rel_name_or_relid(prel->key)),
376+
get_rel_name_or_relid(PrelParentRelid(prel))),
377377
errhint(INIT_ERROR_HINT)));
378378
}
379379
}
@@ -419,7 +419,7 @@ fill_prel_with_partitions(const Oid *partitions,
419419
DisablePathman(); /* disable pg_pathman since config is broken */
420420
elog(ERROR, "pg_pathman's cache for relation \"%s\" "
421421
"has not been properly initialized",
422-
get_rel_name_or_relid(prel->key));
422+
get_rel_name_or_relid(PrelParentRelid(prel)));
423423
}
424424
}
425425
#endif

src/nodes_common.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ get_partition_oids(List *ranges, int *n, const PartRelationInfo *prel)
248248
Oid *result = (Oid *) palloc(allocated * sizeof(Oid));
249249
Oid *children = PrelGetChildrenArray(prel);
250250

251+
/* If required, add parent to result */
252+
Assert(INITIAL_ALLOC_NUM >= 1);
253+
if (prel->enable_parent)
254+
result[used++] = PrelParentRelid(prel);
255+
256+
/* Deal with selected partitions */
251257
foreach (range_cell, ranges)
252258
{
253259
uint32 i;
@@ -366,6 +372,10 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
366372
{
367373
Plan *child_plan = (Plan *) lfirst(lc2);
368374
RelOptInfo *child_rel = ((Path *) lfirst(lc1))->parent;
375+
Oid child_relid;
376+
377+
/* Fetch relid of the 'child_rel' */
378+
child_relid = root->simple_rte_array[child_rel->relid]->relid;
369379

370380
/* Replace rel's tlist with a matching one */
371381
if (!cscan->scan.plan.targetlist)
@@ -380,6 +390,10 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
380390
if (!cscan->custom_scan_tlist)
381391
cscan->custom_scan_tlist = replace_tlist_varnos(child_plan->targetlist,
382392
rel);
393+
394+
/* If this is a plan for parent table, fill it with quals */
395+
if (PrelParentRelid(prel) == child_relid)
396+
child_plan->qual = get_actual_clauses(clauses);
383397
}
384398
}
385399

src/pg_pathman.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -900,13 +900,13 @@ create_partitions_internal(Oid relid, Datum value, Oid value_type)
900900
elog(ERROR, "Could not connect using SPI");
901901

902902
/* while (value >= MAX) ... */
903-
spawn_partitions(prel->key, value, max_rvalue, prel->atttype,
904-
&interval_type_cmp, interval_binary,
903+
spawn_partitions(PrelParentRelid(prel), value, max_rvalue,
904+
prel->atttype, &interval_type_cmp, interval_binary,
905905
interval_type, true, &partid);
906906

907907
/* while (value < MIN) ... */
908-
spawn_partitions(prel->key, value, min_rvalue, prel->atttype,
909-
&interval_type_cmp, interval_binary,
908+
spawn_partitions(PrelParentRelid(prel), value, min_rvalue,
909+
prel->atttype, &interval_type_cmp, interval_binary,
910910
interval_type, false, &partid);
911911

912912
SPI_finish(); /* close SPI connection */

src/relation_info.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ typedef enum
9696
* PartRelationInfo field access macros.
9797
*/
9898

99+
#define PrelParentRelid(prel) ( (prel)->key )
100+
99101
#define PrelGetChildrenArray(prel) ( (prel)->children )
100102

101103
#define PrelGetRangesArray(prel) ( (prel)->ranges )
@@ -111,7 +113,7 @@ PrelLastChild(const PartRelationInfo *prel)
111113

112114
if (PrelChildrenCount(prel) == 0)
113115
elog(ERROR, "pg_pathman's cache entry for relation %u has 0 children",
114-
prel->key);
116+
PrelParentRelid(prel));
115117

116118
return PrelChildrenCount(prel) - 1; /* last partition */
117119
}
@@ -161,7 +163,7 @@ FreeChildrenArray(PartRelationInfo *prel)
161163
Oid child = (prel)->children[i];
162164

163165
/* If it's *always been* relid's partition, free cache */
164-
if (prel->key == get_parent_of_partition(child, NULL))
166+
if (PrelParentRelid(prel) == get_parent_of_partition(child, NULL))
165167
forget_parent_of_partition(child, NULL);
166168
}
167169

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