mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Ye-old pgindent run. Same 4-space tabs.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
* Routines to preprocess the parse tree target list
|
||||
*
|
||||
* This module takes care of altering the query targetlist as needed for
|
||||
* INSERT, UPDATE, and DELETE queries. For INSERT and UPDATE queries,
|
||||
* INSERT, UPDATE, and DELETE queries. For INSERT and UPDATE queries,
|
||||
* the targetlist must contain an entry for each attribute of the target
|
||||
* relation in the correct order. For both UPDATE and DELETE queries,
|
||||
* we need a junk targetlist entry holding the CTID attribute --- the
|
||||
@@ -15,7 +15,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.35 2000/03/09 05:00:24 inoue Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/preptlist.c,v 1.36 2000/04/12 17:15:23 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
static List *expand_targetlist(List *tlist, int command_type,
|
||||
Index result_relation, List *range_table);
|
||||
Index result_relation, List *range_table);
|
||||
|
||||
|
||||
/*
|
||||
@@ -46,6 +46,7 @@ preprocess_targetlist(List *tlist,
|
||||
Index result_relation,
|
||||
List *range_table)
|
||||
{
|
||||
|
||||
/*
|
||||
* for heap_formtuple to work, the targetlist must match the exact
|
||||
* order of the attributes. We also need to fill in any missing
|
||||
@@ -56,11 +57,11 @@ preprocess_targetlist(List *tlist,
|
||||
result_relation, range_table);
|
||||
|
||||
/*
|
||||
* for "update" and "delete" queries, add ctid of the result
|
||||
* relation into the target list so that the ctid will propagate
|
||||
* through execution and ExecutePlan() will be able to identify
|
||||
* the right tuple to replace or delete. This extra field is
|
||||
* marked "junk" so that it is not stored back into the tuple.
|
||||
* for "update" and "delete" queries, add ctid of the result relation
|
||||
* into the target list so that the ctid will propagate through
|
||||
* execution and ExecutePlan() will be able to identify the right
|
||||
* tuple to replace or delete. This extra field is marked "junk" so
|
||||
* that it is not stored back into the tuple.
|
||||
*/
|
||||
if (command_type == CMD_UPDATE || command_type == CMD_DELETE)
|
||||
{
|
||||
@@ -78,7 +79,8 @@ preprocess_targetlist(List *tlist,
|
||||
var = makeVar(result_relation, SelfItemPointerAttributeNumber,
|
||||
TIDOID, -1, 0);
|
||||
|
||||
/* For an UPDATE, expand_targetlist already created a fresh tlist.
|
||||
/*
|
||||
* For an UPDATE, expand_targetlist already created a fresh tlist.
|
||||
* For DELETE, better do a listCopy so that we don't destructively
|
||||
* modify the original tlist (is this really necessary?).
|
||||
*/
|
||||
@@ -117,11 +119,11 @@ expand_targetlist(List *tlist, int command_type,
|
||||
List *temp;
|
||||
|
||||
/*
|
||||
* Keep a map of which tlist items we have transferred to new list.
|
||||
* +1 here keeps palloc from complaining if old_tlist_len=0.
|
||||
* Keep a map of which tlist items we have transferred to new list. +1
|
||||
* here keeps palloc from complaining if old_tlist_len=0.
|
||||
*/
|
||||
tlistentry_used = (bool *) palloc((old_tlist_len+1) * sizeof(bool));
|
||||
memset(tlistentry_used, 0, (old_tlist_len+1) * sizeof(bool));
|
||||
tlistentry_used = (bool *) palloc((old_tlist_len + 1) * sizeof(bool));
|
||||
memset(tlistentry_used, 0, (old_tlist_len + 1) * sizeof(bool));
|
||||
|
||||
/*
|
||||
* Scan the tuple description in the relation's relcache entry to make
|
||||
@@ -133,9 +135,9 @@ expand_targetlist(List *tlist, int command_type,
|
||||
|
||||
for (attrno = 1; attrno <= numattrs; attrno++)
|
||||
{
|
||||
Form_pg_attribute att_tup = rel->rd_att->attrs[attrno-1];
|
||||
char *attrname = NameStr(att_tup->attname);
|
||||
TargetEntry *new_tle = NULL;
|
||||
Form_pg_attribute att_tup = rel->rd_att->attrs[attrno - 1];
|
||||
char *attrname = NameStr(att_tup->attname);
|
||||
TargetEntry *new_tle = NULL;
|
||||
|
||||
/*
|
||||
* We match targetlist entries to attributes using the resname.
|
||||
@@ -143,22 +145,22 @@ expand_targetlist(List *tlist, int command_type,
|
||||
old_tlist_index = 0;
|
||||
foreach(temp, tlist)
|
||||
{
|
||||
TargetEntry *old_tle = (TargetEntry *) lfirst(temp);
|
||||
Resdom *resdom = old_tle->resdom;
|
||||
TargetEntry *old_tle = (TargetEntry *) lfirst(temp);
|
||||
Resdom *resdom = old_tle->resdom;
|
||||
|
||||
if (! tlistentry_used[old_tlist_index] &&
|
||||
if (!tlistentry_used[old_tlist_index] &&
|
||||
strcmp(resdom->resname, attrname) == 0 &&
|
||||
! resdom->resjunk)
|
||||
!resdom->resjunk)
|
||||
{
|
||||
|
||||
/*
|
||||
* We can recycle the old TLE+resdom if right resno; else
|
||||
* make a new one to avoid modifying the old tlist structure.
|
||||
* (Is preserving old tlist actually necessary?)
|
||||
* make a new one to avoid modifying the old tlist
|
||||
* structure. (Is preserving old tlist actually
|
||||
* necessary?)
|
||||
*/
|
||||
if (resdom->resno == attrno)
|
||||
{
|
||||
new_tle = old_tle;
|
||||
}
|
||||
else
|
||||
{
|
||||
resdom = (Resdom *) copyObject((Node *) resdom);
|
||||
@@ -173,14 +175,15 @@ expand_targetlist(List *tlist, int command_type,
|
||||
|
||||
if (new_tle == NULL)
|
||||
{
|
||||
|
||||
/*
|
||||
* Didn't find a matching tlist entry, so make one.
|
||||
*
|
||||
* For INSERT, generate a constant of the default value for
|
||||
* the attribute type, or NULL if no default value.
|
||||
* For INSERT, generate a constant of the default value for the
|
||||
* attribute type, or NULL if no default value.
|
||||
*
|
||||
* For UPDATE, generate a Var reference to the existing value
|
||||
* of the attribute, so that it gets copied to the new tuple.
|
||||
* For UPDATE, generate a Var reference to the existing value of
|
||||
* the attribute, so that it gets copied to the new tuple.
|
||||
*/
|
||||
Oid atttype = att_tup->atttypid;
|
||||
int32 atttypmod = att_tup->atttypmod;
|
||||
@@ -188,92 +191,96 @@ expand_targetlist(List *tlist, int command_type,
|
||||
switch (command_type)
|
||||
{
|
||||
case CMD_INSERT:
|
||||
{
|
||||
{
|
||||
#ifdef _DROP_COLUMN_HACK__
|
||||
Datum typedefault;
|
||||
Datum typedefault;
|
||||
|
||||
#else
|
||||
Datum typedefault = get_typdefault(atttype);
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
int typlen;
|
||||
Const *temp_const;
|
||||
Datum typedefault = get_typdefault(atttype);
|
||||
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
int typlen;
|
||||
Const *temp_const;
|
||||
|
||||
#ifdef _DROP_COLUMN_HACK__
|
||||
if (COLUMN_IS_DROPPED(att_tup))
|
||||
typedefault = PointerGetDatum(NULL);
|
||||
else
|
||||
typedefault = get_typdefault(atttype);
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
if (typedefault == PointerGetDatum(NULL))
|
||||
typlen = 0;
|
||||
else
|
||||
{
|
||||
/*
|
||||
* Since this is an append or replace, the size of
|
||||
* any set attribute is the size of the OID used to
|
||||
* represent it.
|
||||
*/
|
||||
if (att_tup->attisset)
|
||||
typlen = get_typlen(OIDOID);
|
||||
if (COLUMN_IS_DROPPED(att_tup))
|
||||
typedefault = PointerGetDatum(NULL);
|
||||
else
|
||||
typlen = get_typlen(atttype);
|
||||
typedefault = get_typdefault(atttype);
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
if (typedefault == PointerGetDatum(NULL))
|
||||
typlen = 0;
|
||||
else
|
||||
{
|
||||
|
||||
/*
|
||||
* Since this is an append or replace, the
|
||||
* size of any set attribute is the size of
|
||||
* the OID used to represent it.
|
||||
*/
|
||||
if (att_tup->attisset)
|
||||
typlen = get_typlen(OIDOID);
|
||||
else
|
||||
typlen = get_typlen(atttype);
|
||||
}
|
||||
|
||||
temp_const = makeConst(atttype,
|
||||
typlen,
|
||||
typedefault,
|
||||
(typedefault == PointerGetDatum(NULL)),
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
|
||||
new_tle = makeTargetEntry(makeResdom(attrno,
|
||||
atttype,
|
||||
-1,
|
||||
pstrdup(attrname),
|
||||
0,
|
||||
(Oid) 0,
|
||||
false),
|
||||
(Node *) temp_const);
|
||||
break;
|
||||
}
|
||||
|
||||
temp_const = makeConst(atttype,
|
||||
typlen,
|
||||
typedefault,
|
||||
(typedefault == PointerGetDatum(NULL)),
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
|
||||
new_tle = makeTargetEntry(makeResdom(attrno,
|
||||
atttype,
|
||||
-1,
|
||||
pstrdup(attrname),
|
||||
0,
|
||||
(Oid) 0,
|
||||
false),
|
||||
(Node *) temp_const);
|
||||
break;
|
||||
}
|
||||
case CMD_UPDATE:
|
||||
{
|
||||
Var *temp_var;
|
||||
|
||||
#ifdef _DROP_COLUMN_HACK__
|
||||
Node *temp_node = (Node *) NULL;
|
||||
if (COLUMN_IS_DROPPED(att_tup))
|
||||
{
|
||||
temp_node = (Node *)makeConst(atttype, 0,
|
||||
PointerGetDatum(NULL),
|
||||
true,
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
}
|
||||
else
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
temp_var = makeVar(result_relation, attrno, atttype,
|
||||
atttypmod, 0);
|
||||
#ifdef _DROP_COLUMN_HACK__
|
||||
if (!temp_node)
|
||||
temp_node = (Node *) temp_var;
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
Var *temp_var;
|
||||
|
||||
new_tle = makeTargetEntry(makeResdom(attrno,
|
||||
atttype,
|
||||
atttypmod,
|
||||
pstrdup(attrname),
|
||||
0,
|
||||
(Oid) 0,
|
||||
false),
|
||||
#ifdef _DROP_COLUMN_HACK__
|
||||
temp_node);
|
||||
Node *temp_node = (Node *) NULL;
|
||||
|
||||
if (COLUMN_IS_DROPPED(att_tup))
|
||||
{
|
||||
temp_node = (Node *) makeConst(atttype, 0,
|
||||
PointerGetDatum(NULL),
|
||||
true,
|
||||
false,
|
||||
false, /* not a set */
|
||||
false);
|
||||
}
|
||||
else
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
temp_var = makeVar(result_relation, attrno, atttype,
|
||||
atttypmod, 0);
|
||||
#ifdef _DROP_COLUMN_HACK__
|
||||
if (!temp_node)
|
||||
temp_node = (Node *) temp_var;
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
|
||||
new_tle = makeTargetEntry(makeResdom(attrno,
|
||||
atttype,
|
||||
atttypmod,
|
||||
pstrdup(attrname),
|
||||
0,
|
||||
(Oid) 0,
|
||||
false),
|
||||
#ifdef _DROP_COLUMN_HACK__
|
||||
temp_node);
|
||||
#else
|
||||
(Node *) temp_var);
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
break;
|
||||
}
|
||||
(Node *) temp_var);
|
||||
#endif /* _DROP_COLUMN_HACK__ */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
elog(ERROR, "expand_targetlist: unexpected command_type");
|
||||
break;
|
||||
@@ -285,18 +292,19 @@ expand_targetlist(List *tlist, int command_type,
|
||||
|
||||
/*
|
||||
* Copy all unprocessed tlist entries to the end of the new tlist,
|
||||
* making sure they are marked resjunk = true. Typical junk entries
|
||||
* include ORDER BY or GROUP BY expressions (are these actually possible
|
||||
* in an INSERT or UPDATE?), system attribute references, etc.
|
||||
* making sure they are marked resjunk = true. Typical junk entries
|
||||
* include ORDER BY or GROUP BY expressions (are these actually
|
||||
* possible in an INSERT or UPDATE?), system attribute references,
|
||||
* etc.
|
||||
*/
|
||||
old_tlist_index = 0;
|
||||
foreach(temp, tlist)
|
||||
{
|
||||
TargetEntry *old_tle = (TargetEntry *) lfirst(temp);
|
||||
TargetEntry *old_tle = (TargetEntry *) lfirst(temp);
|
||||
|
||||
if (! tlistentry_used[old_tlist_index])
|
||||
if (!tlistentry_used[old_tlist_index])
|
||||
{
|
||||
Resdom *resdom;
|
||||
Resdom *resdom;
|
||||
|
||||
resdom = (Resdom *) copyObject((Node *) old_tle->resdom);
|
||||
resdom->resno = attrno++;
|
||||
|
||||
Reference in New Issue
Block a user