Location for "makeWholeRowVar()"?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Location for "makeWholeRowVar()"?
Дата
Msg-id 28198.1287508150@sss.pgh.pa.us
обсуждение исходный текст
Список pgsql-hackers
The cause of bug #5716 is that preprocess_targetlist is trying to get
away with creating a whole-row variable marked with type RECORDOID,
even in cases where a specific composite type is known for the
referenced RTE.  This fails because now we might have non-equal Vars
representing the same RTE attribute in different places in the same
query.

I think the best fix for this is to have one and only one function
generating whole-row Vars, which means pulling out the guts of the
parser's transformWholeRowRef() function into a function that looks
like the attached.  Now I'm wondering where to put it.  I'm tempted
to put it into makefuncs.c next to makeVar(), and it fits there without
needing to add any new #includes; but it looks a tad more complicated
than most other functions in makefuncs.c.  Does anyone think this is
a bad place for it, and if so where would you put it instead?
        regards, tom lane



/** makeWholeRowVar -*      creates a Var node representing a whole row from the specified RTE*/
Var *
makeWholeRowVar(RangeTblEntry *rte,            Index varno,            Index varlevelsup)
{Var           *result;Oid            toid;
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(varno,                         InvalidAttrNumber,
          toid,                         -1,                         varlevelsup);        break;    case RTE_FUNCTION:
    toid = exprType(rte->funcexpr);        if (type_is_rowtype(toid))        {            /* func returns composite;
sameas relation case */            result = makeVar(varno,                             InvalidAttrNumber,
             toid,                             -1,                             varlevelsup);        }        else
{            /*             * func returns scalar; instead of making a whole-row Var,             * just reference the
function'sscalar output.  (XXX this             * seems a tad inconsistent, especially if "f.*" was             *
explicitlywritten ...)             */            result = makeVar(varno,                             1,
           toid,                             -1,                             varlevelsup);        }        break;
caseRTE_VALUES:        toid = RECORDOID;        /* returns composite; same as relation case */        result =
makeVar(varno,                        InvalidAttrNumber,                         toid,                         -1,
                  varlevelsup);        break;    default:
 
        /*         * RTE is a join or subselect.    We represent this as a whole-row         * Var of RECORD type.
(Notethat in most cases the Var will be         * expanded to a RowExpr during planning, but that is not our         *
concernhere.)         */        result = makeVar(varno,                         InvalidAttrNumber,
  RECORDOID,                         -1,                         varlevelsup);        break;}
 
return result;
}


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: Re: WIP: extensible enums
Следующее
От: Marios Vodas
Дата:
Сообщение: Re: knngist plans