Skip to content

Commit 26e2cc3

Browse files
committed
various fixes for multilevel partitioning
1 parent 758694d commit 26e2cc3

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

Diff for: src/hooks.c

+17-9
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,24 @@ pathman_join_pathlist_hook(PlannerInfo *root,
108108
if (inner_rte->inh)
109109
return;
110110

111+
/* We shouldn't process functions etc */
112+
if (inner_rte->rtekind != RTE_RELATION)
113+
return;
114+
111115
/* We don't support these join types (since inner will be parameterized) */
112116
if (jointype == JOIN_FULL ||
113117
jointype == JOIN_RIGHT ||
114118
jointype == JOIN_UNIQUE_INNER)
115119
return;
116120

121+
/* Skip if inner table is not allowed to act as parent (e.g. FROM ONLY) */
122+
if (PARENTHOOD_DISALLOWED == get_rel_parenthood_status(inner_rte))
123+
return;
124+
117125
/* Proceed iff relation 'innerrel' is partitioned */
118126
if ((inner_prel = get_pathman_relation_info(inner_rte->relid)) == NULL)
119127
return;
120128

121-
/* Skip if inner table is not allowed to act as parent (e.g. FROM ONLY) */
122-
if (PARENTHOOD_DISALLOWED == get_rel_parenthood_status(inner_rte))
123-
goto cleanup;
124-
125129
/*
126130
* Check if query is:
127131
* 1) UPDATE part_table SET = .. FROM part_table.
@@ -294,7 +298,6 @@ pathman_join_pathlist_hook(PlannerInfo *root,
294298
add_path(joinrel, (Path *) nest_path);
295299
}
296300

297-
cleanup:
298301
/* Don't forget to close 'inner_prel'! */
299302
close_pathman_relation_info(inner_prel);
300303
}
@@ -380,14 +383,22 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
380383
foreach (lc, root->append_rel_list)
381384
{
382385
AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(lc);
386+
Oid child_oid,
387+
parent_oid;
388+
389+
/* Is it actually the same table? */
390+
child_oid = root->simple_rte_array[appinfo->child_relid]->relid;
391+
parent_oid = root->simple_rte_array[appinfo->parent_relid]->relid;
383392

384393
/*
385394
* If there's an 'appinfo', it means that somebody
386395
* (PG?) has already processed this partitioned table
387396
* and added its children to the plan.
388397
*/
389-
if (appinfo->child_relid == rti)
398+
if (appinfo->child_relid == rti && child_oid == parent_oid)
399+
{
390400
goto cleanup;
401+
}
391402
}
392403
}
393404

@@ -419,9 +430,6 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
419430
pathkeyDesc = (PathKey *) linitial(pathkeys);
420431
}
421432

422-
/* Mark as partitioned table */
423-
assign_rel_parenthood_status(rte, PARENTHOOD_DISALLOWED);
424-
425433
children = PrelGetChildrenArray(prel);
426434
ranges = list_make1_irange_full(prel, IR_COMPLETE);
427435

Diff for: src/pg_pathman.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -1951,13 +1951,8 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, Index rti,
19511951
set_rel_consider_parallel_compat(root, child_rel, child_rte);
19521952
#endif
19531953

1954-
/*
1955-
* If inh is True and pathlist is not null then it is a partitioned
1956-
* table and we've already filled it, skip it. Otherwise build a
1957-
* pathlist for it
1958-
*/
1959-
if (PARENTHOOD_DISALLOWED != get_rel_parenthood_status(child_rte) ||
1960-
child_rel->pathlist == NIL)
1954+
/* Build a few paths for this relation */
1955+
if (child_rel->pathlist == NIL)
19611956
{
19621957
/* Compute child's access paths & sizes */
19631958
if (child_rte->relkind == RELKIND_FOREIGN_TABLE)

0 commit comments

Comments
 (0)