From 7a39b5e4d11229ece930a51fd7cb29e535db4494 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Mon, 3 Apr 2017 22:41:31 -0400 Subject: Abstract logic to allow for multiple kinds of child rels. Currently, the only type of child relation is an "other member rel", which is the child of a baserel, but in the future joins and even upper relations may have child rels. To facilitate that, introduce macros that test to test for particular RelOptKind values, and use them in various places where they help to clarify the sense of a test. (For example, a test may allow RELOPT_OTHER_MEMBER_REL either because it intends to allow child rels, or because it intends to allow simple rels.) Also, remove find_childrel_top_parent, which will not work for a child rel that is not a baserel. Instead, add a new RelOptInfo member top_parent_relids to track the same kind of information in a more generic manner. Ashutosh Bapat, slightly tweaked by me. Review and testing of the patch set from which this was taken by Rajkumar Raghuwanshi and Rafia Sabih. Discussion: http://postgr.es/m/CA+TgmoagTnF2yqR3PT2rv=om=wJiZ4-A+ATwdnriTGku1CLYxA@mail.gmail.com --- contrib/postgres_fdw/postgres_fdw.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'contrib/postgres_fdw/postgres_fdw.c') diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 54b938734a8..2851869932d 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -729,8 +729,11 @@ get_useful_ecs_for_relation(PlannerInfo *root, RelOptInfo *rel) return useful_eclass_list; /* If this is a child rel, we must use the topmost parent rel to search. */ - if (rel->reloptkind == RELOPT_OTHER_MEMBER_REL) - relids = find_childrel_top_parent(root, rel)->relids; + if (IS_OTHER_REL(rel)) + { + Assert(!bms_is_empty(rel->top_parent_relids)); + relids = rel->top_parent_relids; + } else relids = rel->relids; @@ -1129,8 +1132,7 @@ postgresGetForeignPlan(PlannerInfo *root, * For base relations, set scan_relid as the relid of the relation. For * other kinds of relations set it to 0. */ - if (foreignrel->reloptkind == RELOPT_BASEREL || - foreignrel->reloptkind == RELOPT_OTHER_MEMBER_REL) + if (IS_SIMPLE_REL(foreignrel)) scan_relid = foreignrel->relid; else { @@ -1189,8 +1191,7 @@ postgresGetForeignPlan(PlannerInfo *root, local_exprs = lappend(local_exprs, rinfo->clause); } - if (foreignrel->reloptkind == RELOPT_JOINREL || - foreignrel->reloptkind == RELOPT_UPPER_REL) + if (IS_JOIN_REL(foreignrel) || IS_UPPER_REL(foreignrel)) { /* For a join relation, get the conditions from fdw_private structure */ remote_conds = fpinfo->remote_conds; @@ -1216,7 +1217,7 @@ postgresGetForeignPlan(PlannerInfo *root, * joins. Queries involving aggregates or grouping do not require * EPQ mechanism, hence should not have an outer plan here. */ - Assert(foreignrel->reloptkind != RELOPT_UPPER_REL); + Assert(!IS_UPPER_REL(foreignrel)); outer_plan->targetlist = fdw_scan_tlist; @@ -1255,8 +1256,7 @@ postgresGetForeignPlan(PlannerInfo *root, remote_conds, retrieved_attrs, makeInteger(fpinfo->fetch_size)); - if (foreignrel->reloptkind == RELOPT_JOINREL || - foreignrel->reloptkind == RELOPT_UPPER_REL) + if (IS_JOIN_REL(foreignrel) || IS_UPPER_REL(foreignrel)) fdw_private = lappend(fdw_private, makeString(fpinfo->relation_name->data)); @@ -2535,8 +2535,7 @@ estimate_path_cost_size(PlannerInfo *root, &remote_param_join_conds, &local_param_join_conds); /* Build the list of columns to be fetched from the foreign server. */ - if (foreignrel->reloptkind == RELOPT_JOINREL || - foreignrel->reloptkind == RELOPT_UPPER_REL) + if (IS_JOIN_REL(foreignrel) || IS_UPPER_REL(foreignrel)) fdw_scan_tlist = build_tlist_to_deparse(foreignrel); else fdw_scan_tlist = NIL; @@ -2617,7 +2616,7 @@ estimate_path_cost_size(PlannerInfo *root, startup_cost = fpinfo->rel_startup_cost; run_cost = fpinfo->rel_total_cost - fpinfo->rel_startup_cost; } - else if (foreignrel->reloptkind == RELOPT_JOINREL) + else if (IS_JOIN_REL(foreignrel)) { PgFdwRelationInfo *fpinfo_i; PgFdwRelationInfo *fpinfo_o; @@ -2683,7 +2682,7 @@ estimate_path_cost_size(PlannerInfo *root, run_cost += nrows * remote_conds_cost.per_tuple; run_cost += fpinfo->local_conds_cost.per_tuple * retrieved_rows; } - else if (foreignrel->reloptkind == RELOPT_UPPER_REL) + else if (IS_UPPER_REL(foreignrel)) { PgFdwRelationInfo *ofpinfo; PathTarget *ptarget = root->upper_targets[UPPERREL_GROUP_AGG]; -- cgit v1.2.3