mirror of
https://github.com/postgres/postgres.git
synced 2025-11-16 15:02:33 +03:00
Merge Resdom nodes into TargetEntry nodes to simplify code and save a
few palloc's. I also chose to eliminate the restype and restypmod fields entirely, since they are redundant with information stored in the node's contained expression; re-examining the expression at need seems simpler and more reliable than trying to keep restype/restypmod up to date. initdb forced due to change in contents of stored rules.
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.106 2004/12/31 22:03:34 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/include/nodes/primnodes.h,v 1.107 2005/04/06 16:34:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -27,72 +27,6 @@
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*--------------------
|
||||
* Resdom (Result Domain)
|
||||
*
|
||||
* Notes:
|
||||
*
|
||||
* In a SELECT's targetlist, resno should always be equal to the item's
|
||||
* ordinal position (counting from 1). However, in an INSERT or UPDATE
|
||||
* targetlist, resno represents the attribute number of the destination
|
||||
* column for the item; so there may be missing or out-of-order resnos.
|
||||
* It is even legal to have duplicated resnos; consider
|
||||
* UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ...
|
||||
* The two meanings come together in the executor, because the planner
|
||||
* transforms INSERT/UPDATE tlists into a normalized form with exactly
|
||||
* one entry for each column of the destination table. Before that's
|
||||
* happened, however, it is risky to assume that resno == position.
|
||||
* Generally get_tle_by_resno() should be used rather than list_nth()
|
||||
* to fetch tlist entries by resno, and only in SELECT should you assume
|
||||
* that resno is a unique identifier.
|
||||
*
|
||||
* resname is required to represent the correct column name in non-resjunk
|
||||
* entries of top-level SELECT targetlists, since it will be used as the
|
||||
* column title sent to the frontend. In most other contexts it is only
|
||||
* a debugging aid, and may be wrong or even NULL. (In particular, it may
|
||||
* be wrong in a tlist from a stored rule, if the referenced column has been
|
||||
* renamed by ALTER TABLE since the rule was made. Also, the planner tends
|
||||
* to store NULL rather than look up a valid name for tlist entries in
|
||||
* non-toplevel plan nodes.) In resjunk entries, resname should be either
|
||||
* a specific system-generated name (such as "ctid") or NULL; anything else
|
||||
* risks confusing ExecGetJunkAttribute!
|
||||
*
|
||||
* ressortgroupref is used in the representation of ORDER BY and
|
||||
* GROUP BY items. Targetlist entries with ressortgroupref=0 are not
|
||||
* sort/group items. If ressortgroupref>0, then this item is an ORDER BY or
|
||||
* GROUP BY value. No two entries in a targetlist may have the same nonzero
|
||||
* ressortgroupref --- but there is no particular meaning to the nonzero
|
||||
* values, except as tags. (For example, one must not assume that lower
|
||||
* ressortgroupref means a more significant sort key.) The order of the
|
||||
* associated SortClause or GroupClause lists determine the semantics.
|
||||
*
|
||||
* resorigtbl/resorigcol identify the source of the column, if it is a
|
||||
* simple reference to a column of a base table (or view). If it is not
|
||||
* a simple reference, these fields are zeroes.
|
||||
*
|
||||
* If resjunk is true then the column is a working column (such as a sort key)
|
||||
* that should be removed from the final output of the query. Resjunk columns
|
||||
* must have resnos that cannot duplicate any regular column's resno. Also
|
||||
* note that there are places that assume resjunk columns come after non-junk
|
||||
* columns.
|
||||
*--------------------
|
||||
*/
|
||||
typedef struct Resdom
|
||||
{
|
||||
NodeTag type;
|
||||
AttrNumber resno; /* attribute number (see notes above) */
|
||||
Oid restype; /* type of the value */
|
||||
int32 restypmod; /* type-specific modifier of the value */
|
||||
char *resname; /* name of the column (could be NULL) */
|
||||
Index ressortgroupref;/* nonzero if referenced by a sort/group
|
||||
* clause */
|
||||
Oid resorigtbl; /* OID of column's source table */
|
||||
AttrNumber resorigcol; /* column's number in source table */
|
||||
bool resjunk; /* set to true to eliminate the attribute
|
||||
* from final target list */
|
||||
} Resdom;
|
||||
|
||||
|
||||
/*
|
||||
* Alias -
|
||||
* specifies an alias for a range variable; the alias might also
|
||||
@@ -822,7 +756,7 @@ typedef struct SetToDefault
|
||||
int32 typeMod; /* typemod for substituted value */
|
||||
} SetToDefault;
|
||||
|
||||
/*
|
||||
/*--------------------
|
||||
* TargetEntry -
|
||||
* a target entry (used in query target lists)
|
||||
*
|
||||
@@ -831,14 +765,63 @@ typedef struct SetToDefault
|
||||
* very many places it's convenient to process a whole query targetlist as a
|
||||
* single expression tree.
|
||||
*
|
||||
* The separation between TargetEntry and Resdom is historical. One of these
|
||||
* days, Resdom should probably get folded into TargetEntry.
|
||||
* In a SELECT's targetlist, resno should always be equal to the item's
|
||||
* ordinal position (counting from 1). However, in an INSERT or UPDATE
|
||||
* targetlist, resno represents the attribute number of the destination
|
||||
* column for the item; so there may be missing or out-of-order resnos.
|
||||
* It is even legal to have duplicated resnos; consider
|
||||
* UPDATE table SET arraycol[1] = ..., arraycol[2] = ..., ...
|
||||
* The two meanings come together in the executor, because the planner
|
||||
* transforms INSERT/UPDATE tlists into a normalized form with exactly
|
||||
* one entry for each column of the destination table. Before that's
|
||||
* happened, however, it is risky to assume that resno == position.
|
||||
* Generally get_tle_by_resno() should be used rather than list_nth()
|
||||
* to fetch tlist entries by resno, and only in SELECT should you assume
|
||||
* that resno is a unique identifier.
|
||||
*
|
||||
* resname is required to represent the correct column name in non-resjunk
|
||||
* entries of top-level SELECT targetlists, since it will be used as the
|
||||
* column title sent to the frontend. In most other contexts it is only
|
||||
* a debugging aid, and may be wrong or even NULL. (In particular, it may
|
||||
* be wrong in a tlist from a stored rule, if the referenced column has been
|
||||
* renamed by ALTER TABLE since the rule was made. Also, the planner tends
|
||||
* to store NULL rather than look up a valid name for tlist entries in
|
||||
* non-toplevel plan nodes.) In resjunk entries, resname should be either
|
||||
* a specific system-generated name (such as "ctid") or NULL; anything else
|
||||
* risks confusing ExecGetJunkAttribute!
|
||||
*
|
||||
* ressortgroupref is used in the representation of ORDER BY and
|
||||
* GROUP BY items. Targetlist entries with ressortgroupref=0 are not
|
||||
* sort/group items. If ressortgroupref>0, then this item is an ORDER BY or
|
||||
* GROUP BY value. No two entries in a targetlist may have the same nonzero
|
||||
* ressortgroupref --- but there is no particular meaning to the nonzero
|
||||
* values, except as tags. (For example, one must not assume that lower
|
||||
* ressortgroupref means a more significant sort key.) The order of the
|
||||
* associated SortClause or GroupClause lists determine the semantics.
|
||||
*
|
||||
* resorigtbl/resorigcol identify the source of the column, if it is a
|
||||
* simple reference to a column of a base table (or view). If it is not
|
||||
* a simple reference, these fields are zeroes.
|
||||
*
|
||||
* If resjunk is true then the column is a working column (such as a sort key)
|
||||
* that should be removed from the final output of the query. Resjunk columns
|
||||
* must have resnos that cannot duplicate any regular column's resno. Also
|
||||
* note that there are places that assume resjunk columns come after non-junk
|
||||
* columns.
|
||||
*--------------------
|
||||
*/
|
||||
typedef struct TargetEntry
|
||||
{
|
||||
Expr xpr;
|
||||
Resdom *resdom; /* descriptor for targetlist item */
|
||||
Expr *expr; /* expression to evaluate */
|
||||
AttrNumber resno; /* attribute number (see notes above) */
|
||||
char *resname; /* name of the column (could be NULL) */
|
||||
Index ressortgroupref;/* nonzero if referenced by a sort/group
|
||||
* clause */
|
||||
Oid resorigtbl; /* OID of column's source table */
|
||||
AttrNumber resorigcol; /* column's number in source table */
|
||||
bool resjunk; /* set to true to eliminate the attribute
|
||||
* from final target list */
|
||||
} TargetEntry;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user