@@ -661,6 +661,7 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
661
661
int parentRTindex = rti ;
662
662
List * live_childrels = NIL ;
663
663
List * subpaths = NIL ;
664
+ bool subpaths_valid = true;
664
665
List * all_child_pathkeys = NIL ;
665
666
List * all_child_outers = NIL ;
666
667
ListCell * l ;
@@ -699,19 +700,21 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
699
700
if (IS_DUMMY_REL (childrel ))
700
701
continue ;
701
702
702
- /* XXX need to figure out what to do for LATERAL */
703
- if (childrel -> cheapest_total_path == NULL )
704
- elog (ERROR , "LATERAL within an append relation is not supported yet" );
703
+ /*
704
+ * Child is live, so add it to the live_childrels list for use below.
705
+ */
706
+ live_childrels = lappend (live_childrels , childrel );
705
707
706
708
/*
707
- * Child is live, so add its cheapest access path to the Append path
708
- * we are constructing for the parent.
709
+ * If child has an unparameterized cheapest-total path, add that to
710
+ * the unparameterized Append path we are constructing for the parent.
711
+ * If not, there's no workable unparameterized path.
709
712
*/
710
- subpaths = accumulate_append_subpath (subpaths ,
713
+ if (childrel -> cheapest_total_path )
714
+ subpaths = accumulate_append_subpath (subpaths ,
711
715
childrel -> cheapest_total_path );
712
-
713
- /* Remember which childrels are live, for logic below */
714
- live_childrels = lappend (live_childrels , childrel );
716
+ else
717
+ subpaths_valid = false;
715
718
716
719
/*
717
720
* Collect lists of all the available path orderings and
@@ -779,17 +782,20 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
779
782
}
780
783
781
784
/*
782
- * Next, build an unordered, unparameterized Append path for the rel.
783
- * (Note: this is correct even if we have zero or one live subpath due to
784
- * constraint exclusion.)
785
+ * If we found unparameterized paths for all children, build an unordered,
786
+ * unparameterized Append path for the rel. (Note: this is correct even
787
+ * if we have zero or one live subpath due to constraint exclusion.)
785
788
*/
786
- add_path (rel , (Path * ) create_append_path (rel , subpaths , NULL ));
789
+ if (subpaths_valid )
790
+ add_path (rel , (Path * ) create_append_path (rel , subpaths , NULL ));
787
791
788
792
/*
789
- * Build unparameterized MergeAppend paths based on the collected list of
790
- * child pathkeys.
793
+ * Also build unparameterized MergeAppend paths based on the collected
794
+ * list of child pathkeys.
791
795
*/
792
- generate_mergeappend_paths (root , rel , live_childrels , all_child_pathkeys );
796
+ if (subpaths_valid )
797
+ generate_mergeappend_paths (root , rel , live_childrels ,
798
+ all_child_pathkeys );
793
799
794
800
/*
795
801
* Build Append paths for each parameterization seen among the child rels.
@@ -807,11 +813,11 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
807
813
foreach (l , all_child_outers )
808
814
{
809
815
Relids required_outer = (Relids ) lfirst (l );
810
- bool ok = true;
811
816
ListCell * lcr ;
812
817
813
818
/* Select the child paths for an Append with this parameterization */
814
819
subpaths = NIL ;
820
+ subpaths_valid = true;
815
821
foreach (lcr , live_childrels )
816
822
{
817
823
RelOptInfo * childrel = (RelOptInfo * ) lfirst (lcr );
@@ -831,15 +837,15 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
831
837
required_outer , 1.0 );
832
838
if (cheapest_total == NULL )
833
839
{
834
- ok = false;
840
+ subpaths_valid = false;
835
841
break ;
836
842
}
837
843
}
838
844
839
845
subpaths = accumulate_append_subpath (subpaths , cheapest_total );
840
846
}
841
847
842
- if (ok )
848
+ if (subpaths_valid )
843
849
add_path (rel , (Path * )
844
850
create_append_path (rel , subpaths , required_outer ));
845
851
}
@@ -911,13 +917,11 @@ generate_mergeappend_paths(PlannerInfo *root, RelOptInfo *rel,
911
917
*/
912
918
if (cheapest_startup == NULL || cheapest_total == NULL )
913
919
{
914
- /* XXX need to figure out what to do for LATERAL */
915
- if (childrel -> cheapest_total_path == NULL )
916
- elog (ERROR , "LATERAL within an append relation is not supported yet" );
917
-
918
920
cheapest_startup = cheapest_total =
919
921
childrel -> cheapest_total_path ;
922
+ /* Assert we do have an unparameterized path for this child */
920
923
Assert (cheapest_total != NULL );
924
+ Assert (cheapest_total -> param_info == NULL );
921
925
}
922
926
923
927
/*
0 commit comments