summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-08-11 20:46:47 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-08-11 20:46:47 +0000
commit88381ade63de931c84f53dc873c986d40b8c8b61 (patch)
tree1ec3c77e29b1d320718b64b38db10f8a8f0e0cd3 /src/backend/commands
parentcae912d05bfb354d81427c6ae5354eab90869fe9 (diff)
downloadpostgresql-88381ade63de931c84f53dc873c986d40b8c8b61.tar.gz
Code cleanup inspired by recent resname bug report (doesn't fix the bug
yet, though). Avoid using nth() to fetch tlist entries; provide a common routine get_tle_by_resno() to search a tlist for a particular resno. This replaces a couple uses of nth() and a dozen hand-coded search loops. Also, replace a few uses of nth(length-1, list) with llast().
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/comment.c10
-rw-r--r--src/backend/commands/explain.c29
2 files changed, 15 insertions, 24 deletions
diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c
index 4ed3614506..df09337d72 100644
--- a/src/backend/commands/comment.c
+++ b/src/backend/commands/comment.c
@@ -7,7 +7,7 @@
* Copyright (c) 1996-2003, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.69 2003/08/04 23:59:37 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.70 2003/08/11 20:46:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -365,7 +365,7 @@ CommentAttribute(List *qualname, char *comment)
if (nnames < 2) /* parser messed up */
elog(ERROR, "must specify relation and attribute");
relname = ltruncate(nnames - 1, listCopy(qualname));
- attrname = strVal(nth(nnames - 1, qualname));
+ attrname = strVal(llast(qualname));
/* Open the containing relation to ensure it won't go away meanwhile */
rel = makeRangeVarFromNameList(relname);
@@ -583,7 +583,7 @@ CommentRule(List *qualname, char *comment)
/* New-style: rule and relname both provided */
Assert(nnames >= 2);
relname = ltruncate(nnames - 1, listCopy(qualname));
- rulename = strVal(nth(nnames - 1, qualname));
+ rulename = strVal(llast(qualname));
/* Open the owning relation to ensure it won't go away meanwhile */
rel = makeRangeVarFromNameList(relname);
@@ -778,7 +778,7 @@ CommentTrigger(List *qualname, char *comment)
if (nnames < 2) /* parser messed up */
elog(ERROR, "must specify relation and trigger");
relname = ltruncate(nnames - 1, listCopy(qualname));
- trigname = strVal(nth(nnames - 1, qualname));
+ trigname = strVal(llast(qualname));
/* Open the owning relation to ensure it won't go away meanwhile */
rel = makeRangeVarFromNameList(relname);
@@ -856,7 +856,7 @@ CommentConstraint(List *qualname, char *comment)
if (nnames < 2) /* parser messed up */
elog(ERROR, "must specify relation and constraint");
relName = ltruncate(nnames - 1, listCopy(qualname));
- conName = strVal(nth(nnames - 1, qualname));
+ conName = strVal(llast(qualname));
/* Open the owning relation to ensure it won't go away meanwhile */
rel = makeRangeVarFromNameList(relName);
diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c
index 6e2b857271..e664b3e494 100644
--- a/src/backend/commands/explain.c
+++ b/src/backend/commands/explain.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.114 2003/08/08 21:41:30 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.115 2003/08/11 20:46:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -947,7 +947,6 @@ show_sort_keys(List *tlist, int nkeys, AttrNumber *keycols,
List *context;
bool useprefix;
int keyno;
- List *tl;
char *exprstr;
Relids varnos;
int i;
@@ -993,25 +992,17 @@ show_sort_keys(List *tlist, int nkeys, AttrNumber *keycols,
{
/* find key expression in tlist */
AttrNumber keyresno = keycols[keyno];
+ TargetEntry *target = get_tle_by_resno(tlist, keyresno);
- foreach(tl, tlist)
- {
- TargetEntry *target = (TargetEntry *) lfirst(tl);
-
- if (target->resdom->resno == keyresno)
- {
- /* Deparse the expression, showing any top-level cast */
- exprstr = deparse_expression((Node *) target->expr, context,
- useprefix, true);
- /* And add to str */
- if (keyno > 0)
- appendStringInfo(str, ", ");
- appendStringInfo(str, "%s", exprstr);
- break;
- }
- }
- if (tl == NIL)
+ if (!target)
elog(ERROR, "no tlist entry for key %d", keyresno);
+ /* Deparse the expression, showing any top-level cast */
+ exprstr = deparse_expression((Node *) target->expr, context,
+ useprefix, true);
+ /* And add to str */
+ if (keyno > 0)
+ appendStringInfo(str, ", ");
+ appendStringInfo(str, "%s", exprstr);
}
appendStringInfo(str, "\n");