From ec2984ab4ea387d5e91fbd354209ff45f114b603 Mon Sep 17 00:00:00 2001 From: Ashutosh Bapat Date: Mon, 6 Feb 2017 12:14:06 +0530 Subject: [PATCH 05/11] Add function find_param_path_info. The code to search ParamPathInfo for a set of required outer relations in the list of ParamPathInfos of a given relation is duplicated in get_*rel_parampathinfo() functions. Separate this code into find_param_path_info() and call it from get_*rel_parampathinfo() functions. --- src/backend/optimizer/util/relnode.c | 46 ++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/backend/optimizer/util/relnode.c b/src/backend/optimizer/util/relnode.c index 160ed6d..19982dc 100644 --- a/src/backend/optimizer/util/relnode.c +++ b/src/backend/optimizer/util/relnode.c @@ -52,6 +52,8 @@ static List *subbuild_joinrel_joinlist(RelOptInfo *joinrel, static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel); static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel); +extern ParamPathInfo *find_param_path_info(RelOptInfo *rel, + Relids required_outer); /* @@ -1047,12 +1049,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 @@ -1289,12 +1287,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, @@ -1333,7 +1327,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)) @@ -1342,12 +1335,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); @@ -1358,3 +1347,22 @@ get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer) return ppi; } + +/* + * Returns a ParamPathInfo for outer relations specified 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; +} -- 1.7.9.5