aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/optimizer/util/pathnode.c34
-rw-r--r--src/test/regress/expected/join.out19
-rw-r--r--src/test/regress/sql/join.sql10
3 files changed, 63 insertions, 0 deletions
diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c
index 91295ebca49..fe3b4582d42 100644
--- a/src/backend/optimizer/util/pathnode.c
+++ b/src/backend/optimizer/util/pathnode.c
@@ -3540,6 +3540,40 @@ reparameterize_path(PlannerInfo *root, Path *path,
spath->path.pathkeys,
required_outer);
}
+ case T_Append:
+ {
+ AppendPath *apath = (AppendPath *) path;
+ List *childpaths = NIL;
+ List *partialpaths = NIL;
+ int i;
+ ListCell *lc;
+
+ /* Reparameterize the children */
+ i = 0;
+ foreach(lc, apath->subpaths)
+ {
+ Path *spath = (Path *) lfirst(lc);
+
+ spath = reparameterize_path(root, spath,
+ required_outer,
+ loop_count);
+ if (spath == NULL)
+ return NULL;
+ /* We have to re-split the regular and partial paths */
+ if (i < apath->first_partial_path)
+ childpaths = lappend(childpaths, spath);
+ else
+ partialpaths = lappend(partialpaths, spath);
+ i++;
+ }
+ return (Path *)
+ create_append_path(rel, childpaths, partialpaths,
+ required_outer,
+ apath->path.parallel_workers,
+ apath->path.parallel_aware,
+ apath->partitioned_rels,
+ -1);
+ }
default:
break;
}
diff --git a/src/test/regress/expected/join.out b/src/test/regress/expected/join.out
index 02e7d56e550..c50a206efb8 100644
--- a/src/test/regress/expected/join.out
+++ b/src/test/regress/expected/join.out
@@ -5188,6 +5188,25 @@ select * from
Output: 3
(11 rows)
+-- check handling of nested appendrels inside LATERAL
+select * from
+ ((select 2 as v) union all (select 3 as v)) as q1
+ cross join lateral
+ ((select * from
+ ((select 4 as v) union all (select 5 as v)) as q3)
+ union all
+ (select q1.v)
+ ) as q2;
+ v | v
+---+---
+ 2 | 4
+ 2 | 5
+ 2 | 2
+ 3 | 4
+ 3 | 5
+ 3 | 3
+(6 rows)
+
-- check we don't try to do a unique-ified semijoin with LATERAL
explain (verbose, costs off)
select * from
diff --git a/src/test/regress/sql/join.sql b/src/test/regress/sql/join.sql
index dd62c38c15e..fc84237ce92 100644
--- a/src/test/regress/sql/join.sql
+++ b/src/test/regress/sql/join.sql
@@ -1682,6 +1682,16 @@ select * from
select * from (select 3 as z offset 0) z where z.z = x.x
) zz on zz.z = y.y;
+-- check handling of nested appendrels inside LATERAL
+select * from
+ ((select 2 as v) union all (select 3 as v)) as q1
+ cross join lateral
+ ((select * from
+ ((select 4 as v) union all (select 5 as v)) as q3)
+ union all
+ (select q1.v)
+ ) as q2;
+
-- check we don't try to do a unique-ified semijoin with LATERAL
explain (verbose, costs off)
select * from