firtst release
Revision | f204d75aa3f94d46bed75b0fc9a6ab05ff1647f1 (tree) |
---|---|
Time | 2020-02-17 17:49:55 |
Author | Kyotaro Horiguchi <horikyota.ntt@gmai...> |
Commiter | Kyotaro Horiguchi |
Follow the core chnges.
Update core.c following the changes in the core. It makes difference
in the regression test result so update it, too.
@@ -859,6 +859,10 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, | ||
859 | 859 | { |
860 | 860 | SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(l); |
861 | 861 | |
862 | + /* ignore full joins --- their ordering is predetermined */ | |
863 | + if (sjinfo->jointype == JOIN_FULL) | |
864 | + continue; | |
865 | + | |
862 | 866 | if (bms_overlap(sjinfo->min_lefthand, join_plus_rhs) && |
863 | 867 | !bms_is_subset(sjinfo->min_righthand, join_plus_rhs)) |
864 | 868 | { |
@@ -866,15 +870,6 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, | ||
866 | 870 | sjinfo->min_righthand); |
867 | 871 | more = true; |
868 | 872 | } |
869 | - /* full joins constrain both sides symmetrically */ | |
870 | - if (sjinfo->jointype == JOIN_FULL && | |
871 | - bms_overlap(sjinfo->min_righthand, join_plus_rhs) && | |
872 | - !bms_is_subset(sjinfo->min_lefthand, join_plus_rhs)) | |
873 | - { | |
874 | - join_plus_rhs = bms_add_members(join_plus_rhs, | |
875 | - sjinfo->min_lefthand); | |
876 | - more = true; | |
877 | - } | |
878 | 873 | } |
879 | 874 | } while (more); |
880 | 875 | if (bms_overlap(join_plus_rhs, join_lateral_rels)) |
@@ -975,7 +970,8 @@ mark_dummy_rel(RelOptInfo *rel) | ||
975 | 970 | rel->partial_pathlist = NIL; |
976 | 971 | |
977 | 972 | /* Set up the dummy path */ |
978 | - add_path(rel, (Path *) create_append_path(NULL, rel, NIL, NIL, NULL, | |
973 | + add_path(rel, (Path *) create_append_path(NULL, rel, NIL, NIL, | |
974 | + rel->lateral_relids, | |
979 | 975 | 0, false, NIL, -1)); |
980 | 976 | |
981 | 977 | /* Set or update cheapest_total_path and related fields */ |
@@ -1056,6 +1052,8 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, | ||
1056 | 1052 | RelOptInfo *joinrel, SpecialJoinInfo *parent_sjinfo, |
1057 | 1053 | List *parent_restrictlist) |
1058 | 1054 | { |
1055 | + bool rel1_is_simple = IS_SIMPLE_REL(rel1); | |
1056 | + bool rel2_is_simple = IS_SIMPLE_REL(rel2); | |
1059 | 1057 | int nparts; |
1060 | 1058 | int cnt_parts; |
1061 | 1059 |
@@ -1113,6 +1111,10 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, | ||
1113 | 1111 | { |
1114 | 1112 | RelOptInfo *child_rel1 = rel1->part_rels[cnt_parts]; |
1115 | 1113 | RelOptInfo *child_rel2 = rel2->part_rels[cnt_parts]; |
1114 | + bool rel1_empty = (child_rel1 == NULL || | |
1115 | + IS_DUMMY_REL(child_rel1)); | |
1116 | + bool rel2_empty = (child_rel2 == NULL || | |
1117 | + IS_DUMMY_REL(child_rel2)); | |
1116 | 1118 | SpecialJoinInfo *child_sjinfo; |
1117 | 1119 | List *child_restrictlist; |
1118 | 1120 | RelOptInfo *child_joinrel; |
@@ -1120,6 +1122,72 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2, | ||
1120 | 1122 | AppendRelInfo **appinfos; |
1121 | 1123 | int nappinfos; |
1122 | 1124 | |
1125 | + /* | |
1126 | + * Check for cases where we can prove that this segment of the join | |
1127 | + * returns no rows, due to one or both inputs being empty (including | |
1128 | + * inputs that have been pruned away entirely). If so just ignore it. | |
1129 | + * These rules are equivalent to populate_joinrel_with_paths's rules | |
1130 | + * for dummy input relations. | |
1131 | + */ | |
1132 | + switch (parent_sjinfo->jointype) | |
1133 | + { | |
1134 | + case JOIN_INNER: | |
1135 | + case JOIN_SEMI: | |
1136 | + if (rel1_empty || rel2_empty) | |
1137 | + continue; /* ignore this join segment */ | |
1138 | + break; | |
1139 | + case JOIN_LEFT: | |
1140 | + case JOIN_ANTI: | |
1141 | + if (rel1_empty) | |
1142 | + continue; /* ignore this join segment */ | |
1143 | + break; | |
1144 | + case JOIN_FULL: | |
1145 | + if (rel1_empty && rel2_empty) | |
1146 | + continue; /* ignore this join segment */ | |
1147 | + break; | |
1148 | + default: | |
1149 | + /* other values not expected here */ | |
1150 | + elog(ERROR, "unrecognized join type: %d", | |
1151 | + (int) parent_sjinfo->jointype); | |
1152 | + break; | |
1153 | + } | |
1154 | + | |
1155 | + /* | |
1156 | + * If a child has been pruned entirely then we can't generate paths | |
1157 | + * for it, so we have to reject partitionwise joining unless we were | |
1158 | + * able to eliminate this partition above. | |
1159 | + */ | |
1160 | + if (child_rel1 == NULL || child_rel2 == NULL) | |
1161 | + { | |
1162 | + /* | |
1163 | + * Mark the joinrel as unpartitioned so that later functions treat | |
1164 | + * it correctly. | |
1165 | + */ | |
1166 | + joinrel->nparts = 0; | |
1167 | + return; | |
1168 | + } | |
1169 | + | |
1170 | + /* | |
1171 | + * If a leaf relation has consider_partitionwise_join=false, it means | |
1172 | + * that it's a dummy relation for which we skipped setting up tlist | |
1173 | + * expressions and adding EC members in set_append_rel_size(), so | |
1174 | + * again we have to fail here. | |
1175 | + */ | |
1176 | + if (rel1_is_simple && !child_rel1->consider_partitionwise_join) | |
1177 | + { | |
1178 | + Assert(child_rel1->reloptkind == RELOPT_OTHER_MEMBER_REL); | |
1179 | + Assert(IS_DUMMY_REL(child_rel1)); | |
1180 | + joinrel->nparts = 0; | |
1181 | + return; | |
1182 | + } | |
1183 | + if (rel2_is_simple && !child_rel2->consider_partitionwise_join) | |
1184 | + { | |
1185 | + Assert(child_rel2->reloptkind == RELOPT_OTHER_MEMBER_REL); | |
1186 | + Assert(IS_DUMMY_REL(child_rel2)); | |
1187 | + joinrel->nparts = 0; | |
1188 | + return; | |
1189 | + } | |
1190 | + | |
1123 | 1191 | /* We should never try to join two overlapping sets of rels. */ |
1124 | 1192 | Assert(!bms_overlap(child_rel1->relids, child_rel2->relids)); |
1125 | 1193 | child_joinrelids = bms_union(child_rel1->relids, child_rel2->relids); |
@@ -555,33 +555,33 @@ not used hint: | ||
555 | 555 | duplication hint: |
556 | 556 | error hint: |
557 | 557 | |
558 | - QUERY PLAN | |
559 | -------------------------------------------------------- | |
558 | + QUERY PLAN | |
559 | +------------------------------------------------- | |
560 | 560 | Hash Join |
561 | - Hash Cond: (p1.id = p2.id) | |
562 | - -> Append | |
563 | - -> Seq Scan on p1 | |
564 | - -> Seq Scan on p1_c1 | |
565 | - -> Seq Scan on p1_c2 | |
566 | - -> Seq Scan on p1_c3 | |
567 | - -> Seq Scan on p1_c4 | |
568 | - -> Seq Scan on p1_c1_c1 | |
569 | - -> Seq Scan on p1_c1_c2 | |
570 | - -> Seq Scan on p1_c3_c1 | |
571 | - -> Seq Scan on p1_c3_c2 | |
561 | + Hash Cond: (p2.id = p1.id) | |
562 | + -> Gather | |
563 | + Workers Planned: 8 | |
564 | + -> Parallel Append | |
565 | + -> Seq Scan on p2 | |
566 | + -> Seq Scan on p2_c1 | |
567 | + -> Seq Scan on p2_c3 | |
568 | + -> Parallel Seq Scan on p2_c2 | |
569 | + -> Parallel Seq Scan on p2_c4 | |
570 | + -> Parallel Seq Scan on p2_c1_c1 | |
571 | + -> Parallel Seq Scan on p2_c1_c2 | |
572 | + -> Parallel Seq Scan on p2_c3_c1 | |
573 | + -> Parallel Seq Scan on p2_c3_c2 | |
572 | 574 | -> Hash |
573 | - -> Gather | |
574 | - Workers Planned: 8 | |
575 | - -> Parallel Append | |
576 | - -> Seq Scan on p2 | |
577 | - -> Seq Scan on p2_c1 | |
578 | - -> Seq Scan on p2_c3 | |
579 | - -> Parallel Seq Scan on p2_c2 | |
580 | - -> Parallel Seq Scan on p2_c4 | |
581 | - -> Parallel Seq Scan on p2_c1_c1 | |
582 | - -> Parallel Seq Scan on p2_c1_c2 | |
583 | - -> Parallel Seq Scan on p2_c3_c1 | |
584 | - -> Parallel Seq Scan on p2_c3_c2 | |
575 | + -> Append | |
576 | + -> Seq Scan on p1 | |
577 | + -> Seq Scan on p1_c1 | |
578 | + -> Seq Scan on p1_c2 | |
579 | + -> Seq Scan on p1_c3 | |
580 | + -> Seq Scan on p1_c4 | |
581 | + -> Seq Scan on p1_c1_c1 | |
582 | + -> Seq Scan on p1_c1_c2 | |
583 | + -> Seq Scan on p1_c3_c1 | |
584 | + -> Seq Scan on p1_c3_c2 | |
585 | 585 | (25 rows) |
586 | 586 | |
587 | 587 | -- Number of workers results to the largest number |
@@ -799,33 +799,33 @@ not used hint: | ||
799 | 799 | duplication hint: |
800 | 800 | error hint: |
801 | 801 | |
802 | - QUERY PLAN | |
803 | -------------------------------------------------------- | |
802 | + QUERY PLAN | |
803 | +------------------------------------------------- | |
804 | 804 | Hash Join |
805 | - Hash Cond: (p2.id = p1.id) | |
806 | - -> Append | |
807 | - -> Seq Scan on p2 | |
808 | - -> Seq Scan on p2_c1 | |
809 | - -> Seq Scan on p2_c2 | |
810 | - -> Seq Scan on p2_c3 | |
811 | - -> Seq Scan on p2_c4 | |
812 | - -> Seq Scan on p2_c1_c1 | |
813 | - -> Seq Scan on p2_c1_c2 | |
814 | - -> Seq Scan on p2_c3_c1 | |
815 | - -> Seq Scan on p2_c3_c2 | |
805 | + Hash Cond: (p1.id = p2.id) | |
806 | + -> Gather | |
807 | + Workers Planned: 8 | |
808 | + -> Parallel Append | |
809 | + -> Seq Scan on p1 | |
810 | + -> Seq Scan on p1_c1 | |
811 | + -> Seq Scan on p1_c3 | |
812 | + -> Parallel Seq Scan on p1_c2 | |
813 | + -> Parallel Seq Scan on p1_c4 | |
814 | + -> Parallel Seq Scan on p1_c1_c1 | |
815 | + -> Parallel Seq Scan on p1_c1_c2 | |
816 | + -> Parallel Seq Scan on p1_c3_c1 | |
817 | + -> Parallel Seq Scan on p1_c3_c2 | |
816 | 818 | -> Hash |
817 | - -> Gather | |
818 | - Workers Planned: 8 | |
819 | - -> Parallel Append | |
820 | - -> Seq Scan on p1 | |
821 | - -> Seq Scan on p1_c1 | |
822 | - -> Seq Scan on p1_c3 | |
823 | - -> Parallel Seq Scan on p1_c2 | |
824 | - -> Parallel Seq Scan on p1_c4 | |
825 | - -> Parallel Seq Scan on p1_c1_c1 | |
826 | - -> Parallel Seq Scan on p1_c1_c2 | |
827 | - -> Parallel Seq Scan on p1_c3_c1 | |
828 | - -> Parallel Seq Scan on p1_c3_c2 | |
819 | + -> Append | |
820 | + -> Seq Scan on p2 | |
821 | + -> Seq Scan on p2_c1 | |
822 | + -> Seq Scan on p2_c2 | |
823 | + -> Seq Scan on p2_c3 | |
824 | + -> Seq Scan on p2_c4 | |
825 | + -> Seq Scan on p2_c1_c1 | |
826 | + -> Seq Scan on p2_c1_c2 | |
827 | + -> Seq Scan on p2_c3_c1 | |
828 | + -> Seq Scan on p2_c3_c2 | |
829 | 829 | (25 rows) |
830 | 830 | |
831 | 831 | -- Parallel index scan |
@@ -880,33 +880,33 @@ not used hint: | ||
880 | 880 | duplication hint: |
881 | 881 | error hint: |
882 | 882 | |
883 | - QUERY PLAN | |
884 | ------------------------------------------------------------------------------ | |
883 | + QUERY PLAN | |
884 | +----------------------------------------------------------------------- | |
885 | 885 | Hash Join |
886 | - Hash Cond: (p2.id = p1.id) | |
887 | - -> Append | |
888 | - -> Seq Scan on p2 | |
889 | - -> Seq Scan on p2_c1 | |
890 | - -> Seq Scan on p2_c2 | |
891 | - -> Seq Scan on p2_c3 | |
892 | - -> Seq Scan on p2_c4 | |
893 | - -> Seq Scan on p2_c1_c1 | |
894 | - -> Seq Scan on p2_c1_c2 | |
895 | - -> Seq Scan on p2_c3_c1 | |
896 | - -> Seq Scan on p2_c3_c2 | |
886 | + Hash Cond: (p1.id = p2.id) | |
887 | + -> Gather | |
888 | + Workers Planned: 8 | |
889 | + -> Parallel Append | |
890 | + -> Parallel Index Scan using p1_pkey on p1 | |
891 | + -> Parallel Index Scan using p1_c1_pkey on p1_c1 | |
892 | + -> Parallel Index Scan using p1_c2_pkey on p1_c2 | |
893 | + -> Parallel Index Scan using p1_c3_pkey on p1_c3 | |
894 | + -> Parallel Index Scan using p1_c4_pkey on p1_c4 | |
895 | + -> Parallel Index Scan using p1_c1_c1_pkey on p1_c1_c1 | |
896 | + -> Parallel Index Scan using p1_c1_c2_pkey on p1_c1_c2 | |
897 | + -> Parallel Index Scan using p1_c3_c1_pkey on p1_c3_c1 | |
898 | + -> Parallel Index Scan using p1_c3_c2_pkey on p1_c3_c2 | |
897 | 899 | -> Hash |
898 | - -> Gather | |
899 | - Workers Planned: 8 | |
900 | - -> Parallel Append | |
901 | - -> Parallel Index Scan using p1_pkey on p1 | |
902 | - -> Parallel Index Scan using p1_c1_pkey on p1_c1 | |
903 | - -> Parallel Index Scan using p1_c2_pkey on p1_c2 | |
904 | - -> Parallel Index Scan using p1_c3_pkey on p1_c3 | |
905 | - -> Parallel Index Scan using p1_c4_pkey on p1_c4 | |
906 | - -> Parallel Index Scan using p1_c1_c1_pkey on p1_c1_c1 | |
907 | - -> Parallel Index Scan using p1_c1_c2_pkey on p1_c1_c2 | |
908 | - -> Parallel Index Scan using p1_c3_c1_pkey on p1_c3_c1 | |
909 | - -> Parallel Index Scan using p1_c3_c2_pkey on p1_c3_c2 | |
900 | + -> Append | |
901 | + -> Seq Scan on p2 | |
902 | + -> Seq Scan on p2_c1 | |
903 | + -> Seq Scan on p2_c2 | |
904 | + -> Seq Scan on p2_c3 | |
905 | + -> Seq Scan on p2_c4 | |
906 | + -> Seq Scan on p2_c1_c1 | |
907 | + -> Seq Scan on p2_c1_c2 | |
908 | + -> Seq Scan on p2_c3_c1 | |
909 | + -> Seq Scan on p2_c3_c2 | |
910 | 910 | (25 rows) |
911 | 911 | |
912 | 912 | -- This hint doesn't turn on parallel, so the Parallel hint is ignored |