aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/joinpath.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-12-05 12:36:41 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-12-05 12:36:41 -0500
commitdc3648f65bea3d3373b4e0026ae83bd8f436ee40 (patch)
tree55a1e515fd7f99a033157ba7b24511d448b3bd57 /src/backend/optimizer/path/joinpath.c
parent1bd84ef6778017f89c2ca80377c3ae02ed3f4861 (diff)
downloadpostgresql-dc3648f65bea3d3373b4e0026ae83bd8f436ee40.tar.gz
postgresql-dc3648f65bea3d3373b4e0026ae83bd8f436ee40.zip
Fix Memoize to work with partitionwise joining.
A couple of places weren't up to speed for this. By sheer good luck, we didn't fail but just selected a non-memoized join plan, at least in the test case we have. Nonetheless, it's a bug, and I'm not quite sure that it couldn't have worse consequences in other examples. So back-patch to v14 where Memoize came in. Richard Guo Discussion: https://postgr.es/m/CAMbWs48GkNom272sfp0-WeD6_0HSR19BJ4H1c9ZKSfbVnJsvRg@mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/path/joinpath.c')
-rw-r--r--src/backend/optimizer/path/joinpath.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c
index d23cd0e5271..44aa913da22 100644
--- a/src/backend/optimizer/path/joinpath.c
+++ b/src/backend/optimizer/path/joinpath.c
@@ -490,6 +490,7 @@ get_memoize_path(PlannerInfo *root, RelOptInfo *innerrel,
Path *outer_path, JoinType jointype,
JoinPathExtraData *extra)
{
+ RelOptInfo *top_outerrel;
List *param_exprs;
List *hash_operators;
ListCell *lc;
@@ -579,10 +580,21 @@ get_memoize_path(PlannerInfo *root, RelOptInfo *innerrel,
return NULL;
}
+ /*
+ * When considering a partitionwise join, we have clauses that reference
+ * the outerrel's top parent not outerrel itself.
+ */
+ if (outerrel->reloptkind == RELOPT_OTHER_MEMBER_REL)
+ top_outerrel = find_base_rel(root, bms_singleton_member(outerrel->top_parent_relids));
+ else if (outerrel->reloptkind == RELOPT_OTHER_JOINREL)
+ top_outerrel = find_join_rel(root, outerrel->top_parent_relids);
+ else
+ top_outerrel = outerrel;
+
/* Check if we have hash ops for each parameter to the path */
if (paraminfo_get_equal_hashops(root,
inner_path->param_info,
- outerrel,
+ top_outerrel,
innerrel,
&param_exprs,
&hash_operators,