diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-06 16:34:07 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2005-04-06 16:34:07 +0000 |
commit | ad161bcc8a3792d18ef2f3ebe66bb1e22d42b6f2 (patch) | |
tree | 18ec8963fbd1d6dd62ad214bfe3552fc2e7d06eb /src/backend/optimizer/prep/preptlist.c | |
parent | 0f3748a28c42d09d794ff00af3f1f992eaa5fd7c (diff) |
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.
Diffstat (limited to 'src/backend/optimizer/prep/preptlist.c')
-rw-r--r-- | src/backend/optimizer/prep/preptlist.c | 68 |
1 files changed, 27 insertions, 41 deletions
diff --git a/src/backend/optimizer/prep/preptlist.c b/src/backend/optimizer/prep/preptlist.c index 69dc30c63d5..ac8dae65ce7 100644 --- a/src/backend/optimizer/prep/preptlist.c +++ b/src/backend/optimizer/prep/preptlist.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.73 2005/03/17 23:44:52 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/prep/preptlist.c,v 1.74 2005/04/06 16:34:06 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -79,18 +79,17 @@ preprocess_targetlist(Query *parse, List *tlist) */ if (command_type == CMD_UPDATE || command_type == CMD_DELETE) { - Resdom *resdom; + TargetEntry *tle; Var *var; - resdom = makeResdom(list_length(tlist) + 1, - TIDOID, - -1, - pstrdup("ctid"), - true); - var = makeVar(result_relation, SelfItemPointerAttributeNumber, TIDOID, -1, 0); + tle = makeTargetEntry((Expr *) var, + list_length(tlist) + 1, + pstrdup("ctid"), + true); + /* * For an UPDATE, expand_targetlist already created a fresh tlist. * For DELETE, better do a listCopy so that we don't destructively @@ -99,7 +98,7 @@ preprocess_targetlist(Query *parse, List *tlist) if (command_type == CMD_DELETE) tlist = list_copy(tlist); - tlist = lappend(tlist, makeTargetEntry(resdom, (Expr *) var)); + tlist = lappend(tlist, tle); } /* @@ -132,18 +131,9 @@ preprocess_targetlist(Query *parse, List *tlist) foreach(l, parse->rowMarks) { Index rti = lfirst_int(l); - char *resname; - Resdom *resdom; Var *var; - TargetEntry *ctid; - - resname = (char *) palloc(32); - snprintf(resname, 32, "ctid%u", rti); - resdom = makeResdom(list_length(tlist) + 1, - TIDOID, - -1, - resname, - true); + char *resname; + TargetEntry *tle; var = makeVar(rti, SelfItemPointerAttributeNumber, @@ -151,8 +141,15 @@ preprocess_targetlist(Query *parse, List *tlist) -1, 0); - ctid = makeTargetEntry(resdom, (Expr *) var); - tlist = lappend(tlist, ctid); + resname = (char *) palloc(32); + snprintf(resname, 32, "ctid%u", rti); + + tle = makeTargetEntry((Expr *) var, + list_length(tlist) + 1, + resname, + true); + + tlist = lappend(tlist, tle); } } @@ -206,9 +203,8 @@ expand_targetlist(List *tlist, int command_type, if (tlist_item != NULL) { TargetEntry *old_tle = (TargetEntry *) lfirst(tlist_item); - Resdom *resdom = old_tle->resdom; - if (!resdom->resjunk && resdom->resno == attrno) + if (!old_tle->resjunk && old_tle->resno == attrno) { new_tle = old_tle; tlist_item = lnext(tlist_item); @@ -268,9 +264,6 @@ expand_targetlist(List *tlist, int command_type, (Datum) 0, true, /* isnull */ true /* byval */ ); - /* label resdom with INT4, too */ - atttype = INT4OID; - atttypmod = -1; } break; case CMD_UPDATE: @@ -290,9 +283,6 @@ expand_targetlist(List *tlist, int command_type, (Datum) 0, true, /* isnull */ true /* byval */ ); - /* label resdom with INT4, too */ - atttype = INT4OID; - atttypmod = -1; } break; default: @@ -302,12 +292,10 @@ expand_targetlist(List *tlist, int command_type, break; } - new_tle = makeTargetEntry(makeResdom(attrno, - atttype, - atttypmod, + new_tle = makeTargetEntry((Expr *) new_expr, + attrno, pstrdup(NameStr(att_tup->attname)), - false), - (Expr *) new_expr); + false); } new_tlist = lappend(new_tlist, new_tle); @@ -324,16 +312,14 @@ expand_targetlist(List *tlist, int command_type, while (tlist_item) { TargetEntry *old_tle = (TargetEntry *) lfirst(tlist_item); - Resdom *resdom = old_tle->resdom; - if (!resdom->resjunk) + if (!old_tle->resjunk) elog(ERROR, "targetlist is not sorted correctly"); /* Get the resno right, but don't copy unnecessarily */ - if (resdom->resno != attrno) + if (old_tle->resno != attrno) { - resdom = (Resdom *) copyObject((Node *) resdom); - resdom->resno = attrno; - old_tle = makeTargetEntry(resdom, old_tle->expr); + old_tle = flatCopyTargetEntry(old_tle); + old_tle->resno = attrno; } new_tlist = lappend(new_tlist, old_tle); attrno++; |