Commit 2355b69b authored by Peter Eisentraut's avatar Peter Eisentraut

Small refactoring of makeVar() from a TargetEntry

parent c10575ff
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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 @@ ...@@ -17,6 +17,7 @@
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
...@@ -90,6 +91,22 @@ makeVar(Index varno, ...@@ -90,6 +91,22 @@ makeVar(Index varno,
return var; 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 - * makeTargetEntry -
* creates a TargetEntry node * creates a TargetEntry node
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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, ...@@ -629,12 +629,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
Assert(list_length(sub_eclass->ec_members) == 1); Assert(list_length(sub_eclass->ec_members) == 1);
sub_member = (EquivalenceMember *) linitial(sub_eclass->ec_members); sub_member = (EquivalenceMember *) linitial(sub_eclass->ec_members);
outer_expr = (Expr *) outer_expr = (Expr *) makeVarFromTargetEntry(rel->relid, tle);
makeVar(rel->relid,
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
0);
/* /*
* Note: it might look funny to be setting sortref = 0 for a * Note: it might look funny to be setting sortref = 0 for a
...@@ -712,12 +707,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, ...@@ -712,12 +707,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
if (equal(tle->expr, sub_expr)) if (equal(tle->expr, sub_expr))
{ {
/* Exact match */ /* Exact match */
outer_expr = (Expr *) outer_expr = (Expr *) makeVarFromTargetEntry(rel->relid, tle);
makeVar(rel->relid,
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
0);
} }
else else
{ {
...@@ -730,12 +720,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, ...@@ -730,12 +720,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
if (equal(tle_stripped, sub_stripped)) if (equal(tle_stripped, sub_stripped))
{ {
/* Match after discarding RelabelType */ /* Match after discarding RelabelType */
outer_expr = (Expr *) outer_expr = (Expr *) makeVarFromTargetEntry(rel->relid, tle);
makeVar(rel->relid,
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
0);
if (exprType((Node *) outer_expr) != if (exprType((Node *) outer_expr) !=
exprType((Node *) sub_expr)) exprType((Node *) sub_expr))
outer_expr = (Expr *) outer_expr = (Expr *)
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -1283,11 +1283,7 @@ search_indexed_tlist_for_non_var(Node *node,
/* Found a matching subplan output expression */ /* Found a matching subplan output expression */
Var *newvar; Var *newvar;
newvar = makeVar(newvarno, newvar = makeVarFromTargetEntry(newvarno, tle);
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
0);
newvar->varnoold = 0; /* wasn't ever a plain Var */ newvar->varnoold = 0; /* wasn't ever a plain Var */
newvar->varoattno = 0; newvar->varoattno = 0;
return newvar; return newvar;
...@@ -1325,11 +1321,7 @@ search_indexed_tlist_for_sortgroupref(Node *node, ...@@ -1325,11 +1321,7 @@ search_indexed_tlist_for_sortgroupref(Node *node,
/* Found a matching subplan output expression */ /* Found a matching subplan output expression */
Var *newvar; Var *newvar;
newvar = makeVar(newvarno, newvar = makeVarFromTargetEntry(newvarno, tle);
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
0);
newvar->varnoold = 0; /* wasn't ever a plain Var */ newvar->varnoold = 0; /* wasn't ever a plain Var */
newvar->varoattno = 0; newvar->varoattno = 0;
return newvar; return newvar;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * 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) ...@@ -737,11 +737,7 @@ generate_subquery_vars(PlannerInfo *root, List *tlist, Index varno)
if (tent->resjunk) if (tent->resjunk)
continue; continue;
var = makeVar(varno, var = makeVarFromTargetEntry(varno, tent);
tent->resno,
exprType((Node *) tent->expr),
exprTypmod((Node *) tent->expr),
0);
result = lappend(result, var); result = lappend(result, var);
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* *
* IDENTIFICATION * 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, ...@@ -991,11 +991,7 @@ make_setop_translation_list(Query *query, Index newvarno,
if (tle->resjunk) if (tle->resjunk)
continue; continue;
vars = lappend(vars, makeVar(newvarno, vars = lappend(vars, makeVarFromTargetEntry(newvarno, tle));
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
0));
} }
*translated_vars = vars; *translated_vars = vars;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * 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) ...@@ -727,11 +727,7 @@ build_physical_tlist(PlannerInfo *root, RelOptInfo *rel)
* A resjunk column of the subquery can be reflected as * A resjunk column of the subquery can be reflected as
* resjunk in the physical tlist; we need not punt. * resjunk in the physical tlist; we need not punt.
*/ */
var = makeVar(varno, var = makeVarFromTargetEntry(varno, tle);
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
0);
tlist = lappend(tlist, tlist = lappend(tlist,
makeTargetEntry((Expr *) var, makeTargetEntry((Expr *) var,
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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) ...@@ -484,11 +484,7 @@ transformInsertStmt(ParseState *pstate, InsertStmt *stmt)
expr = tle->expr; expr = tle->expr;
else else
{ {
Var *var = makeVar(rtr->rtindex, Var *var = makeVarFromTargetEntry(rtr->rtindex, tle);
tle->resno,
exprType((Node *) tle->expr),
exprTypmod((Node *) tle->expr),
0);
var->location = exprLocation((Node *) tle->expr); var->location = exprLocation((Node *) tle->expr);
expr = (Expr *) var; expr = (Expr *) var;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * 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, ...@@ -29,6 +29,9 @@ extern Var *makeVar(Index varno,
int32 vartypmod, int32 vartypmod,
Index varlevelsup); Index varlevelsup);
extern Var *makeVarFromTargetEntry(Index varno,
TargetEntry *tle);
extern TargetEntry *makeTargetEntry(Expr *expr, extern TargetEntry *makeTargetEntry(Expr *expr,
AttrNumber resno, AttrNumber resno,
char *resname, char *resname,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment