diff --git a/src/backend/nodes/makefuncs.c b/src/backend/nodes/makefuncs.c index 5550f706b18c23a8a1d50472018b7b0220e21968..60c9a63a13f1fb543144637dff6b95b9c719cfa2 100644 --- a/src/backend/nodes/makefuncs.c +++ b/src/backend/nodes/makefuncs.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.66 2010/01/02 16:57:46 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/nodes/makefuncs.c,v 1.67 2010/08/27 20:30:07 petere Exp $ * *------------------------------------------------------------------------- */ @@ -17,6 +17,7 @@ #include "catalog/pg_type.h" #include "nodes/makefuncs.h" +#include "nodes/nodeFuncs.h" #include "utils/lsyscache.h" @@ -90,6 +91,22 @@ makeVar(Index varno, return var; } +/* + * makeVarFromTargetEntry - + * convenience function to create a same-level Var node from a + * TargetEntry + */ +Var * +makeVarFromTargetEntry(Index varno, + TargetEntry *tle) +{ + return makeVar(varno, + tle->resno, + exprType((Node *) tle->expr), + exprTypmod((Node *) tle->expr), + 0); +} + /* * makeTargetEntry - * creates a TargetEntry node diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index 3f0c2fe90404c269d0511f7013ce1175e148f35c..fa7ad6544bc7294ba3410a6b5ac82591fbd78a0c 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.101 2010/02/26 02:00:45 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/pathkeys.c,v 1.102 2010/08/27 20:30:08 petere Exp $ * *------------------------------------------------------------------------- */ @@ -629,12 +629,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, Assert(list_length(sub_eclass->ec_members) == 1); sub_member = (EquivalenceMember *) linitial(sub_eclass->ec_members); - outer_expr = (Expr *) - makeVar(rel->relid, - tle->resno, - exprType((Node *) tle->expr), - exprTypmod((Node *) tle->expr), - 0); + outer_expr = (Expr *) makeVarFromTargetEntry(rel->relid, tle); /* * Note: it might look funny to be setting sortref = 0 for a @@ -712,12 +707,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, if (equal(tle->expr, sub_expr)) { /* Exact match */ - outer_expr = (Expr *) - makeVar(rel->relid, - tle->resno, - exprType((Node *) tle->expr), - exprTypmod((Node *) tle->expr), - 0); + outer_expr = (Expr *) makeVarFromTargetEntry(rel->relid, tle); } else { @@ -730,12 +720,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, if (equal(tle_stripped, sub_stripped)) { /* Match after discarding RelabelType */ - outer_expr = (Expr *) - makeVar(rel->relid, - tle->resno, - exprType((Node *) tle->expr), - exprTypmod((Node *) tle->expr), - 0); + outer_expr = (Expr *) makeVarFromTargetEntry(rel->relid, tle); if (exprType((Node *) outer_expr) != exprType((Node *) sub_expr)) outer_expr = (Expr *) diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index 450970e5c37a07a6a33d44085c26a6008cbec6e7..3fda3fbb1c86473cb84f828cf1dd0631a2a024ae 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.161 2010/07/12 17:01:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/setrefs.c,v 1.162 2010/08/27 20:30:08 petere Exp $ * *------------------------------------------------------------------------- */ @@ -1283,11 +1283,7 @@ search_indexed_tlist_for_non_var(Node *node, /* Found a matching subplan output expression */ Var *newvar; - newvar = makeVar(newvarno, - tle->resno, - exprType((Node *) tle->expr), - exprTypmod((Node *) tle->expr), - 0); + newvar = makeVarFromTargetEntry(newvarno, tle); newvar->varnoold = 0; /* wasn't ever a plain Var */ newvar->varoattno = 0; return newvar; @@ -1325,11 +1321,7 @@ search_indexed_tlist_for_sortgroupref(Node *node, /* Found a matching subplan output expression */ Var *newvar; - newvar = makeVar(newvarno, - tle->resno, - exprType((Node *) tle->expr), - exprTypmod((Node *) tle->expr), - 0); + newvar = makeVarFromTargetEntry(newvarno, tle); newvar->varnoold = 0; /* wasn't ever a plain Var */ newvar->varoattno = 0; return newvar; diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index b94419a09dc20c10b090d0bbc7a0b7b1a76f7e26..18336ca726cd2952bac19e0c75aa70913d57587a 100644 --- a/src/backend/optimizer/plan/subselect.c +++ b/src/backend/optimizer/plan/subselect.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.163 2010/07/12 17:01:06 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.164 2010/08/27 20:30:08 petere Exp $ * *------------------------------------------------------------------------- */ @@ -737,11 +737,7 @@ generate_subquery_vars(PlannerInfo *root, List *tlist, Index varno) if (tent->resjunk) continue; - var = makeVar(varno, - tent->resno, - exprType((Node *) tent->expr), - exprTypmod((Node *) tent->expr), - 0); + var = makeVarFromTargetEntry(varno, tent); result = lappend(result, var); } diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c index dbe7836b4235df8db3920f8086338166e03a5aa7..c2eff7ae06ba6e0c7667275a082cc9d42ad7fc4c 100644 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@ -16,7 +16,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.73 2010/07/06 19:18:56 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.74 2010/08/27 20:30:08 petere Exp $ * *------------------------------------------------------------------------- */ @@ -991,11 +991,7 @@ make_setop_translation_list(Query *query, Index newvarno, if (tle->resjunk) continue; - vars = lappend(vars, makeVar(newvarno, - tle->resno, - exprType((Node *) tle->expr), - exprTypmod((Node *) tle->expr), - 0)); + vars = lappend(vars, makeVarFromTargetEntry(newvarno, tle)); } *translated_vars = vars; diff --git a/src/backend/optimizer/util/plancat.c b/src/backend/optimizer/util/plancat.c index 10800b488f6fe9df1630fdcdd405c658c32b0be5..f39b4de71fee6d0758c724f833e05ece13b01a2d 100644 --- a/src/backend/optimizer/util/plancat.c +++ b/src/backend/optimizer/util/plancat.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.163 2010/03/30 21:58:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/util/plancat.c,v 1.164 2010/08/27 20:30:08 petere Exp $ * *------------------------------------------------------------------------- */ @@ -727,11 +727,7 @@ build_physical_tlist(PlannerInfo *root, RelOptInfo *rel) * A resjunk column of the subquery can be reflected as * resjunk in the physical tlist; we need not punt. */ - var = makeVar(varno, - tle->resno, - exprType((Node *) tle->expr), - exprTypmod((Node *) tle->expr), - 0); + var = makeVarFromTargetEntry(varno, tle); tlist = lappend(tlist, makeTargetEntry((Expr *) var, diff --git a/src/backend/parser/analyze.c b/src/backend/parser/analyze.c index 1576613bc1a6193f155ae8752e4f4562f72170df..62d8ad5d7149338b24fac4a445f5c41c6d741a31 100644 --- a/src/backend/parser/analyze.c +++ b/src/backend/parser/analyze.c @@ -17,7 +17,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.402 2010/02/26 02:00:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/parser/analyze.c,v 1.403 2010/08/27 20:30:08 petere Exp $ * *------------------------------------------------------------------------- */ @@ -484,11 +484,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt) expr = tle->expr; else { - Var *var = makeVar(rtr->rtindex, - tle->resno, - exprType((Node *) tle->expr), - exprTypmod((Node *) tle->expr), - 0); + Var *var = makeVarFromTargetEntry(rtr->rtindex, tle); var->location = exprLocation((Node *) tle->expr); expr = (Expr *) var; diff --git a/src/include/nodes/makefuncs.h b/src/include/nodes/makefuncs.h index c4e7385c48dcdf9b392e4228db174e1855ea4cad..bf28a30086344b9a7d888d2855d5bc402e1ed723 100644 --- a/src/include/nodes/makefuncs.h +++ b/src/include/nodes/makefuncs.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/nodes/makefuncs.h,v 1.70 2010/01/02 16:58:04 momjian Exp $ + * $PostgreSQL: pgsql/src/include/nodes/makefuncs.h,v 1.71 2010/08/27 20:30:08 petere Exp $ * *------------------------------------------------------------------------- */ @@ -29,6 +29,9 @@ extern Var *makeVar(Index varno, int32 vartypmod, Index varlevelsup); +extern Var *makeVarFromTargetEntry(Index varno, + TargetEntry *tle); + extern TargetEntry *makeTargetEntry(Expr *expr, AttrNumber resno, char *resname,