diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-10-19 15:08:37 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-10-19 15:09:23 -0400 |
commit | 6e74a91b2bf0e0032ccd60dd99d6cf47c190c428 (patch) | |
tree | ab3b16a1b02b566a71da14e298090f4d8c707dda /src/backend/parser/parse_expr.c | |
parent | 722d5beeb266ae83f548fc3953df700a71f30134 (diff) | |
download | postgresql-6e74a91b2bf0e0032ccd60dd99d6cf47c190c428.tar.gz postgresql-6e74a91b2bf0e0032ccd60dd99d6cf47c190c428.zip |
Fix incorrect generation of whole-row variables in planner.
A couple of places in the planner need to generate whole-row Vars, and were
cutting corners by setting vartype = RECORDOID in the Vars, even in cases
where there's an identifiable named composite type for the RTE being
referenced. While we mostly got away with this, it failed when there was
also a parser-generated whole-row reference to the same RTE, because the
two Vars weren't equal() due to the difference in vartype. Fix by
providing a subroutine the planner can call to generate whole-row Vars
the same way the parser does.
Per bug #5716 from Andrew Tipton. Back-patch to 9.0 where one of the bogus
calls was introduced (the other one is new in HEAD).
Diffstat (limited to 'src/backend/parser/parse_expr.c')
-rw-r--r-- | src/backend/parser/parse_expr.c | 76 |
1 files changed, 2 insertions, 74 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index e49473cc817..addd0d4fffe 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -2015,12 +2015,6 @@ transformCurrentOfExpr(ParseState *pstate, CurrentOfExpr *cexpr) /* * Construct a whole-row reference to represent the notation "relation.*". - * - * A whole-row reference is a Var with varno set to the correct range - * table entry, and varattno == 0 to signal that it references the whole - * tuple. (Use of zero here is unclean, since it could easily be confused - * with error cases, but it's not worth changing now.) The vartype indicates - * a rowtype; either a named composite type, or RECORD. */ static Node * transformWholeRowRef(ParseState *pstate, RangeTblEntry *rte, int location) @@ -2028,80 +2022,14 @@ transformWholeRowRef(ParseState *pstate, RangeTblEntry *rte, int location) Var *result; int vnum; int sublevels_up; - Oid toid; /* Find the RTE's rangetable location */ - vnum = RTERangeTablePosn(pstate, rte, &sublevels_up); /* Build the appropriate referencing node */ + result = makeWholeRowVar(rte, vnum, sublevels_up); - switch (rte->rtekind) - { - case RTE_RELATION: - /* relation: the rowtype is a named composite type */ - toid = get_rel_type_id(rte->relid); - if (!OidIsValid(toid)) - elog(ERROR, "could not find type OID for relation %u", - rte->relid); - result = makeVar(vnum, - InvalidAttrNumber, - toid, - -1, - sublevels_up); - break; - case RTE_FUNCTION: - toid = exprType(rte->funcexpr); - if (type_is_rowtype(toid)) - { - /* func returns composite; same as relation case */ - result = makeVar(vnum, - InvalidAttrNumber, - toid, - -1, - sublevels_up); - } - else - { - /* - * func returns scalar; instead of making a whole-row Var, - * just reference the function's scalar output. (XXX this - * seems a tad inconsistent, especially if "f.*" was - * explicitly written ...) - */ - result = makeVar(vnum, - 1, - toid, - -1, - sublevels_up); - } - break; - case RTE_VALUES: - toid = RECORDOID; - /* returns composite; same as relation case */ - result = makeVar(vnum, - InvalidAttrNumber, - toid, - -1, - sublevels_up); - break; - default: - - /* - * RTE is a join or subselect. We represent this as a whole-row - * Var of RECORD type. (Note that in most cases the Var will be - * expanded to a RowExpr during planning, but that is not our - * concern here.) - */ - result = makeVar(vnum, - InvalidAttrNumber, - RECORDOID, - -1, - sublevels_up); - break; - } - - /* location is not filled in by makeVar */ + /* location is not filled in by makeWholeRowVar */ result->location = location; /* mark relation as requiring whole-row SELECT access */ |