summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/relnode.c
diff options
context:
space:
mode:
authorRobert Haas <rhaas@postgresql.org>2017-08-15 12:30:38 -0400
committerRobert Haas <rhaas@postgresql.org>2017-08-15 12:30:38 -0400
commite139f1953f29db245f60a7acb72fccb1e05d2442 (patch)
tree783ae7f36a8066e9057d5ee275d5cc97870f8ee3 /src/backend/optimizer/util/relnode.c
parent00418c61244138bd8ac2de58076a1d0dd4f539f3 (diff)
Assorted preparatory refactoring for partition-wise join.
Instead of duplicating the logic to search for a matching ParamPathInfo in multiple places, factor it out into a separate function. Pass only the relevant bits of the PartitionKey to partition_bounds_equal instead of the whole thing, because partition-wise join will want to call this without having a PartitionKey available. Adjust allow_star_schema_join and calc_nestloop_required_outer to take relevant Relids rather than the entire Path, because partition-wise join will want to call it with the top-parent relids to determine whether a child join is allowable. Ashutosh Bapat. Review and testing of the larger patch set of which this is a part by Amit Langote, Rajkumar Raghuwanshi, Rafia Sabih, Thomas Munro, Dilip Kumar, and me. Discussion: http://postgr.es/m/CA+TgmobQK80vtXjAsPZWWXd7c8u13G86gmuLupN+uUJjA+i4nA@mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/util/relnode.c')
-rw-r--r--src/backend/optimizer/util/relnode.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c
index c8e2b67da42..8ad0b4a6697 100644
--- a/src/backend/optimizer/util/relnode.c
+++ b/src/backend/optimizer/util/relnode.c
@@ -1048,12 +1048,8 @@ get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel,
Assert(!bms_overlap(baserel->relids, required_outer));
/* If we already have a PPI for this parameterization, just return it */
- foreach(lc, baserel->ppilist)
- {
- ppi = (ParamPathInfo *) lfirst(lc);
- if (bms_equal(ppi->ppi_req_outer, required_outer))
- return ppi;
- }
+ if ((ppi = find_param_path_info(baserel, required_outer)))
+ return ppi;
/*
* Identify all joinclauses that are movable to this base rel given this
@@ -1290,12 +1286,8 @@ get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel,
*restrict_clauses = list_concat(pclauses, *restrict_clauses);
/* If we already have a PPI for this parameterization, just return it */
- foreach(lc, joinrel->ppilist)
- {
- ppi = (ParamPathInfo *) lfirst(lc);
- if (bms_equal(ppi->ppi_req_outer, required_outer))
- return ppi;
- }
+ if ((ppi = find_param_path_info(joinrel, required_outer)))
+ return ppi;
/* Estimate the number of rows returned by the parameterized join */
rows = get_parameterized_joinrel_size(root, joinrel,
@@ -1334,7 +1326,6 @@ ParamPathInfo *
get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
{
ParamPathInfo *ppi;
- ListCell *lc;
/* Unparameterized paths have no ParamPathInfo */
if (bms_is_empty(required_outer))
@@ -1343,12 +1334,8 @@ get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Assert(!bms_overlap(appendrel->relids, required_outer));
/* If we already have a PPI for this parameterization, just return it */
- foreach(lc, appendrel->ppilist)
- {
- ppi = (ParamPathInfo *) lfirst(lc);
- if (bms_equal(ppi->ppi_req_outer, required_outer))
- return ppi;
- }
+ if ((ppi = find_param_path_info(appendrel, required_outer)))
+ return ppi;
/* Else build the ParamPathInfo */
ppi = makeNode(ParamPathInfo);
@@ -1359,3 +1346,23 @@ get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
return ppi;
}
+
+/*
+ * Returns a ParamPathInfo for the parameterization given by required_outer, if
+ * already available in the given rel. Returns NULL otherwise.
+ */
+ParamPathInfo *
+find_param_path_info(RelOptInfo *rel, Relids required_outer)
+{
+ ListCell *lc;
+
+ foreach(lc, rel->ppilist)
+ {
+ ParamPathInfo *ppi = (ParamPathInfo *) lfirst(lc);
+
+ if (bms_equal(ppi->ppi_req_outer, required_outer))
+ return ppi;
+ }
+
+ return NULL;
+}