Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bf8fd64

Browse files
committedDec 4, 2022
Fix generate_partitionwise_join_paths() to tolerate failure.
We might fail to generate a partitionwise join, because reparameterize_path_by_child() does not support all path types. This should not be a hard failure condition: we should just fall back to a non-partitioned join. However, generate_partitionwise_join_paths did not consider this possibility and would emit the (misleading) error "could not devise a query plan for the given query" if we'd failed to make any paths for a child join. Fix it to give up on partitionwise joining if so. (The accepted technique for giving up appears to be to set rel->nparts = 0, which I find pretty bizarre, but there you have it.) I have not added a test case because there'd be little point: any omissions of this sort that we identify would soon get fixed by extending reparameterize_path_by_child(), so the test would stop proving anything. However, right now there is a known test case based on failure to cover MaterialPath, and with that I've found that this is broken in all supported versions. Hence, patch all the way back. Original report and patch by me; thanks to Richard Guo for identifying a test case that works against committed versions. Discussion: https://postgr.es/m/1854233.1669949723@sss.pgh.pa.us
1 parent c67204d commit bf8fd64

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed
 

‎src/backend/optimizer/path/allpaths.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4240,12 +4240,24 @@ generate_partitionwise_join_paths(PlannerInfo *root, RelOptInfo *rel)
42404240
if (child_rel == NULL)
42414241
continue;
42424242

4243-
/* Add partitionwise join paths for partitioned child-joins. */
4243+
/* Make partitionwise join paths for this partitioned child-join. */
42444244
generate_partitionwise_join_paths(root, child_rel);
42454245

4246+
/* If we failed to make any path for this child, we must give up. */
4247+
if (child_rel->pathlist == NIL)
4248+
{
4249+
/*
4250+
* Mark the parent joinrel as unpartitioned so that later
4251+
* functions treat it correctly.
4252+
*/
4253+
rel->nparts = 0;
4254+
return;
4255+
}
4256+
4257+
/* Else, identify the cheapest path for it. */
42464258
set_cheapest(child_rel);
42474259

4248-
/* Dummy children will not be scanned, so ignore those. */
4260+
/* Dummy children need not be scanned, so ignore those. */
42494261
if (IS_DUMMY_REL(child_rel))
42504262
continue;
42514263

0 commit comments

Comments
 (0)
Failed to load comments.