Skip to content

Commit e373da0

Browse files
committed
fix 'spawned' in spawn_partitions(), small fixes in pl_funcs.c, get_pathman_relation_info() returns pointer to const PartRelationInfo
1 parent 18167f8 commit e373da0

File tree

7 files changed

+146
-138
lines changed

7 files changed

+146
-138
lines changed

src/hooks.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ pathman_join_pathlist_hook(PlannerInfo *root,
3636
JoinType jointype,
3737
JoinPathExtraData *extra)
3838
{
39-
JoinCostWorkspace workspace;
40-
RangeTblEntry *inner_rte = root->simple_rte_array[innerrel->relid];
41-
PartRelationInfo *inner_prel;
42-
List *pathkeys = NIL,
43-
*joinclauses,
44-
*otherclauses;
45-
ListCell *lc;
46-
WalkerContext context;
47-
double paramsel;
48-
bool innerrel_rinfo_contains_part_attr;
39+
JoinCostWorkspace workspace;
40+
RangeTblEntry *inner_rte = root->simple_rte_array[innerrel->relid];
41+
const PartRelationInfo *inner_prel;
42+
List *pathkeys = NIL,
43+
*joinclauses,
44+
*otherclauses;
45+
ListCell *lc;
46+
WalkerContext context;
47+
double paramsel;
48+
bool innerrel_rinfo_contains_part_attr;
4949

5050
/* Call hooks set by other extensions */
5151
if (set_join_pathlist_next)
@@ -159,10 +159,10 @@ pathman_join_pathlist_hook(PlannerInfo *root,
159159
void
160160
pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTblEntry *rte)
161161
{
162-
PartRelationInfo *prel = NULL;
163-
RangeTblEntry **new_rte_array;
164-
RelOptInfo **new_rel_array;
165-
int len;
162+
const PartRelationInfo *prel;
163+
RangeTblEntry **new_rte_array;
164+
RelOptInfo **new_rel_array;
165+
int len;
166166

167167
/* Invoke original hook if needed */
168168
if (set_rel_pathlist_hook_next != NULL)

src/nodes_common.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ replace_tlist_varnos(List *child_tlist, RelOptInfo *parent)
139139

140140
/* Append partition attribute in case it's not present in target list */
141141
static List *
142-
append_part_attr_to_tlist(List *tlist, Index relno, PartRelationInfo *prel)
142+
append_part_attr_to_tlist(List *tlist, Index relno, const PartRelationInfo *prel)
143143
{
144144
ListCell *lc;
145145
bool part_attr_found = false;
@@ -346,9 +346,12 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
346346
List *clauses, List *custom_plans,
347347
CustomScanMethods *scan_methods)
348348
{
349-
RuntimeAppendPath *rpath = (RuntimeAppendPath *) best_path;
350-
CustomScan *cscan;
351-
PartRelationInfo *prel = get_pathman_relation_info(rpath->relid);
349+
RuntimeAppendPath *rpath = (RuntimeAppendPath *) best_path;
350+
const PartRelationInfo *prel;
351+
CustomScan *cscan;
352+
353+
prel = get_pathman_relation_info(rpath->relid);
354+
Assert(prel);
352355

353356
cscan = makeNode(CustomScan);
354357
cscan->custom_scan_tlist = NIL; /* initial value (empty list) */
@@ -487,27 +490,27 @@ end_append_common(CustomScanState *node)
487490
void
488491
rescan_append_common(CustomScanState *node)
489492
{
490-
RuntimeAppendState *scan_state = (RuntimeAppendState *) node;
491-
ExprContext *econtext = node->ss.ps.ps_ExprContext;
492-
PartRelationInfo *prel;
493-
List *ranges;
494-
ListCell *lc;
495-
Oid *parts;
496-
int nparts;
493+
RuntimeAppendState *scan_state = (RuntimeAppendState *) node;
494+
ExprContext *econtext = node->ss.ps.ps_ExprContext;
495+
const PartRelationInfo *prel;
496+
List *ranges;
497+
ListCell *lc;
498+
Oid *parts;
499+
int nparts;
497500

498501
prel = get_pathman_relation_info(scan_state->relid);
499502
Assert(prel);
500503

504+
/* First we select all available partitions... */
501505
ranges = list_make1_irange(make_irange(0, PrelChildrenCount(prel) - 1, false));
502506

503507
InitWalkerContext(&scan_state->wcxt, prel, econtext, false);
504-
505508
foreach (lc, scan_state->custom_exprs)
506509
{
507510
WrapperNode *wn;
508511

512+
/* ... then we cut off irrelevant ones using the provided clauses */
509513
wn = walk_expr_tree((Expr *) lfirst(lc), &scan_state->wcxt);
510-
511514
ranges = irange_list_intersect(ranges, wn->rangeset);
512515
}
513516

src/partition_filter.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,18 +153,18 @@ partition_filter_exec(CustomScanState *node)
153153

154154
if (!TupIsNull(slot))
155155
{
156-
PartRelationInfo *prel;
156+
const PartRelationInfo *prel;
157157

158-
MemoryContext old_cxt;
158+
MemoryContext old_cxt;
159159

160-
List *ranges;
161-
int nparts;
162-
Oid *parts;
163-
Oid selected_partid;
160+
List *ranges;
161+
int nparts;
162+
Oid *parts;
163+
Oid selected_partid;
164164

165-
WalkerContext wcxt;
166-
bool isnull;
167-
Datum value;
165+
WalkerContext wcxt;
166+
bool isnull;
167+
Datum value;
168168

169169
/* Fetch PartRelationInfo for this partitioned relation */
170170
prel = get_pathman_relation_info(state->partitioned_table);
@@ -390,9 +390,9 @@ partition_filter_visitor(Plan *plan, void *context)
390390

391391
forboth (lc1, modify_table->plans, lc2, modify_table->resultRelations)
392392
{
393-
Index rindex = lfirst_int(lc2);
394-
Oid relid = getrelid(rindex, rtable);
395-
PartRelationInfo *prel = get_pathman_relation_info(relid);
393+
Index rindex = lfirst_int(lc2);
394+
Oid relid = getrelid(rindex, rtable);
395+
const PartRelationInfo *prel = get_pathman_relation_info(relid);
396396

397397
/* Check that table is partitioned */
398398
if (prel)

src/pg_pathman.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ _PG_init(void)
175175
void
176176
disable_inheritance(Query *parse)
177177
{
178-
ListCell *lc;
179-
RangeTblEntry *rte;
180-
PartRelationInfo *prel;
181-
MemoryContext oldcontext;
178+
const PartRelationInfo *prel;
179+
RangeTblEntry *rte;
180+
MemoryContext oldcontext;
181+
ListCell *lc;
182182

183183
/* If query contains CTE (WITH statement) then handle subqueries too */
184184
disable_inheritance_cte(parse);
@@ -301,12 +301,12 @@ disable_inheritance_subselect_walker(Node *node, void *context)
301301
void
302302
handle_modification_query(Query *parse)
303303
{
304-
PartRelationInfo *prel;
305-
List *ranges;
306-
RangeTblEntry *rte;
307-
WrapperNode *wrap;
308-
Expr *expr;
309-
WalkerContext context;
304+
const PartRelationInfo *prel;
305+
List *ranges;
306+
RangeTblEntry *rte;
307+
WrapperNode *wrap;
308+
Expr *expr;
309+
WalkerContext context;
310310

311311
Assert(parse->commandType == CMD_UPDATE ||
312312
parse->commandType == CMD_DELETE);
@@ -725,7 +725,7 @@ spawn_partitions(Oid partitioned_rel, /* parent's Oid */
725725

726726
FmgrInfo interval_move_bound; /* function to move upper\lower boundary */
727727
bool interval_move_bound_cached = false; /* is it cached already? */
728-
bool done = false;
728+
bool spawned = false;
729729

730730
Datum cur_part_leading = leading_bound;
731731

@@ -737,7 +737,7 @@ spawn_partitions(Oid partitioned_rel, /* parent's Oid */
737737
get_namespace_name(get_pathman_schema()));
738738

739739
/* Execute comparison function cmp(value, cur_part_leading) */
740-
while ((done = do_compare(cmp_proc, value, cur_part_leading, forward)))
740+
while (do_compare(cmp_proc, value, cur_part_leading, forward))
741741
{
742742
char *nulls = NULL; /* no params are NULL */
743743
Oid types[3] = { REGCLASSOID, leading_bound_type, leading_bound_type };
@@ -786,11 +786,14 @@ spawn_partitions(Oid partitioned_rel, /* parent's Oid */
786786
DebugPrintDatum(cur_part_leading, leading_bound_type),
787787
MyProcPid);
788788
#endif
789+
790+
/* We have spawned at least 1 partition */
791+
spawned = true;
789792
}
790793

791794
pfree(query);
792795

793-
return done;
796+
return spawned;
794797
}
795798

796799
/*

0 commit comments

Comments
 (0)