Skip to content

Commit

Permalink
Remove duplicate find_em_expr_for_rel function
Browse files Browse the repository at this point in the history
The functions find_em_expr_for_rel and ts_find_em_expr_for_rel are
identical. This patch removes find_em_expr_for_rel and changes all
call-sites to use ts_find_em_expr_for_rel.
  • Loading branch information
svenklemm committed Sep 20, 2020
1 parent 5179447 commit 78c0544
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 31 deletions.
7 changes: 7 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,13 @@ ts_get_appendrelinfo(PlannerInfo *root, Index rti, bool missing_ok)
return NULL;
}

/*
* Find an equivalence class member expression, all of whose Vars, come from
* the indicated relation.
*
* This function has been copied from find_em_expr_for_rel in
* contrib/postgres_fdw/postgres_fdw.c in postgres source.
*/
Expr *
ts_find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
{
Expand Down
30 changes: 1 addition & 29 deletions tsl/src/fdw/deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,34 +212,6 @@ static bool is_subquery_var(Var *node, RelOptInfo *foreignrel, int *relno, int *
static void get_relation_column_alias_ids(Var *node, RelOptInfo *foreignrel, int *relno,
int *colno);

/*
* Find an equivalence class member expression, all of whose Vars, come from
* the indicated relation.
*/
extern Expr *
find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel)
{
ListCell *lc_em;

foreach (lc_em, ec->ec_members)
{
EquivalenceMember *em = lfirst(lc_em);

if (bms_is_subset(em->em_relids, rel->relids))
{
/*
* If there is more than one equivalence member whose Vars are
* taken entirely from this relation, we'll be content to choose
* any one of those.
*/
return em->em_expr;
}
}

/* We didn't find any suitable equivalence class expression */
return NULL;
}

/*
* Examine each qual clause in input_conds, and classify them into two groups,
* which are returned as two lists:
Expand Down Expand Up @@ -2799,7 +2771,7 @@ appendOrderByClause(List *pathkeys, deparse_expr_cxt *context)
PathKey *pathkey = lfirst(lcell);
Expr *em_expr;

em_expr = find_em_expr_for_rel(pathkey->pk_eclass, baserel);
em_expr = ts_find_em_expr_for_rel(pathkey->pk_eclass, baserel);
Assert(em_expr != NULL);

appendStringInfoString(buf, delim);
Expand Down
1 change: 0 additions & 1 deletion tsl/src/fdw/deparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ typedef struct DeparsedInsertStmt
List *retrieved_attrs;
} DeparsedInsertStmt;

extern Expr *find_em_expr_for_rel(EquivalenceClass *ec, RelOptInfo *rel);
extern void deparse_insert_stmt(DeparsedInsertStmt *stmt, RangeTblEntry *rte, Index rtindex,
Relation rel, List *target_attrs, bool do_nothing,
List *returning_list);
Expand Down
2 changes: 1 addition & 1 deletion tsl/src/fdw/scan_plan.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ get_useful_pathkeys_for_relation(PlannerInfo *root, RelOptInfo *rel)
* is_foreign_expr would detect volatile expressions as well, but
* checking ec_has_volatile here saves some cycles.
*/
if (pathkey_ec->ec_has_volatile || !(em_expr = find_em_expr_for_rel(pathkey_ec, rel)) ||
if (pathkey_ec->ec_has_volatile || !(em_expr = ts_find_em_expr_for_rel(pathkey_ec, rel)) ||
!is_foreign_expr(root, rel, em_expr))
{
query_pathkeys_ok = false;
Expand Down

0 comments on commit 78c0544

Please sign in to comment.