• R/O
  • HTTP
  • SSH
  • HTTPS

pg_hint_plan: Commit

firtst release


Commit MetaInfo

Revisionf204d75aa3f94d46bed75b0fc9a6ab05ff1647f1 (tree)
Time2020-02-17 17:49:55
AuthorKyotaro Horiguchi <horikyota.ntt@gmai...>
CommiterKyotaro Horiguchi

Log Message

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.

Change Summary

Incremental Difference

--- a/core.c
+++ b/core.c
@@ -859,6 +859,10 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
859859 {
860860 SpecialJoinInfo *sjinfo = (SpecialJoinInfo *) lfirst(l);
861861
862+ /* ignore full joins --- their ordering is predetermined */
863+ if (sjinfo->jointype == JOIN_FULL)
864+ continue;
865+
862866 if (bms_overlap(sjinfo->min_lefthand, join_plus_rhs) &&
863867 !bms_is_subset(sjinfo->min_righthand, join_plus_rhs))
864868 {
@@ -866,15 +870,6 @@ join_is_legal(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
866870 sjinfo->min_righthand);
867871 more = true;
868872 }
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- }
878873 }
879874 } while (more);
880875 if (bms_overlap(join_plus_rhs, join_lateral_rels))
@@ -975,7 +970,8 @@ mark_dummy_rel(RelOptInfo *rel)
975970 rel->partial_pathlist = NIL;
976971
977972 /* 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,
979975 0, false, NIL, -1));
980976
981977 /* Set or update cheapest_total_path and related fields */
@@ -1056,6 +1052,8 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
10561052 RelOptInfo *joinrel, SpecialJoinInfo *parent_sjinfo,
10571053 List *parent_restrictlist)
10581054 {
1055+ bool rel1_is_simple = IS_SIMPLE_REL(rel1);
1056+ bool rel2_is_simple = IS_SIMPLE_REL(rel2);
10591057 int nparts;
10601058 int cnt_parts;
10611059
@@ -1113,6 +1111,10 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
11131111 {
11141112 RelOptInfo *child_rel1 = rel1->part_rels[cnt_parts];
11151113 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));
11161118 SpecialJoinInfo *child_sjinfo;
11171119 List *child_restrictlist;
11181120 RelOptInfo *child_joinrel;
@@ -1120,6 +1122,72 @@ try_partitionwise_join(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2,
11201122 AppendRelInfo **appinfos;
11211123 int nappinfos;
11221124
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+
11231191 /* We should never try to join two overlapping sets of rels. */
11241192 Assert(!bms_overlap(child_rel1->relids, child_rel2->relids));
11251193 child_joinrelids = bms_union(child_rel1->relids, child_rel2->relids);
--- a/output/ut-W.source
+++ b/output/ut-W.source
@@ -555,33 +555,33 @@ not used hint:
555555 duplication hint:
556556 error hint:
557557
558- QUERY PLAN
559--------------------------------------------------------
558+ QUERY PLAN
559+-------------------------------------------------
560560 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
572574 -> 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
585585 (25 rows)
586586
587587 -- Number of workers results to the largest number
@@ -799,33 +799,33 @@ not used hint:
799799 duplication hint:
800800 error hint:
801801
802- QUERY PLAN
803--------------------------------------------------------
802+ QUERY PLAN
803+-------------------------------------------------
804804 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
816818 -> 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
829829 (25 rows)
830830
831831 -- Parallel index scan
@@ -880,33 +880,33 @@ not used hint:
880880 duplication hint:
881881 error hint:
882882
883- QUERY PLAN
884------------------------------------------------------------------------------
883+ QUERY PLAN
884+-----------------------------------------------------------------------
885885 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
897899 -> 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
910910 (25 rows)
911911
912912 -- This hint doesn't turn on parallel, so the Parallel hint is ignored
Show on old repository browser