OSDN Git Service

Change copyright year to 2020.
[pghintplan/pg_hint_plan.git] / make_join_rel.c
index e98b64e..863fbd7 100644 (file)
@@ -1,13 +1,14 @@
 /*-------------------------------------------------------------------------
  *
  * make_join_rel.c
- *       Routines copied from PostgreSQL core distribution.
+ *       Routines copied from PostgreSQL core distribution with some
+ *       modifications.
  *
  * src/backend/optimizer/path/joinrels.c
  *     make_join_rel()
  *
- * Portions Copyright (c) 2013-2014, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
- * Portions Copyright (c) 1996-2012, PostgreSQL Global Development Group
+ * Portions Copyright (c) 2013-2020, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
+ * Portions Copyright (c) 1996-2020, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *-------------------------------------------------------------------------
@@ -15,7 +16,7 @@
 
 /*
  * adjust_rows: tweak estimated row numbers according to the hint.
-*/
+ */
 static double
 adjust_rows(double rows, RowsHint *hint)
 {
@@ -106,7 +107,10 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                /* we don't bother trying to make the remaining fields valid */
                sjinfo->lhs_strict = false;
                sjinfo->delay_upper_joins = false;
-               sjinfo->join_quals = NIL;
+               sjinfo->semi_can_btree = false;
+               sjinfo->semi_can_hash = false;
+               sjinfo->semi_operators = NIL;
+               sjinfo->semi_rhs_exprs = NIL;
        }
 
        /*
@@ -124,9 +128,9 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                RowsHint   *domultiply = NULL;
 
                /* Search for applicable rows hint for this join node */
-               for (i = 0; i < current_hint->num_hints[HINT_TYPE_ROWS]; i++)
+               for (i = 0; i < current_hint_state->num_hints[HINT_TYPE_ROWS]; i++)
                {
-                       rows_hint = current_hint->rows_hints[i];
+                       rows_hint = current_hint_state->rows_hints[i];
 
                        /*
                         * Skip this rows_hint if it is invalid from the first or it
@@ -204,6 +208,27 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                return joinrel;
        }
 
+       /* Add paths to the join relation. */
+       populate_joinrel_with_paths(root, rel1, rel2, joinrel, sjinfo,
+                                                               restrictlist);
+
+       bms_free(joinrelids);
+
+       return joinrel;
+}
+
+/*
+ * populate_joinrel_with_paths
+ *       Add paths to the given joinrel for given pair of joining relations. The
+ *       SpecialJoinInfo provides details about the join and the restrictlist
+ *       contains the join clauses and the other clauses applicable for given pair
+ *       of the joining relations.
+ */
+static void
+populate_joinrel_with_paths(PlannerInfo *root, RelOptInfo *rel1,
+                                                       RelOptInfo *rel2, RelOptInfo *joinrel,
+                                                       SpecialJoinInfo *sjinfo, List *restrictlist)
+{
        /*
         * Consider paths using each rel as both outer and inner.  Depending on
         * the join type, a provably empty outer or inner rel might mean the join
@@ -226,7 +251,7 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
        {
                case JOIN_INNER:
                        if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
-                               restriction_is_constant_false(restrictlist, false))
+                               restriction_is_constant_false(restrictlist, joinrel, false))
                        {
                                mark_dummy_rel(joinrel);
                                break;
@@ -240,12 +265,12 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                        break;
                case JOIN_LEFT:
                        if (is_dummy_rel(rel1) ||
-                               restriction_is_constant_false(restrictlist, true))
+                               restriction_is_constant_false(restrictlist, joinrel, true))
                        {
                                mark_dummy_rel(joinrel);
                                break;
                        }
-                       if (restriction_is_constant_false(restrictlist, false) &&
+                       if (restriction_is_constant_false(restrictlist, joinrel, false) &&
                                bms_is_subset(rel2->relids, sjinfo->syn_righthand))
                                mark_dummy_rel(rel2);
                        add_paths_to_joinrel(root, joinrel, rel1, rel2,
@@ -257,7 +282,7 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                        break;
                case JOIN_FULL:
                        if ((is_dummy_rel(rel1) && is_dummy_rel(rel2)) ||
-                               restriction_is_constant_false(restrictlist, true))
+                               restriction_is_constant_false(restrictlist, joinrel, true))
                        {
                                mark_dummy_rel(joinrel);
                                break;
@@ -293,7 +318,7 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                                bms_is_subset(sjinfo->min_righthand, rel2->relids))
                        {
                                if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
-                                       restriction_is_constant_false(restrictlist, false))
+                                       restriction_is_constant_false(restrictlist, joinrel, false))
                                {
                                        mark_dummy_rel(joinrel);
                                        break;
@@ -316,7 +341,7 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                                                                   sjinfo) != NULL)
                        {
                                if (is_dummy_rel(rel1) || is_dummy_rel(rel2) ||
-                                       restriction_is_constant_false(restrictlist, false))
+                                       restriction_is_constant_false(restrictlist, joinrel, false))
                                {
                                        mark_dummy_rel(joinrel);
                                        break;
@@ -331,12 +356,12 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                        break;
                case JOIN_ANTI:
                        if (is_dummy_rel(rel1) ||
-                               restriction_is_constant_false(restrictlist, true))
+                               restriction_is_constant_false(restrictlist, joinrel, true))
                        {
                                mark_dummy_rel(joinrel);
                                break;
                        }
-                       if (restriction_is_constant_false(restrictlist, false) &&
+                       if (restriction_is_constant_false(restrictlist, joinrel, false) &&
                                bms_is_subset(rel2->relids, sjinfo->syn_righthand))
                                mark_dummy_rel(rel2);
                        add_paths_to_joinrel(root, joinrel, rel1, rel2,
@@ -349,7 +374,6 @@ make_join_rel(PlannerInfo *root, RelOptInfo *rel1, RelOptInfo *rel2)
                        break;
        }
 
-       bms_free(joinrelids);
-
-       return joinrel;
+       /* Apply partitionwise join technique, if possible. */
+       try_partitionwise_join(root, rel1, rel2, joinrel, sjinfo, restrictlist);
 }