From d0b4399d81f39decccb23fa38f772b71b51bf96a Mon Sep 17 00:00:00 2001 From: Neil Conway Date: Wed, 26 May 2004 04:41:50 +0000 Subject: Reimplement the linked list data structure used throughout the backend. In the past, we used a 'Lispy' linked list implementation: a "list" was merely a pointer to the head node of the list. The problem with that design is that it makes lappend() and length() linear time. This patch fixes that problem (and others) by maintaining a count of the list length and a pointer to the tail node along with each head node pointer. A "list" is now a pointer to a structure containing some meta-data about the list; the head and tail pointers in that structure refer to ListCell structures that maintain the actual linked list of nodes. The function names of the list API have also been changed to, I hope, be more logically consistent. By default, the old function names are still available; they will be disabled-by-default once the rest of the tree has been updated to use the new API names. --- src/backend/commands/aggregatecmds.c | 4 +- src/backend/commands/alter.c | 6 +- src/backend/commands/analyze.c | 14 +-- src/backend/commands/async.c | 4 +- src/backend/commands/cluster.c | 14 +-- src/backend/commands/comment.c | 60 +++++----- src/backend/commands/copy.c | 51 ++++---- src/backend/commands/dbcommands.c | 4 +- src/backend/commands/define.c | 6 +- src/backend/commands/explain.c | 44 ++++--- src/backend/commands/functioncmds.c | 20 ++-- src/backend/commands/indexcmds.c | 40 +++---- src/backend/commands/lockcmds.c | 4 +- src/backend/commands/opclasscmds.c | 12 +- src/backend/commands/operatorcmds.c | 14 +-- src/backend/commands/portalcmds.c | 10 +- src/backend/commands/prepare.c | 36 +++--- src/backend/commands/schemacmds.c | 12 +- src/backend/commands/sequence.c | 4 +- src/backend/commands/tablecmds.c | 224 ++++++++++++++++------------------- src/backend/commands/trigger.c | 40 +++---- src/backend/commands/typecmds.c | 16 +-- src/backend/commands/user.c | 46 +++---- src/backend/commands/vacuum.c | 24 ++-- src/backend/commands/variable.c | 8 +- src/backend/commands/view.c | 8 +- 26 files changed, 351 insertions(+), 374 deletions(-) (limited to 'src/backend/commands') diff --git a/src/backend/commands/aggregatecmds.c b/src/backend/commands/aggregatecmds.c index d587245ef97..c8865b3dbde 100644 --- a/src/backend/commands/aggregatecmds.c +++ b/src/backend/commands/aggregatecmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.17 2004/05/07 00:24:57 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/aggregatecmds.c,v 1.18 2004/05/26 04:41:09 neilc Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -56,7 +56,7 @@ DefineAggregate(List *names, List *parameters) char *initval = NULL; Oid baseTypeId; Oid transTypeId; - List *pl; + ListCell *pl; /* Convert list of names to a name and namespace */ aggNamespace = QualifiedNameGetCreationNamespace(names, &aggName); diff --git a/src/backend/commands/alter.c b/src/backend/commands/alter.c index 5bb3c51dd35..40a28103c77 100644 --- a/src/backend/commands/alter.c +++ b/src/backend/commands/alter.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.6 2003/11/29 19:51:47 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/commands/alter.c,v 1.7 2004/05/26 04:41:09 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -41,7 +41,9 @@ ExecRenameStmt(RenameStmt *stmt) switch (stmt->renameType) { case OBJECT_AGGREGATE: - RenameAggregate(stmt->object, (TypeName *) lfirst(stmt->objarg), stmt->newname); + RenameAggregate(stmt->object, + (TypeName *) linitial(stmt->objarg), + stmt->newname); break; case OBJECT_CONVERSION: diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 0f6ff2d37e6..4efaf653ede 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.72 2004/05/23 21:24:02 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.73 2004/05/26 04:41:09 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -207,9 +207,9 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) */ if (vacstmt->va_cols != NIL) { - List *le; + ListCell *le; - vacattrstats = (VacAttrStats **) palloc(length(vacstmt->va_cols) * + vacattrstats = (VacAttrStats **) palloc(list_length(vacstmt->va_cols) * sizeof(VacAttrStats *)); tcnt = 0; foreach(le, vacstmt->va_cols) @@ -260,7 +260,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) thisdata->tupleFract = 1.0; /* fix later if partial */ if (indexInfo->ii_Expressions != NIL && vacstmt->va_cols == NIL) { - List *indexprs = indexInfo->ii_Expressions; + ListCell *indexpr_item = list_head(indexInfo->ii_Expressions); thisdata->vacattrstats = (VacAttrStats **) palloc(indexInfo->ii_NumIndexAttrs * sizeof(VacAttrStats *)); @@ -274,10 +274,10 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt) /* Found an index expression */ Node *indexkey; - if (indexprs == NIL) /* shouldn't happen */ + if (indexpr_item == NULL) /* shouldn't happen */ elog(ERROR, "too few entries in indexprs list"); - indexkey = (Node *) lfirst(indexprs); - indexprs = lnext(indexprs); + indexkey = (Node *) lfirst(indexpr_item); + indexpr_item = lnext(indexpr_item); /* * Can't analyze if the opclass uses a storage type diff --git a/src/backend/commands/async.c b/src/backend/commands/async.c index 15d7c0aae5c..847f73ff06a 100644 --- a/src/backend/commands/async.c +++ b/src/backend/commands/async.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.111 2004/05/23 03:50:45 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/async.c,v 1.112 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -932,7 +932,7 @@ NotifyMyFrontEnd(char *relname, int32 listenerPID) static bool AsyncExistsPendingNotify(const char *relname) { - List *p; + ListCell *p; foreach(p, pendingNotifies) { diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c index 168ae749fa0..d9c4397176b 100644 --- a/src/backend/commands/cluster.c +++ b/src/backend/commands/cluster.c @@ -11,7 +11,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.123 2004/05/08 00:34:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/cluster.c,v 1.124 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -103,7 +103,7 @@ cluster(ClusterStmt *stmt) if (stmt->indexname == NULL) { - List *index; + ListCell *index; /* We need to find the index that has indisclustered set. */ foreach(index, RelationGetIndexList(rel)) @@ -111,7 +111,7 @@ cluster(ClusterStmt *stmt) HeapTuple idxtuple; Form_pg_index indexForm; - indexOid = lfirsto(index); + indexOid = lfirst_oid(index); idxtuple = SearchSysCache(INDEXRELID, ObjectIdGetDatum(indexOid), 0, 0, 0); @@ -165,8 +165,8 @@ cluster(ClusterStmt *stmt) * tables that have some index with indisclustered set. */ MemoryContext cluster_context; - List *rv, - *rvs; + List *rvs; + ListCell *rv; /* * We cannot run this form of CLUSTER inside a user transaction @@ -408,7 +408,7 @@ mark_index_clustered(Relation rel, Oid indexOid) HeapTuple indexTuple; Form_pg_index indexForm; Relation pg_index; - List *index; + ListCell *index; /* * If the index is already marked clustered, no need to do anything. @@ -438,7 +438,7 @@ mark_index_clustered(Relation rel, Oid indexOid) foreach(index, RelationGetIndexList(rel)) { - Oid thisIndexOid = lfirsto(index); + Oid thisIndexOid = lfirst_oid(index); indexTuple = SearchSysCacheCopy(INDEXRELID, ObjectIdGetDatum(thisIndexOid), diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c index 423ab97570a..4c0d65038b2 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 - * $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.76 2004/03/08 21:35:59 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/comment.c,v 1.77 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -379,11 +379,11 @@ CommentAttribute(List *qualname, char *comment) AttrNumber attnum; /* Separate relname and attr name */ - nnames = length(qualname); + nnames = list_length(qualname); if (nnames < 2) /* parser messed up */ elog(ERROR, "must specify relation and attribute"); - relname = ltruncate(nnames - 1, listCopy(qualname)); - attrname = strVal(llast(qualname)); + relname = list_truncate(list_copy(qualname), nnames - 1); + attrname = strVal(lfirst(list_tail(qualname))); /* Open the containing relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -429,11 +429,11 @@ CommentDatabase(List *qualname, char *comment) char *database; Oid oid; - if (length(qualname) != 1) + if (list_length(qualname) != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("database name may not be qualified"))); - database = strVal(lfirst(qualname)); + database = strVal(linitial(qualname)); /* * We cannot currently support cross-database comments (since other @@ -493,11 +493,11 @@ CommentNamespace(List *qualname, char *comment) Oid classoid; char *namespace; - if (length(qualname) != 1) + if (list_length(qualname) != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("schema name may not be qualified"))); - namespace = strVal(lfirst(qualname)); + namespace = strVal(linitial(qualname)); oid = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(namespace), @@ -548,7 +548,7 @@ CommentRule(List *qualname, char *comment) AclResult aclcheck; /* Separate relname and trig name */ - nnames = length(qualname); + nnames = list_length(qualname); if (nnames == 1) { /* Old-style: only a rule name is given */ @@ -556,7 +556,7 @@ CommentRule(List *qualname, char *comment) HeapScanDesc scanDesc; ScanKeyData scanKeyData; - rulename = strVal(lfirst(qualname)); + rulename = strVal(linitial(qualname)); /* Search pg_rewrite for such a rule */ ScanKeyInit(&scanKeyData, @@ -599,8 +599,8 @@ CommentRule(List *qualname, char *comment) { /* New-style: rule and relname both provided */ Assert(nnames >= 2); - relname = ltruncate(nnames - 1, listCopy(qualname)); - rulename = strVal(llast(qualname)); + relname = list_truncate(list_copy(qualname), nnames - 1); + rulename = strVal(lfirst(list_tail(qualname))); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -683,7 +683,7 @@ CommentType(List *typename, char *comment) static void CommentAggregate(List *aggregate, List *arguments, char *comment) { - TypeName *aggtype = (TypeName *) lfirst(arguments); + TypeName *aggtype = (TypeName *) linitial(arguments); Oid baseoid, oid; @@ -750,7 +750,7 @@ CommentProc(List *function, List *arguments, char *comment) static void CommentOperator(List *opername, List *arguments, char *comment) { - TypeName *typenode1 = (TypeName *) lfirst(arguments); + TypeName *typenode1 = (TypeName *) linitial(arguments); TypeName *typenode2 = (TypeName *) lsecond(arguments); Oid oid; Oid classoid; @@ -794,11 +794,11 @@ CommentTrigger(List *qualname, char *comment) Oid oid; /* Separate relname and trig name */ - nnames = length(qualname); + nnames = list_length(qualname); if (nnames < 2) /* parser messed up */ elog(ERROR, "must specify relation and trigger"); - relname = ltruncate(nnames - 1, listCopy(qualname)); - trigname = strVal(llast(qualname)); + relname = list_truncate(list_copy(qualname), nnames - 1); + trigname = strVal(lfirst(list_tail(qualname))); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relname); @@ -872,11 +872,11 @@ CommentConstraint(List *qualname, char *comment) Oid conOid = InvalidOid; /* Separate relname and constraint name */ - nnames = length(qualname); + nnames = list_length(qualname); if (nnames < 2) /* parser messed up */ elog(ERROR, "must specify relation and constraint"); - relName = ltruncate(nnames - 1, listCopy(qualname)); - conName = strVal(llast(qualname)); + relName = list_truncate(list_copy(qualname), nnames - 1); + conName = strVal(lfirst(list_tail(qualname))); /* Open the owning relation to ensure it won't go away meanwhile */ rel = makeRangeVarFromNameList(relName); @@ -985,11 +985,11 @@ CommentLanguage(List *qualname, char *comment) Oid classoid; char *language; - if (length(qualname) != 1) + if (list_length(qualname) != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("language name may not be qualified"))); - language = strVal(lfirst(qualname)); + language = strVal(linitial(qualname)); oid = GetSysCacheOid(LANGNAME, CStringGetDatum(language), @@ -1032,8 +1032,8 @@ CommentOpClass(List *qualname, List *arguments, char *comment) Oid classoid; HeapTuple tuple; - Assert(length(arguments) == 1); - amname = strVal(lfirst(arguments)); + Assert(list_length(arguments) == 1); + amname = strVal(linitial(arguments)); /* * Get the access method's OID. @@ -1118,8 +1118,8 @@ CommentLargeObject(List *qualname, char *comment) Oid classoid; Node *node; - Assert(length(qualname) == 1); - node = (Node *) lfirst(qualname); + Assert(list_length(qualname) == 1); + node = (Node *) linitial(qualname); switch (nodeTag(node)) { @@ -1176,11 +1176,11 @@ CommentCast(List *qualname, List *arguments, char *comment) Oid castOid; Oid classoid; - Assert(length(qualname) == 1); - sourcetype = (TypeName *) lfirst(qualname); + Assert(list_length(qualname) == 1); + sourcetype = (TypeName *) linitial(qualname); Assert(IsA(sourcetype, TypeName)); - Assert(length(arguments) == 1); - targettype = (TypeName *) lfirst(arguments); + Assert(list_length(arguments) == 1); + targettype = (TypeName *) linitial(arguments); Assert(IsA(targettype, TypeName)); sourcetypeid = typenameTypeId(sourcetype); diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 74025ad041b..a666516fb39 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.223 2004/04/21 00:34:18 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/copy.c,v 1.224 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -685,7 +685,7 @@ DoCopy(const CopyStmt *stmt) char *filename = stmt->filename; bool is_from = stmt->is_from; bool pipe = (stmt->filename == NULL); - List *option; + ListCell *option; List *attnamelist = stmt->attlist; List *attnumlist; bool binary = false; @@ -934,15 +934,15 @@ DoCopy(const CopyStmt *stmt) { TupleDesc tupDesc = RelationGetDescr(rel); Form_pg_attribute *attr = tupDesc->attrs; - List *cur; + ListCell *cur; force_quote_atts = CopyGetAttnums(rel, force_quote); foreach(cur, force_quote_atts) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); - if (!intMember(attnum, attnumlist)) + if (!list_member_int(attnumlist, attnum)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("FORCE QUOTE column \"%s\" not referenced by COPY", @@ -955,7 +955,7 @@ DoCopy(const CopyStmt *stmt) */ if (force_notnull) { - List *cur; + ListCell *cur; TupleDesc tupDesc = RelationGetDescr(rel); Form_pg_attribute *attr = tupDesc->attrs; @@ -963,9 +963,9 @@ DoCopy(const CopyStmt *stmt) foreach(cur, force_notnull_atts) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); - if (!intMember(attnum, attnumlist)) + if (!list_member_int(attnumlist, attnum)) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("FORCE NOT NULL column \"%s\" not referenced by COPY", @@ -1011,7 +1011,7 @@ DoCopy(const CopyStmt *stmt) if (pipe) { if (whereToSendOutput == Remote) - ReceiveCopyBegin(binary, length(attnumlist)); + ReceiveCopyBegin(binary, list_length(attnumlist)); else copy_file = stdin; } @@ -1062,7 +1062,7 @@ DoCopy(const CopyStmt *stmt) if (pipe) { if (whereToSendOutput == Remote) - SendCopyBegin(binary, length(attnumlist)); + SendCopyBegin(binary, list_length(attnumlist)); else copy_file = stdout; } @@ -1147,14 +1147,14 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, bool *isvarlena; char *string; Snapshot mySnapshot; - List *cur; + ListCell *cur; MemoryContext oldcontext; MemoryContext mycontext; tupDesc = rel->rd_att; attr = tupDesc->attrs; num_phys_attrs = tupDesc->natts; - attr_count = length(attnumlist); + attr_count = list_length(attnumlist); /* * Get info about the columns we need to process. @@ -1167,7 +1167,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, force_quote = (bool *) palloc((num_phys_attrs + 1) * sizeof(bool)); foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); Oid out_func_oid; if (binary) @@ -1180,7 +1180,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, &isvarlena[attnum - 1]); fmgr_info(out_func_oid, &out_functions[attnum - 1]); - if (intMember(attnum, force_quote_atts)) + if (list_member_int(force_quote_atts, attnum)) force_quote[attnum - 1] = true; else force_quote[attnum - 1] = false; @@ -1266,7 +1266,7 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids, foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); Datum value; bool isnull; @@ -1451,7 +1451,6 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, bool hasConstraints = false; int attnum; int i; - List *cur; Oid in_func_oid; Datum *values; char *nulls; @@ -1471,7 +1470,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, tupDesc = RelationGetDescr(rel); attr = tupDesc->attrs; num_phys_attrs = tupDesc->natts; - attr_count = length(attnumlist); + attr_count = list_length(attnumlist); num_defaults = 0; /* @@ -1526,13 +1525,13 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, &in_func_oid, &elements[attnum - 1]); fmgr_info(in_func_oid, &in_functions[attnum - 1]); - if (intMember(attnum, force_notnull_atts)) + if (list_member_int(force_notnull_atts, attnum)) force_notnull[attnum - 1] = true; else force_notnull[attnum - 1] = false; /* Get default info if needed */ - if (!intMember(attnum, attnumlist)) + if (!list_member_int(attnumlist, attnum)) { /* attribute is NOT to be copied from input */ /* use default value if one exists */ @@ -1681,6 +1680,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, { CopyReadResult result = NORMAL_ATTR; char *string; + ListCell *cur; /* Actually read the line into memory here */ done = CopyReadLine(); @@ -1722,7 +1722,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, */ foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); int m = attnum - 1; /* @@ -1783,6 +1783,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, { /* binary */ int16 fld_count; + ListCell *cur; fld_count = CopyGetInt16(); if (CopyGetEof() || fld_count == -1) @@ -1815,7 +1816,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids, i = 0; foreach(cur, attnumlist) { - int attnum = lfirsti(cur); + int attnum = lfirst_int(cur); int m = attnum - 1; copy_attname = NameStr(attr[m]->attname); @@ -2642,13 +2643,13 @@ CopyGetAttnums(Relation rel, List *attnamelist) { if (attr[i]->attisdropped) continue; - attnums = lappendi(attnums, i + 1); + attnums = lappend_int(attnums, i + 1); } } else { /* Validate the user-supplied list and extract attnums */ - List *l; + ListCell *l; foreach(l, attnamelist) { @@ -2659,12 +2660,12 @@ CopyGetAttnums(Relation rel, List *attnamelist) /* Note we disallow system columns here */ attnum = attnameAttNum(rel, name, false); /* Check for duplicates */ - if (intMember(attnum, attnums)) + if (list_member_int(attnums, attnum)) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_COLUMN), errmsg("column \"%s\" specified more than once", name))); - attnums = lappendi(attnums, attnum); + attnums = lappend_int(attnums, attnum); } } diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 038db4de70e..9114983e75d 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.132 2004/04/19 17:42:57 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/dbcommands.c,v 1.133 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -82,7 +82,7 @@ createdb(const CreatedbStmt *stmt) char new_record_nulls[Natts_pg_database]; Oid dboid; AclId datdba; - List *option; + ListCell *option; DefElem *downer = NULL; DefElem *dpath = NULL; DefElem *dtemplate = NULL; diff --git a/src/backend/commands/define.c b/src/backend/commands/define.c index e4a62b77308..1a12674fa77 100644 --- a/src/backend/commands/define.c +++ b/src/backend/commands/define.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.88 2004/05/14 16:11:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/define.c,v 1.89 2004/05/26 04:41:10 neilc Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -190,7 +190,7 @@ defGetQualifiedName(DefElem *def) return (List *) def->arg; case T_String: /* Allow quoted name for backwards compatibility */ - return makeList1(def->arg); + return list_make1(def->arg); default: ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), @@ -223,7 +223,7 @@ defGetTypeName(DefElem *def) /* Allow quoted typename for backwards compatibility */ TypeName *n = makeNode(TypeName); - n->names = makeList1(def->arg); + n->names = list_make1(def->arg); n->typmod = -1; return n; } diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index e2f3d4aa813..3658a00ea21 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 - * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.120 2004/04/01 21:28:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.121 2004/05/26 04:41:10 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -72,7 +72,7 @@ ExplainQuery(ExplainStmt *stmt, DestReceiver *dest) Query *query = stmt->query; TupOutputState *tstate; List *rewritten; - List *l; + ListCell *l; /* prepare for projection of tuples */ tstate = begin_tup_output_tupdesc(dest, ExplainResultDesc(stmt)); @@ -104,7 +104,7 @@ ExplainQuery(ExplainStmt *stmt, DestReceiver *dest) { ExplainOneQuery(lfirst(l), stmt, tstate); /* put a blank line between plans */ - if (lnext(l) != NIL) + if (lnext(l) != NULL) do_text_output_oneline(tstate, ""); } } @@ -156,9 +156,9 @@ ExplainOneQuery(Query *query, ExplainStmt *stmt, TupOutputState *tstate) /* Still need to rewrite cursor command */ Assert(query->commandType == CMD_SELECT); rewritten = QueryRewrite(query); - if (length(rewritten) != 1) + if (list_length(rewritten) != 1) elog(ERROR, "unexpected rewrite result"); - query = (Query *) lfirst(rewritten); + query = (Query *) linitial(rewritten); Assert(query->commandType == CMD_SELECT); /* do not actually execute the underlying query! */ stmt->analyze = false; @@ -317,7 +317,7 @@ explain_outNode(StringInfo str, Plan *outer_plan, int indent, ExplainState *es) { - List *l; + ListCell *l; char *pname; int i; @@ -491,7 +491,7 @@ explain_outNode(StringInfo str, { Relation relation; - relation = index_open(lfirsto(l)); + relation = index_open(lfirst_oid(l)); appendStringInfo(str, "%s%s", (++i > 1) ? ", " : "", quote_identifier(RelationGetRelationName(relation))); @@ -699,7 +699,7 @@ explain_outNode(StringInfo str, if (plan->initPlan) { List *saved_rtable = es->rtable; - List *lst; + ListCell *lst; for (i = 0; i < indent; i++) appendStringInfo(str, " "); @@ -749,7 +749,7 @@ explain_outNode(StringInfo str, { Append *appendplan = (Append *) plan; AppendState *appendstate = (AppendState *) planstate; - List *lst; + ListCell *lst; int j; j = 0; @@ -797,7 +797,7 @@ explain_outNode(StringInfo str, if (planstate->subPlan) { List *saved_rtable = es->rtable; - List *lst; + ListCell *lst; for (i = 0; i < indent; i++) appendStringInfo(str, " "); @@ -839,11 +839,8 @@ show_scan_qual(List *qual, bool is_or_qual, const char *qlabel, /* No work if empty qual */ if (qual == NIL) return; - if (is_or_qual) - { - if (lfirst(qual) == NIL && lnext(qual) == NIL) - return; - } + if (is_or_qual && list_length(qual) == 1 && linitial(qual) == NIL) + return; /* Fix qual --- indexqual requires different processing */ if (is_or_qual) @@ -852,7 +849,7 @@ show_scan_qual(List *qual, bool is_or_qual, const char *qlabel, node = (Node *) make_ands_explicit(qual); /* Generate deparse context */ - Assert(scanrelid > 0 && scanrelid <= length(es->rtable)); + Assert(scanrelid > 0 && scanrelid <= list_length(es->rtable)); rte = rt_fetch(scanrelid, es->rtable); scancontext = deparse_context_for_rte(rte); @@ -984,7 +981,7 @@ show_sort_keys(List *tlist, int nkeys, AttrNumber *keycols, context = deparse_context_for_plan(0, NULL, 0, NULL, es->rtable); - useprefix = length(es->rtable) > 1; + useprefix = list_length(es->rtable) > 1; } bms_free(varnos); @@ -1017,17 +1014,16 @@ make_ors_ands_explicit(List *orclauses) { if (orclauses == NIL) return NULL; /* probably can't happen */ - else if (lnext(orclauses) == NIL) - return (Node *) make_ands_explicit(lfirst(orclauses)); + else if (list_length(orclauses) == 1) + return (Node *) make_ands_explicit(linitial(orclauses)); else { - FastList args; - List *orptr; + List *args = NIL; + ListCell *orptr; - FastListInit(&args); foreach(orptr, orclauses) - FastAppend(&args, make_ands_explicit(lfirst(orptr))); + args = lappend(args, make_ands_explicit(lfirst(orptr))); - return (Node *) make_orclause(FastListValue(&args)); + return (Node *) make_orclause(args); } } diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c index c118e8e3b5e..757869a925a 100644 --- a/src/backend/commands/functioncmds.c +++ b/src/backend/commands/functioncmds.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.46 2004/05/14 16:11:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/functioncmds.c,v 1.47 2004/05/26 04:41:11 neilc Exp $ * * DESCRIPTION * These routines take the parse tree and pick out the @@ -137,7 +137,7 @@ examine_parameter_list(List *parameter, Oid languageOid, Oid *parameterTypes, const char *parameterNames[]) { int parameterCount = 0; - List *x; + ListCell *x; MemSet(parameterTypes, 0, FUNC_MAX_ARGS * sizeof(Oid)); MemSet(parameterNames, 0, FUNC_MAX_ARGS * sizeof(char *)); @@ -202,14 +202,14 @@ examine_parameter_list(List *parameter, Oid languageOid, */ static void -compute_attributes_sql_style(const List *options, +compute_attributes_sql_style(List *options, List **as, char **language, char *volatility_p, bool *strict_p, bool *security_definer) { - const List *option; + ListCell *option; DefElem *as_item = NULL; DefElem *language_item = NULL; DefElem *volatility_item = NULL; @@ -322,7 +322,7 @@ compute_attributes_sql_style(const List *options, static void compute_attributes_with_style(List *parameters, bool *isStrict_p, char *volatility_p) { - List *pl; + ListCell *pl; foreach(pl, parameters) { @@ -357,7 +357,7 @@ compute_attributes_with_style(List *parameters, bool *isStrict_p, char *volatili */ static void -interpret_AS_clause(Oid languageOid, const char *languageName, const List *as, +interpret_AS_clause(Oid languageOid, const char *languageName, List *as, char **prosrc_str_p, char **probin_str_p) { Assert(as != NIL); @@ -368,8 +368,8 @@ interpret_AS_clause(Oid languageOid, const char *languageName, const List *as, * For "C" language, store the file name in probin and, when * given, the link symbol name in prosrc. */ - *probin_str_p = strVal(lfirst(as)); - if (lnext(as) == NULL) + *probin_str_p = strVal(linitial(as)); + if (list_length(as) == 1) *prosrc_str_p = "-"; else *prosrc_str_p = strVal(lsecond(as)); @@ -377,10 +377,10 @@ interpret_AS_clause(Oid languageOid, const char *languageName, const List *as, else { /* Everything else wants the given string in prosrc. */ - *prosrc_str_p = strVal(lfirst(as)); + *prosrc_str_p = strVal(linitial(as)); *probin_str_p = "-"; - if (lnext(as) != NIL) + if (list_length(as) != 1) ereport(ERROR, (errcode(ERRCODE_INVALID_FUNCTION_DEFINITION), errmsg("only one AS item needed for language \"%s\"", diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c index 448f99e1d37..1fe8e58e585 100644 --- a/src/backend/commands/indexcmds.c +++ b/src/backend/commands/indexcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.119 2004/05/08 00:34:49 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/indexcmds.c,v 1.120 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -109,7 +109,7 @@ DefineIndex(RangeVar *heapRelation, /* * count attributes in index */ - numberOfAttributes = length(attributeList); + numberOfAttributes = list_length(attributeList); if (numberOfAttributes <= 0) ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), @@ -165,7 +165,7 @@ DefineIndex(RangeVar *heapRelation, namespaceId); else { - IndexElem *iparam = (IndexElem *) lfirst(attributeList); + IndexElem *iparam = (IndexElem *) linitial(attributeList); indexRelationName = CreateIndexName(RelationGetRelationName(rel), iparam->name, @@ -208,7 +208,7 @@ DefineIndex(RangeVar *heapRelation, */ if (rangetable != NIL) { - if (length(rangetable) != 1 || getrelid(1, rangetable) != relationId) + if (list_length(rangetable) != 1 || getrelid(1, rangetable) != relationId) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("index expressions and predicates may refer only to the table being indexed"))); @@ -226,7 +226,7 @@ DefineIndex(RangeVar *heapRelation, if (primary) { List *cmds; - List *keys; + ListCell *keys; /* * If ALTER TABLE, check that there isn't already a PRIMARY KEY. @@ -399,7 +399,7 @@ ComputeIndexAttrs(IndexInfo *indexInfo, Oid accessMethodId, bool isconstraint) { - List *rest; + ListCell *rest; int attn = 0; /* @@ -516,9 +516,9 @@ GetIndexOpClass(List *opclass, Oid attrType, * Release 7.5 removes bigbox_ops (which was dead code for a long while * anyway). tgl 2003/11/11 */ - if (length(opclass) == 1) + if (list_length(opclass) == 1) { - char *claname = strVal(lfirst(opclass)); + char *claname = strVal(linitial(opclass)); if (strcmp(claname, "network_ops") == 0 || strcmp(claname, "timespan_ops") == 0 || @@ -697,8 +697,8 @@ static bool relationHasPrimaryKey(Relation rel) { bool result = false; - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *indexoidscan; /* * Get the list of index OIDs for the table from the relcache, and @@ -709,7 +709,7 @@ relationHasPrimaryKey(Relation rel) foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); HeapTuple indexTuple; indexTuple = SearchSysCache(INDEXRELID, @@ -723,7 +723,7 @@ relationHasPrimaryKey(Relation rel) break; } - freeList(indexoidlist); + list_free(indexoidlist); return result; } @@ -843,12 +843,13 @@ void ReindexDatabase(const char *dbname, bool force /* currently unused */, bool all) { - Relation relationRelation; + Relation relationRelation; HeapScanDesc scan; - HeapTuple tuple; + HeapTuple tuple; MemoryContext private_context; MemoryContext old; - List *relids = NIL; + List *relids = NIL; + ListCell *l; AssertArg(dbname); @@ -887,7 +888,7 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */, * reindexing itself will try to update pg_class. */ old = MemoryContextSwitchTo(private_context); - relids = lappendo(relids, RelOid_pg_class); + relids = lappend_oid(relids, RelOid_pg_class); MemoryContextSwitchTo(old); /* @@ -921,7 +922,7 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */, continue; /* got it already */ old = MemoryContextSwitchTo(private_context); - relids = lappendo(relids, HeapTupleGetOid(tuple)); + relids = lappend_oid(relids, HeapTupleGetOid(tuple)); MemoryContextSwitchTo(old); } heap_endscan(scan); @@ -929,9 +930,9 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */, /* Now reindex each rel in a separate transaction */ CommitTransactionCommand(); - while (relids) + foreach(l, relids) { - Oid relid = lfirsto(relids); + Oid relid = lfirst_oid(l); StartTransactionCommand(); SetQuerySnapshot(); /* might be needed for functions in @@ -941,7 +942,6 @@ ReindexDatabase(const char *dbname, bool force /* currently unused */, (errmsg("table \"%s\" was reindexed", get_rel_name(relid)))); CommitTransactionCommand(); - relids = lnext(relids); } StartTransactionCommand(); diff --git a/src/backend/commands/lockcmds.c b/src/backend/commands/lockcmds.c index 58bee42f8fe..7ab0687e983 100644 --- a/src/backend/commands/lockcmds.c +++ b/src/backend/commands/lockcmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.9 2004/03/11 01:47:35 ishii Exp $ + * $PostgreSQL: pgsql/src/backend/commands/lockcmds.c,v 1.10 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -28,7 +28,7 @@ void LockTableCommand(LockStmt *lockstmt) { - List *p; + ListCell *p; /* * Iterate over the list and open, lock, and close the relations one diff --git a/src/backend/commands/opclasscmds.c b/src/backend/commands/opclasscmds.c index d3551a7349f..db5c2ccabc9 100644 --- a/src/backend/commands/opclasscmds.c +++ b/src/backend/commands/opclasscmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.24 2003/11/29 19:51:47 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/commands/opclasscmds.c,v 1.25 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -77,7 +77,7 @@ DefineOpClass(CreateOpClassStmt *stmt) numProcs; /* amsupport value */ List *operators; /* OpClassMember list for operators */ List *procedures; /* OpClassMember list for support procs */ - List *l; + ListCell *l; Relation rel; HeapTuple tup; Datum values[Natts_pg_opclass]; @@ -168,7 +168,7 @@ DefineOpClass(CreateOpClassStmt *stmt) item->number, numOperators))); if (item->args != NIL) { - TypeName *typeName1 = (TypeName *) lfirst(item->args); + TypeName *typeName1 = (TypeName *) linitial(item->args); TypeName *typeName2 = (TypeName *) lsecond(item->args); operOid = LookupOperNameTypeNames(item->name, @@ -506,7 +506,7 @@ assignProcSubtype(Oid amoid, Oid typeoid, Oid procOid) static void addClassMember(List **list, OpClassMember *member, bool isProc) { - List *l; + ListCell *l; foreach(l, *list) { @@ -540,7 +540,7 @@ storeOperators(Oid opclassoid, List *operators) Datum values[Natts_pg_amop]; char nulls[Natts_pg_amop]; HeapTuple tup; - List *l; + ListCell *l; int i; rel = heap_openr(AccessMethodOperatorRelationName, RowExclusiveLock); @@ -584,7 +584,7 @@ storeProcedures(Oid opclassoid, List *procedures) Datum values[Natts_pg_amproc]; char nulls[Natts_pg_amproc]; HeapTuple tup; - List *l; + ListCell *l; int i; rel = heap_openr(AccessMethodProcedureRelationName, RowExclusiveLock); diff --git a/src/backend/commands/operatorcmds.c b/src/backend/commands/operatorcmds.c index a198f51eeeb..d2ffae2ce56 100644 --- a/src/backend/commands/operatorcmds.c +++ b/src/backend/commands/operatorcmds.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.15 2004/05/14 16:11:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/operatorcmds.c,v 1.16 2004/05/26 04:41:11 neilc Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -79,7 +79,7 @@ DefineOperator(List *names, List *parameters) List *rightSortName = NIL; /* optional right sort operator */ List *ltCompareName = NIL; /* optional < compare operator */ List *gtCompareName = NIL; /* optional > compare operator */ - List *pl; + ListCell *pl; /* Convert list of names to a name and namespace */ oprNamespace = QualifiedNameGetCreationNamespace(names, &oprName); @@ -167,13 +167,13 @@ DefineOperator(List *names, List *parameters) if (canMerge) { if (!leftSortName) - leftSortName = makeList1(makeString("<")); + leftSortName = list_make1(makeString("<")); if (!rightSortName) - rightSortName = makeList1(makeString("<")); + rightSortName = list_make1(makeString("<")); if (!ltCompareName) - ltCompareName = makeList1(makeString("<")); + ltCompareName = list_make1(makeString("<")); if (!gtCompareName) - gtCompareName = makeList1(makeString(">")); + gtCompareName = list_make1(makeString(">")); } /* @@ -206,7 +206,7 @@ void RemoveOperator(RemoveOperStmt *stmt) { List *operatorName = stmt->opname; - TypeName *typeName1 = (TypeName *) lfirst(stmt->args); + TypeName *typeName1 = (TypeName *) linitial(stmt->args); TypeName *typeName2 = (TypeName *) lsecond(stmt->args); Oid operOid; HeapTuple tup; diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index 855c9391c18..d2fa894a76e 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -14,7 +14,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.26 2004/03/21 22:29:10 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/portalcmds.c,v 1.27 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -68,9 +68,9 @@ PerformCursorOpen(DeclareCursorStmt *stmt) * strange. */ rewritten = QueryRewrite((Query *) stmt->query); - if (length(rewritten) != 1 || !IsA(lfirst(rewritten), Query)) + if (list_length(rewritten) != 1 || !IsA(linitial(rewritten), Query)) elog(ERROR, "unexpected rewrite result"); - query = (Query *) lfirst(rewritten); + query = (Query *) linitial(rewritten); if (query->commandType != CMD_SELECT) elog(ERROR, "unexpected rewrite result"); @@ -100,8 +100,8 @@ PerformCursorOpen(DeclareCursorStmt *stmt) PortalDefineQuery(portal, NULL, /* unfortunately don't have sourceText */ "SELECT", /* cursor's query is always a SELECT */ - makeList1(query), - makeList1(plan), + list_make1(query), + list_make1(plan), PortalGetHeapMemory(portal)); MemoryContextSwitchTo(oldContext); diff --git a/src/backend/commands/prepare.c b/src/backend/commands/prepare.c index d85d41c1ec7..083ad2af5e7 100644 --- a/src/backend/commands/prepare.c +++ b/src/backend/commands/prepare.c @@ -10,7 +10,7 @@ * Copyright (c) 2002-2003, PostgreSQL Global Development Group * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.26 2004/04/22 02:58:20 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.27 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -125,7 +125,7 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag) plan_list = entry->plan_list; qcontext = entry->context; - Assert(length(query_list) == length(plan_list)); + Assert(list_length(query_list) == list_length(plan_list)); /* Evaluate parameters, if any */ if (entry->argtype_list != NIL) @@ -162,11 +162,11 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag) plan_list = copyObject(plan_list); qcontext = PortalGetHeapMemory(portal); - if (length(query_list) != 1) + if (list_length(query_list) != 1) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), errmsg("prepared statement is not a SELECT"))); - query = (Query *) lfirst(query_list); + query = (Query *) linitial(query_list); if (query->commandType != CMD_SELECT) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), @@ -208,14 +208,14 @@ ExecuteQuery(ExecuteStmt *stmt, DestReceiver *dest, char *completionTag) static ParamListInfo EvaluateParams(EState *estate, List *params, List *argtypes) { - int nargs = length(argtypes); + int nargs = list_length(argtypes); ParamListInfo paramLI; List *exprstates; - List *l; + ListCell *l; int i = 0; /* Parser should have caught this error, but check for safety */ - if (length(params) != nargs) + if (list_length(params) != nargs) elog(ERROR, "wrong number of arguments"); exprstates = (List *) ExecPrepareExpr((Expr *) params, estate); @@ -326,7 +326,7 @@ StorePreparedStatement(const char *stmt_name, qstring = query_string ? pstrdup(query_string) : NULL; query_list = (List *) copyObject(query_list); plan_list = (List *) copyObject(plan_list); - argtype_list = listCopy(argtype_list); + argtype_list = list_copy(argtype_list); /* Now we can add entry to hash table */ entry = (PreparedStatement *) hash_search(prepared_queries, @@ -419,11 +419,11 @@ FetchPreparedStatementResultDesc(PreparedStatement *stmt) switch (ChoosePortalStrategy(stmt->query_list)) { case PORTAL_ONE_SELECT: - query = (Query *) lfirst(stmt->query_list); + query = (Query *) linitial(stmt->query_list); return ExecCleanTypeFromTL(query->targetList, false); case PORTAL_UTIL_SELECT: - query = (Query *) lfirst(stmt->query_list); + query = (Query *) linitial(stmt->query_list); return UtilityTupleDescriptor(query->utilityStmt); case PORTAL_MULTI_QUERY: @@ -478,8 +478,9 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate) { ExecuteStmt *execstmt = (ExecuteStmt *) stmt->query->utilityStmt; PreparedStatement *entry; - List *l, - *query_list, + ListCell *q, + *p; + List *query_list, *plan_list; ParamListInfo paramLI = NULL; EState *estate = NULL; @@ -493,7 +494,7 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate) query_list = entry->query_list; plan_list = entry->plan_list; - Assert(length(query_list) == length(plan_list)); + Assert(list_length(query_list) == list_length(plan_list)); /* Evaluate parameters, if any */ if (entry->argtype_list != NIL) @@ -508,14 +509,13 @@ ExplainExecuteQuery(ExplainStmt *stmt, TupOutputState *tstate) } /* Explain each query */ - foreach(l, query_list) + forboth (q, query_list, p, plan_list) { - Query *query = (Query *) lfirst(l); - Plan *plan = (Plan *) lfirst(plan_list); + Query *query = (Query *) lfirst(q); + Plan *plan = (Plan *) lfirst(p); bool is_last_query; - plan_list = lnext(plan_list); - is_last_query = (plan_list == NIL); + is_last_query = (lnext(p) == NULL); if (query->commandType == CMD_UTILITY) { diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c index 8af564cf74b..18a212271ea 100644 --- a/src/backend/commands/schemacmds.c +++ b/src/backend/commands/schemacmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.17 2003/11/29 19:51:47 pgsql Exp $ + * $PostgreSQL: pgsql/src/backend/commands/schemacmds.c,v 1.18 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -42,7 +42,7 @@ CreateSchemaCommand(CreateSchemaStmt *stmt) const char *authId = stmt->authid; Oid namespaceId; List *parsetree_list; - List *parsetree_item; + ListCell *parsetree_item; const char *owner_name; AclId owner_userid; AclId saved_userid; @@ -129,8 +129,8 @@ CreateSchemaCommand(CreateSchemaStmt *stmt) foreach(parsetree_item, parsetree_list) { Node *parsetree = (Node *) lfirst(parsetree_item); - List *querytree_list, - *querytree_item; + List *querytree_list; + ListCell *querytree_item; querytree_list = parse_analyze(parsetree, NULL, 0); @@ -166,11 +166,11 @@ RemoveSchema(List *names, DropBehavior behavior) Oid namespaceId; ObjectAddress object; - if (length(names) != 1) + if (list_length(names) != 1) ereport(ERROR, (errcode(ERRCODE_SYNTAX_ERROR), errmsg("schema name may not be qualified"))); - namespaceName = strVal(lfirst(names)); + namespaceName = strVal(linitial(names)); namespaceId = GetSysCacheOid(NAMESPACENAME, CStringGetDatum(namespaceName), diff --git a/src/backend/commands/sequence.c b/src/backend/commands/sequence.c index 0ff1b386b5b..351813b5dec 100644 --- a/src/backend/commands/sequence.c +++ b/src/backend/commands/sequence.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.110 2004/05/08 19:09:24 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.111 2004/05/26 04:41:11 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -862,7 +862,7 @@ init_params(List *options, Form_pg_sequence new, bool isInit) DefElem *min_value = NULL; DefElem *cache_value = NULL; DefElem *is_cycled = NULL; - List *option; + ListCell *option; foreach(option, options) { diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index bf308141fac..431c4ac742a 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.107 2004/05/08 22:46:29 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.108 2004/05/26 04:41:12 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -262,7 +262,7 @@ DefineRelation(CreateStmt *stmt, char relkind) bool localHasOids; int parentOidCount; List *rawDefaults; - List *listptr; + ListCell *listptr; int i; AttrNumber attnum; @@ -320,7 +320,7 @@ DefineRelation(CreateStmt *stmt, char relkind) if (old_constraints != NIL) { - ConstrCheck *check = (ConstrCheck *) palloc(length(old_constraints) * + ConstrCheck *check = (ConstrCheck *) palloc(list_length(old_constraints) * sizeof(ConstrCheck)); int ncheck = 0; int constr_name_ctr = 0; @@ -634,7 +634,7 @@ static List * MergeAttributes(List *schema, List *supers, bool istemp, List **supOids, List **supconstr, int *supOidCount) { - List *entry; + ListCell *entry; List *inhSchema = NIL; List *parentOids = NIL; List *constraints = NIL; @@ -654,9 +654,9 @@ MergeAttributes(List *schema, List *supers, bool istemp, foreach(entry, schema) { ColumnDef *coldef = lfirst(entry); - List *rest; + ListCell *rest; - foreach(rest, lnext(entry)) + for_each_cell(rest, lnext(entry)) { ColumnDef *restdef = lfirst(rest); @@ -708,13 +708,13 @@ MergeAttributes(List *schema, List *supers, bool istemp, /* * Reject duplications in the list of parents. */ - if (oidMember(RelationGetRelid(relation), parentOids)) + if (list_member_oid(parentOids, RelationGetRelid(relation))) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_TABLE), errmsg("inherited relation \"%s\" duplicated", parent->relname))); - parentOids = lappendo(parentOids, RelationGetRelid(relation)); + parentOids = lappend_oid(parentOids, RelationGetRelid(relation)); if (relation->rd_rel->relhasoids) parentsWithOids++; @@ -767,7 +767,7 @@ MergeAttributes(List *schema, List *supers, bool istemp, ereport(NOTICE, (errmsg("merging multiple inherited definitions of column \"%s\"", attributeName))); - def = (ColumnDef *) nth(exist_attno - 1, inhSchema); + def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1); if (typenameTypeId(def->typename) != attribute->atttypid || def->typename->typmod != attribute->atttypmod) ereport(ERROR, @@ -922,7 +922,7 @@ MergeAttributes(List *schema, List *supers, bool istemp, ereport(NOTICE, (errmsg("merging column \"%s\" with inherited definition", attributeName))); - def = (ColumnDef *) nth(exist_attno - 1, inhSchema); + def = (ColumnDef *) list_nth(inhSchema, exist_attno - 1); if (typenameTypeId(def->typename) != typenameTypeId(newdef->typename) || def->typename->typmod != newdef->typename->typmod) ereport(ERROR, @@ -1033,7 +1033,7 @@ StoreCatalogInheritance(Oid relationId, List *supers) Relation relation; TupleDesc desc; int16 seqNumber; - List *entry; + ListCell *entry; HeapTuple tuple; /* @@ -1059,7 +1059,7 @@ StoreCatalogInheritance(Oid relationId, List *supers) seqNumber = 1; foreach(entry, supers) { - Oid parentOid = lfirsto(entry); + Oid parentOid = lfirst_oid(entry); Datum datum[Natts_pg_inherits]; char nullarr[Natts_pg_inherits]; ObjectAddress childobject, @@ -1113,16 +1113,17 @@ StoreCatalogInheritance(Oid relationId, List *supers) static int findAttrByName(const char *attributeName, List *schema) { - List *s; - int i = 0; + ListCell *s; + int i = 1; foreach(s, schema) { ColumnDef *def = lfirst(s); - ++i; if (strcmp(attributeName, def->colname) == 0) return i; + + i++; } return 0; } @@ -1198,7 +1199,7 @@ renameatt(Oid myrelid, Form_pg_attribute attform; int attnum; List *indexoidlist; - List *indexoidscan; + ListCell *indexoidscan; /* * Grab an exclusive lock on the target table, which we will NOT @@ -1232,8 +1233,8 @@ renameatt(Oid myrelid, */ if (recurse) { - List *child, - *children; + ListCell *child; + List *children; /* this routine is actually in the planner */ children = find_all_inheritors(myrelid); @@ -1245,7 +1246,7 @@ renameatt(Oid myrelid, */ foreach(child, children) { - Oid childrelid = lfirsto(child); + Oid childrelid = lfirst_oid(child); if (childrelid == myrelid) continue; @@ -1322,7 +1323,7 @@ renameatt(Oid myrelid, foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); HeapTuple indextup; Form_pg_index indexform; int i; @@ -1370,7 +1371,7 @@ renameatt(Oid myrelid, ReleaseSysCache(indextup); } - freeList(indexoidlist); + list_free(indexoidlist); heap_close(attrelation, RowExclusiveLock); @@ -1765,7 +1766,7 @@ static void ATController(Relation rel, List *cmds, bool recurse) { List *wqueue = NIL; - List *lcmd; + ListCell *lcmd; /* Phase 1: preliminary examination of commands, create work queue */ foreach(lcmd, cmds) @@ -1962,7 +1963,7 @@ static void ATRewriteCatalogs(List **wqueue) { int pass; - List *ltab; + ListCell *ltab; /* * We process all the tables "in parallel", one pass at a time. This @@ -1979,7 +1980,7 @@ ATRewriteCatalogs(List **wqueue) AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab); List *subcmds = tab->subcmds[pass]; Relation rel; - List *lcmd; + ListCell *lcmd; if (subcmds == NIL) continue; @@ -2107,7 +2108,7 @@ ATExecCmd(AlteredTableInfo *tab, Relation rel, AlterTableCmd *cmd) static void ATRewriteTables(List **wqueue) { - List *ltab; + ListCell *ltab; /* Go through each table that needs to be checked or rewritten */ foreach(ltab, *wqueue) @@ -2215,7 +2216,7 @@ ATRewriteTables(List **wqueue) { AlteredTableInfo *tab = (AlteredTableInfo *) lfirst(ltab); Relation rel = NULL; - List *lcon; + ListCell *lcon; foreach(lcon, tab->constraints) { @@ -2259,7 +2260,7 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap) TupleDesc newTupDesc; bool needscan = false; int i; - List *l; + ListCell *l; EState *estate; /* @@ -2473,7 +2474,7 @@ ATGetQueueEntry(List **wqueue, Relation rel) { Oid relid = RelationGetRelid(rel); AlteredTableInfo *tab; - List *ltab; + ListCell *ltab; foreach(ltab, *wqueue) { @@ -2554,8 +2555,8 @@ ATSimpleRecursion(List **wqueue, Relation rel, if (recurse && rel->rd_rel->relkind == RELKIND_RELATION) { Oid relid = RelationGetRelid(rel); - List *child, - *children; + ListCell *child; + List *children; /* this routine is actually in the planner */ children = find_all_inheritors(relid); @@ -2567,7 +2568,7 @@ ATSimpleRecursion(List **wqueue, Relation rel, */ foreach(child, children) { - Oid childrelid = lfirsto(child); + Oid childrelid = lfirst_oid(child); Relation childrel; if (childrelid == relid) @@ -2592,15 +2593,15 @@ ATOneLevelRecursion(List **wqueue, Relation rel, AlterTableCmd *cmd) { Oid relid = RelationGetRelid(rel); - List *child, - *children; + ListCell *child; + List *children; /* this routine is actually in the planner */ children = find_inheritance_children(relid); foreach(child, children) { - Oid childrelid = lfirsto(child); + Oid childrelid = lfirst_oid(child); Relation childrel; childrel = relation_open(childrelid, AccessExclusiveLock); @@ -2764,7 +2765,7 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel, attribute->atttypmod = colDef->typename->typmod; attribute->attnum = i; attribute->attbyval = tform->typbyval; - attribute->attndims = length(colDef->typename->arrayBounds); + attribute->attndims = list_length(colDef->typename->arrayBounds); attribute->attstorage = tform->typstorage; attribute->attalign = tform->typalign; attribute->attnotnull = colDef->is_not_null; @@ -2814,7 +2815,7 @@ ATExecAddColumn(AlteredTableInfo *tab, Relation rel, * This function is intended for CREATE TABLE, so it processes a * _list_ of defaults, but we just do one. */ - AddRelationRawConstraints(rel, makeList1(rawEnt), NIL); + AddRelationRawConstraints(rel, list_make1(rawEnt), NIL); /* Make the additional catalog changes visible */ CommandCounterIncrement(); @@ -2880,7 +2881,7 @@ ATExecDropNotNull(Relation rel, const char *colName) AttrNumber attnum; Relation attr_rel; List *indexoidlist; - List *indexoidscan; + ListCell *indexoidscan; /* * lookup the attribute @@ -2913,7 +2914,7 @@ ATExecDropNotNull(Relation rel, const char *colName) foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); HeapTuple indexTuple; Form_pg_index indexStruct; int i; @@ -2945,7 +2946,7 @@ ATExecDropNotNull(Relation rel, const char *colName) ReleaseSysCache(indexTuple); } - freeList(indexoidlist); + list_free(indexoidlist); /* * Okay, actually perform the catalog change ... if needed @@ -3067,7 +3068,7 @@ ATExecColumnDefault(Relation rel, const char *colName, * This function is intended for CREATE TABLE, so it processes a * _list_ of defaults, but we just do one. */ - AddRelationRawConstraints(rel, makeList1(rawEnt), NIL); + AddRelationRawConstraints(rel, list_make1(rawEnt), NIL); } } @@ -3292,12 +3293,12 @@ ATExecDropColumn(Relation rel, const char *colName, if (children) { Relation attr_rel; - List *child; + ListCell *child; attr_rel = heap_openr(AttributeRelationName, RowExclusiveLock); foreach(child, children) { - Oid childrelid = lfirsto(child); + Oid childrelid = lfirst_oid(child); Relation childrel; Form_pg_attribute childatt; @@ -3464,14 +3465,14 @@ ATExecAddConstraint(AlteredTableInfo *tab, Relation rel, Node *newConstraint) case CONSTR_CHECK: { List *newcons; - List *lcon; + ListCell *lcon; /* * Call AddRelationRawConstraints to do the work. * It returns a list of cooked constraints. */ newcons = AddRelationRawConstraints(rel, NIL, - makeList1(constr)); + list_make1(constr)); /* Add each constraint to Phase 3's queue */ foreach(lcon, newcons) { @@ -3676,7 +3677,7 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, * get the right answer from the test below on opclass membership * unless we select the proper operator.) */ - Operator o = oper(makeList1(makeString("=")), + Operator o = oper(list_make1(makeString("=")), pktypoid[i], fktypoid[i], true); if (o == NULL) @@ -3687,8 +3688,8 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, fkconstraint->constr_name), errdetail("Key columns \"%s\" and \"%s\" " "are of incompatible types: %s and %s.", - strVal(nth(i, fkconstraint->fk_attrs)), - strVal(nth(i, fkconstraint->pk_attrs)), + strVal(list_nth(fkconstraint->fk_attrs, i)), + strVal(list_nth(fkconstraint->pk_attrs, i)), format_type_be(fktypoid[i]), format_type_be(pktypoid[i])))); @@ -3704,8 +3705,8 @@ ATAddForeignKeyConstraint(AlteredTableInfo *tab, Relation rel, fkconstraint->constr_name), errdetail("Key columns \"%s\" and \"%s\" " "are of different types: %s and %s.", - strVal(nth(i, fkconstraint->fk_attrs)), - strVal(nth(i, fkconstraint->pk_attrs)), + strVal(list_nth(fkconstraint->fk_attrs, i)), + strVal(list_nth(fkconstraint->pk_attrs, i)), format_type_be(fktypoid[i]), format_type_be(pktypoid[i])))); @@ -3774,7 +3775,7 @@ static int transformColumnNameList(Oid relId, List *colList, int16 *attnums, Oid *atttypids) { - List *l; + ListCell *l; int attnum; attnum = 0; @@ -3821,8 +3822,8 @@ transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, int16 *attnums, Oid *atttypids, Oid *opclasses) { - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *indexoidscan; HeapTuple indexTuple = NULL; Form_pg_index indexStruct = NULL; int i; @@ -3836,7 +3837,7 @@ transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); indexTuple = SearchSysCache(INDEXRELID, ObjectIdGetDatum(indexoid), @@ -3853,7 +3854,7 @@ transformFkeyGetPrimaryKey(Relation pkrel, Oid *indexOid, indexStruct = NULL; } - freeList(indexoidlist); + list_free(indexoidlist); /* * Check that we found it @@ -3900,8 +3901,8 @@ transformFkeyCheckAttrs(Relation pkrel, { Oid indexoid = InvalidOid; bool found = false; - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *indexoidscan; /* * Get the list of index OIDs for the table from the relcache, and @@ -3917,7 +3918,7 @@ transformFkeyCheckAttrs(Relation pkrel, int i, j; - indexoid = lfirsto(indexoidscan); + indexoid = lfirst_oid(indexoidscan); indexTuple = SearchSysCache(INDEXRELID, ObjectIdGetDatum(indexoid), 0, 0, 0); @@ -3982,7 +3983,7 @@ transformFkeyCheckAttrs(Relation pkrel, errmsg("there is no unique constraint matching given keys for referenced table \"%s\"", RelationGetRelationName(pkrel)))); - freeList(indexoidlist); + list_free(indexoidlist); return indexoid; } @@ -4001,7 +4002,7 @@ validateForeignKeyConstraint(FkConstraint *fkconstraint, HeapScanDesc scan; HeapTuple tuple; Trigger trig; - List *list; + ListCell *list; int count; /* @@ -4026,8 +4027,8 @@ validateForeignKeyConstraint(FkConstraint *fkconstraint, trig.tginitdeferred = FALSE; trig.tgargs = (char **) palloc(sizeof(char *) * - (4 + length(fkconstraint->fk_attrs) - + length(fkconstraint->pk_attrs))); + (4 + list_length(fkconstraint->fk_attrs) + + list_length(fkconstraint->pk_attrs))); trig.tgargs[0] = trig.tgname; trig.tgargs[1] = RelationGetRelationName(rel); @@ -4094,8 +4095,8 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, { RangeVar *myRel; CreateTrigStmt *fk_trigger; - List *fk_attr; - List *pk_attr; + ListCell *fk_attr; + ListCell *pk_attr; ObjectAddress trigobj, constrobj; @@ -4146,19 +4147,16 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); - fk_attr = fkconstraint->fk_attrs; - pk_attr = fkconstraint->pk_attrs; - if (length(fk_attr) != length(pk_attr)) + if (list_length(fkconstraint->fk_attrs) != list_length(fkconstraint->pk_attrs)) ereport(ERROR, (errcode(ERRCODE_INVALID_FOREIGN_KEY), errmsg("number of referencing and referenced columns for foreign key disagree"))); - while (fk_attr != NIL) + forboth(fk_attr, fkconstraint->fk_attrs, + pk_attr, fkconstraint->pk_attrs) { fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr)); - fk_attr = lnext(fk_attr); - pk_attr = lnext(pk_attr); } trigobj.objectId = CreateTrigger(fk_trigger, true); @@ -4219,14 +4217,11 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); - fk_attr = fkconstraint->fk_attrs; - pk_attr = fkconstraint->pk_attrs; - while (fk_attr != NIL) + forboth(fk_attr, fkconstraint->fk_attrs, + pk_attr, fkconstraint->pk_attrs) { fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr)); - fk_attr = lnext(fk_attr); - pk_attr = lnext(pk_attr); } trigobj.objectId = CreateTrigger(fk_trigger, true); @@ -4286,14 +4281,11 @@ createForeignKeyTriggers(Relation rel, FkConstraint *fkconstraint, makeString(fkconstraint->pktable->relname)); fk_trigger->args = lappend(fk_trigger->args, makeString(fkMatchTypeToString(fkconstraint->fk_matchtype))); - fk_attr = fkconstraint->fk_attrs; - pk_attr = fkconstraint->pk_attrs; - while (fk_attr != NIL) + forboth(fk_attr, fkconstraint->fk_attrs, + pk_attr, fkconstraint->pk_attrs) { fk_trigger->args = lappend(fk_trigger->args, lfirst(fk_attr)); fk_trigger->args = lappend(fk_trigger->args, lfirst(pk_attr)); - fk_attr = lnext(fk_attr); - pk_attr = lnext(pk_attr); } trigobj.objectId = CreateTrigger(fk_trigger, true); @@ -4626,9 +4618,9 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, if (relKind == RELKIND_INDEX) { Assert(foundObject.objectSubId == 0); - if (!oidMember(foundObject.objectId, tab->changedIndexOids)) + if (!list_member_oid(tab->changedIndexOids, foundObject.objectId)) { - tab->changedIndexOids = lappendo(tab->changedIndexOids, + tab->changedIndexOids = lappend_oid(tab->changedIndexOids, foundObject.objectId); tab->changedIndexDefs = lappend(tab->changedIndexDefs, pg_get_indexdef_string(foundObject.objectId)); @@ -4653,9 +4645,9 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, case OCLASS_CONSTRAINT: Assert(foundObject.objectSubId == 0); - if (!oidMember(foundObject.objectId, tab->changedConstraintOids)) + if (!list_member_oid(tab->changedConstraintOids, foundObject.objectId)) { - tab->changedConstraintOids = lappendo(tab->changedConstraintOids, + tab->changedConstraintOids = lappend_oid(tab->changedConstraintOids, foundObject.objectId); tab->changedConstraintDefs = lappend(tab->changedConstraintDefs, pg_get_constraintdef_string(foundObject.objectId)); @@ -4750,7 +4742,7 @@ ATExecAlterColumnType(AlteredTableInfo *tab, Relation rel, */ attTup->atttypid = targettype; attTup->atttypmod = typename->typmod; - attTup->attndims = length(typename->arrayBounds); + attTup->attndims = list_length(typename->arrayBounds); attTup->attlen = tform->typlen; attTup->attbyval = tform->typbyval; attTup->attalign = tform->typalign; @@ -4805,7 +4797,7 @@ static void ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab) { ObjectAddress obj; - List *l; + ListCell *l; /* * Re-parse the index and constraint definitions, and attach them to @@ -4835,7 +4827,7 @@ ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab) obj.classId = get_system_catalog_relid(ConstraintRelationName); foreach(l, tab->changedConstraintOids) { - obj.objectId = lfirsto(l); + obj.objectId = lfirst_oid(l); obj.objectSubId = 0; performDeletion(&obj, DROP_RESTRICT); } @@ -4843,7 +4835,7 @@ ATPostAlterTypeCleanup(List **wqueue, AlteredTableInfo *tab) obj.classId = RelOid_pg_class; foreach(l, tab->changedIndexOids) { - obj.objectId = lfirsto(l); + obj.objectId = lfirst_oid(l); obj.objectSubId = 0; performDeletion(&obj, DROP_RESTRICT); } @@ -4859,7 +4851,7 @@ ATPostAlterTypeParse(char *cmd, List **wqueue) { List *raw_parsetree_list; List *querytree_list; - List *list_item; + ListCell *list_item; /* * We expect that we only have to do raw parsing and parse analysis, not @@ -4871,7 +4863,7 @@ ATPostAlterTypeParse(char *cmd, List **wqueue) { Node *parsetree = (Node *) lfirst(list_item); - querytree_list = nconc(querytree_list, + querytree_list = list_concat(querytree_list, parse_analyze(parsetree, NULL, 0)); } @@ -4907,7 +4899,7 @@ ATPostAlterTypeParse(char *cmd, List **wqueue) case T_AlterTableStmt: { AlterTableStmt *stmt = (AlterTableStmt *) query->utilityStmt; - List *lcmd; + ListCell *lcmd; rel = relation_openrv(stmt->relation, AccessExclusiveLock); tab = ATGetQueueEntry(wqueue, rel); @@ -5002,17 +4994,17 @@ ATExecChangeOwner(Oid relationOid, int32 newOwnerSysId) if (tuple_class->relkind == RELKIND_RELATION || tuple_class->relkind == RELKIND_TOASTVALUE) { - List *index_oid_list, - *i; + List *index_oid_list; + ListCell *i; /* Find all the indexes belonging to this relation */ index_oid_list = RelationGetIndexList(target_rel); /* For each index, recursively change its ownership */ foreach(i, index_oid_list) - ATExecChangeOwner(lfirsto(i), newOwnerSysId); + ATExecChangeOwner(lfirst_oid(i), newOwnerSysId); - freeList(index_oid_list); + list_free(index_oid_list); } if (tuple_class->relkind == RELKIND_RELATION) @@ -5362,7 +5354,7 @@ register_on_commit_action(Oid relid, OnCommitAction action) void remove_on_commit_action(Oid relid) { - List *l; + ListCell *l; foreach(l, on_commits) { @@ -5385,7 +5377,7 @@ remove_on_commit_action(Oid relid) void PreCommit_on_commit_actions(void) { - List *l; + ListCell *l; foreach(l, on_commits) { @@ -5437,40 +5429,34 @@ PreCommit_on_commit_actions(void) void AtEOXact_on_commit_actions(bool isCommit) { - List *l, - *prev; + ListCell *cur_item; + ListCell *prev_item; - prev = NIL; - l = on_commits; - while (l != NIL) + prev_item = NULL; + cur_item = list_head(on_commits); + + while (cur_item != NULL) { - OnCommitItem *oc = (OnCommitItem *) lfirst(l); + OnCommitItem *oc = (OnCommitItem *) lfirst(cur_item); if (isCommit ? oc->deleted_in_cur_xact : oc->created_in_cur_xact) { - /* This entry must be removed */ - if (prev != NIL) - { - lnext(prev) = lnext(l); - pfree(l); - l = lnext(prev); - } - else - { - on_commits = lnext(l); - pfree(l); - l = on_commits; - } + /* cur_item must be removed */ + on_commits = list_delete_cell(on_commits, cur_item, prev_item); pfree(oc); + if (prev_item) + cur_item = lnext(prev_item); + else + cur_item = list_head(on_commits); } else { - /* This entry must be preserved */ - oc->created_in_cur_xact = false; + /* cur_item must be preserved */ oc->deleted_in_cur_xact = false; - prev = l; - l = lnext(l); + oc->created_in_cur_xact = false; + prev_item = cur_item; + cur_item = lnext(prev_item); } } } diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c index bddf3f5ad68..cfbd58e4282 100644 --- a/src/backend/commands/trigger.c +++ b/src/backend/commands/trigger.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.164 2004/02/10 01:55:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/trigger.c,v 1.165 2004/05/26 04:41:12 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -111,19 +111,19 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) bool needconstrrelid = false; void *elem = NULL; - if (strncmp(strVal(llast(stmt->funcname)), "RI_FKey_check_", 14) == 0) + if (strncmp(strVal(lfirst(list_tail((stmt->funcname)))), "RI_FKey_check_", 14) == 0) { /* A trigger on FK table. */ needconstrrelid = true; - if (length(stmt->args) > RI_PK_RELNAME_ARGNO) - elem = nth(RI_PK_RELNAME_ARGNO, stmt->args); + if (list_length(stmt->args) > RI_PK_RELNAME_ARGNO) + elem = list_nth(stmt->args, RI_PK_RELNAME_ARGNO); } - else if (strncmp(strVal(llast(stmt->funcname)), "RI_FKey_", 8) == 0) + else if (strncmp(strVal(lfirst(list_tail((stmt->funcname)))), "RI_FKey_", 8) == 0) { /* A trigger on PK table. */ needconstrrelid = true; - if (length(stmt->args) > RI_FK_RELNAME_ARGNO) - elem = nth(RI_FK_RELNAME_ARGNO, stmt->args); + if (list_length(stmt->args) > RI_FK_RELNAME_ARGNO) + elem = list_nth(stmt->args, RI_FK_RELNAME_ARGNO); } if (elem != NULL) { @@ -318,9 +318,9 @@ CreateTrigger(CreateTrigStmt *stmt, bool forConstraint) if (stmt->args) { - List *le; + ListCell *le; char *args; - int16 nargs = length(stmt->args); + int16 nargs = list_length(stmt->args); int len = 0; foreach(le, stmt->args) @@ -1691,7 +1691,7 @@ static bool deferredTriggerCheckState(Oid tgoid, int32 itemstate) { MemoryContext oldcxt; - List *sl; + ListCell *sl; DeferredTriggerStatus trigstate; /* @@ -2193,7 +2193,7 @@ DeferredTriggerAbortXact(void) void DeferredTriggerSetState(ConstraintsSetStmt *stmt) { - List *l; + ListCell *l; /* * Ignore call if we aren't in a transaction. @@ -2210,15 +2210,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) * Drop all per-transaction information about individual trigger * states. */ - l = deferredTriggers->deftrig_trigstates; - while (l != NIL) - { - List *next = lnext(l); - - pfree(lfirst(l)); - pfree(l); - l = next; - } + list_free_deep(deferredTriggers->deftrig_trigstates); deferredTriggers->deftrig_trigstates = NIL; /* @@ -2233,7 +2225,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) MemoryContext oldcxt; bool found; DeferredTriggerStatus state; - List *ls; + ListCell *ls; List *loid = NIL; /* ---------- @@ -2293,7 +2285,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) cname))); constr_oid = HeapTupleGetOid(htup); - loid = lappendo(loid, constr_oid); + loid = lappend_oid(loid, constr_oid); found = true; } @@ -2321,7 +2313,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) foreach(ls, deferredTriggers->deftrig_trigstates) { state = (DeferredTriggerStatus) lfirst(ls); - if (state->dts_tgoid == lfirsto(l)) + if (state->dts_tgoid == lfirst_oid(l)) { state->dts_tgisdeferred = stmt->deferred; found = true; @@ -2332,7 +2324,7 @@ DeferredTriggerSetState(ConstraintsSetStmt *stmt) { state = (DeferredTriggerStatus) palloc(sizeof(DeferredTriggerStatusData)); - state->dts_tgoid = lfirsto(l); + state->dts_tgoid = lfirst_oid(l); state->dts_tgisdeferred = stmt->deferred; deferredTriggers->deftrig_trigstates = diff --git a/src/backend/commands/typecmds.c b/src/backend/commands/typecmds.c index 03428369ff4..d8a2a5b20f5 100644 --- a/src/backend/commands/typecmds.c +++ b/src/backend/commands/typecmds.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.56 2004/05/14 16:11:25 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/typecmds.c,v 1.57 2004/05/26 04:41:12 neilc Exp $ * * DESCRIPTION * The "DefineFoo" routines take the parse tree and pick out the @@ -114,7 +114,7 @@ DefineType(List *names, List *parameters) Oid sendOid = InvalidOid; Oid analyzeOid = InvalidOid; char *shadow_type; - List *pl; + ListCell *pl; Oid typoid; Oid resulttype; @@ -502,10 +502,10 @@ DefineDomain(CreateDomainStmt *stmt) bool typNotNull = false; bool nullDefined = false; Oid basetypelem; - int32 typNDims = length(stmt->typename->arrayBounds); + int32 typNDims = list_length(stmt->typename->arrayBounds); HeapTuple typeTup; List *schema = stmt->constraints; - List *listptr; + ListCell *listptr; Oid basetypeoid; Oid domainoid; Form_pg_type baseType; @@ -1304,7 +1304,7 @@ AlterDomainNotNull(List *names, bool notNull) if (notNull) { List *rels; - List *rt; + ListCell *rt; /* Fetch relation list with attributes based on this domain */ /* ShareLock is sufficient to prevent concurrent data changes */ @@ -1461,7 +1461,7 @@ AlterDomainAddConstraint(List *names, Node *newConstraint) HeapTuple tup; Form_pg_type typTup; List *rels; - List *rt; + ListCell *rt; EState *estate; ExprContext *econtext; char *ccbin; @@ -1681,7 +1681,7 @@ get_rels_with_domain(Oid domainOid, LOCKMODE lockmode) { Form_pg_depend pg_depend = (Form_pg_depend) GETSTRUCT(depTup); RelToCheck *rtc = NULL; - List *rellist; + ListCell *rellist; Form_pg_attribute pg_att; int ptr; @@ -1848,7 +1848,7 @@ domainAddConstraint(Oid domainOid, Oid domainNamespace, Oid baseTypeOid, /* * Make sure no outside relations are referred to. */ - if (length(pstate->p_rtable) != 0) + if (list_length(pstate->p_rtable) != 0) ereport(ERROR, (errcode(ERRCODE_INVALID_COLUMN_REFERENCE), errmsg("cannot use table references in domain check constraint"))); diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c index 476e7e1865e..255428fadc7 100644 --- a/src/backend/commands/user.c +++ b/src/backend/commands/user.c @@ -6,7 +6,7 @@ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.140 2004/05/06 16:59:16 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/commands/user.c,v 1.141 2004/05/26 04:41:12 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -491,8 +491,8 @@ CreateUser(CreateUserStmt *stmt) sysid_exists = false, havesysid = false; int max_id; - List *item, - *option; + ListCell *item; + ListCell *option; char *password = NULL; /* PostgreSQL user password */ bool encrypt_password = Password_encryption; /* encrypt password? */ char encrypted_password[MD5_PASSWD_LEN + 1]; @@ -715,7 +715,7 @@ CreateUser(CreateUserStmt *stmt) ags.name = strVal(lfirst(item)); /* the group name to add * this in */ ags.action = +1; - ags.listUsers = makeList1(makeInteger(sysid)); + ags.listUsers = list_make1(makeInteger(sysid)); AlterGroup(&ags, "CREATE USER"); } @@ -746,7 +746,7 @@ AlterUser(AlterUserStmt *stmt) TupleDesc pg_shadow_dsc; HeapTuple tuple, new_tuple; - List *option; + ListCell *option; char *password = NULL; /* PostgreSQL user password */ bool encrypt_password = Password_encryption; /* encrypt password? */ char encrypted_password[MD5_PASSWD_LEN + 1]; @@ -1017,7 +1017,7 @@ DropUser(DropUserStmt *stmt) { Relation pg_shadow_rel; TupleDesc pg_shadow_dsc; - List *item; + ListCell *item; if (!superuser()) ereport(ERROR, @@ -1122,7 +1122,7 @@ DropUser(DropUserStmt *stmt) /* the group name from which to try to drop the user: */ ags.name = pstrdup(NameStr(((Form_pg_group) GETSTRUCT(tmp_tuple))->groname)); ags.action = -1; - ags.listUsers = makeList1(makeInteger(usesysid)); + ags.listUsers = list_make1(makeInteger(usesysid)); AlterGroup(&ags, "DROP USER"); } heap_endscan(scan); @@ -1283,9 +1283,9 @@ CreateGroup(CreateGroupStmt *stmt) int max_id; Datum new_record[Natts_pg_group]; char new_record_nulls[Natts_pg_group]; - List *item, - *option, - *newlist = NIL; + ListCell *item; + ListCell *option; + List *newlist = NIL; IdList *grolist; int sysid = 0; List *userElts = NIL; @@ -1397,8 +1397,8 @@ CreateGroup(CreateGroupStmt *stmt) const char *groupuser = strVal(lfirst(item)); int32 userid = get_usesysid(groupuser); - if (!intMember(userid, newlist)) - newlist = lappendi(newlist, userid); + if (!list_member_int(newlist, userid)) + newlist = lappend_int(newlist, userid); } /* build an array to insert */ @@ -1454,8 +1454,8 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) IdList *oldarray; Datum datum; bool null; - List *newlist, - *item; + List *newlist; + ListCell *item; /* * Make sure the user can do this. @@ -1525,8 +1525,8 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) sysid = 0; /* keep compiler quiet */ } - if (!intMember(sysid, newlist)) - newlist = lappendi(newlist, sysid); + if (!list_member_int(newlist, sysid)) + newlist = lappend_int(newlist, sysid); } /* Do the update */ @@ -1565,8 +1565,8 @@ AlterGroup(AlterGroupStmt *stmt, const char *tag) /* for dropuser we already know the uid */ sysid = intVal(lfirst(item)); } - if (intMember(sysid, newlist)) - newlist = lremovei(sysid, newlist); + if (list_member_int(newlist, sysid)) + newlist = list_delete_int(newlist, sysid); else if (!is_dropuser) ereport(WARNING, (errcode(ERRCODE_WARNING), @@ -1636,9 +1636,9 @@ UpdateGroupMembership(Relation group_rel, HeapTuple group_tuple, static IdList * IdListToArray(List *members) { - int nmembers = length(members); + int nmembers = list_length(members); IdList *newarray; - List *item; + ListCell *item; int i; newarray = palloc(ARR_OVERHEAD(1) + nmembers * sizeof(int32)); @@ -1650,7 +1650,7 @@ IdListToArray(List *members) ARR_DIMS(newarray)[0] = nmembers; /* axis is this long */ i = 0; foreach(item, members) - ((int *) ARR_DATA_PTR(newarray))[i++] = lfirsti(item); + ((int *) ARR_DATA_PTR(newarray))[i++] = lfirst_int(item); return newarray; } @@ -1679,8 +1679,8 @@ IdArrayToList(IdList *oldarray) sysid = ((int32 *) ARR_DATA_PTR(oldarray))[i]; /* filter out any duplicates --- probably a waste of time */ - if (!intMember(sysid, newlist)) - newlist = lappendi(newlist, sysid); + if (!list_member_int(newlist, sysid)) + newlist = lappend_int(newlist, sysid); } return newlist; diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c index 5822b7f210c..b2ebda8e975 100644 --- a/src/backend/commands/vacuum.c +++ b/src/backend/commands/vacuum.c @@ -13,7 +13,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.277 2004/05/22 23:14:38 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.278 2004/05/26 04:41:12 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -164,8 +164,8 @@ vacuum(VacuumStmt *vacstmt) bool all_rels, in_outer_xact, use_own_xacts; - List *relations, - *cur; + List *relations; + ListCell *cur; if (vacstmt->verbose) elevel = INFO; @@ -276,7 +276,7 @@ vacuum(VacuumStmt *vacstmt) Assert(vacstmt->analyze); if (in_outer_xact) use_own_xacts = false; - else if (length(relations) > 1) + else if (list_length(relations) > 1) use_own_xacts = true; else use_own_xacts = false; @@ -312,7 +312,7 @@ vacuum(VacuumStmt *vacstmt) */ foreach(cur, relations) { - Oid relid = lfirsto(cur); + Oid relid = lfirst_oid(cur); if (vacstmt->vacuum) { @@ -431,7 +431,7 @@ get_rel_oids(const RangeVar *vacrel, const char *stmttype) /* Make a relation list entry for this guy */ oldcontext = MemoryContextSwitchTo(vac_context); - oid_list = lappendo(oid_list, relid); + oid_list = lappend_oid(oid_list, relid); MemoryContextSwitchTo(oldcontext); } else @@ -455,7 +455,7 @@ get_rel_oids(const RangeVar *vacrel, const char *stmttype) { /* Make a relation list entry for this guy */ oldcontext = MemoryContextSwitchTo(vac_context); - oid_list = lappendo(oid_list, HeapTupleGetOid(tuple)); + oid_list = lappend_oid(oid_list, HeapTupleGetOid(tuple)); MemoryContextSwitchTo(oldcontext); } @@ -3061,13 +3061,13 @@ vac_cmp_vtlinks(const void *left, const void *right) void vac_open_indexes(Relation relation, int *nindexes, Relation **Irel) { - List *indexoidlist, - *indexoidscan; + List *indexoidlist; + ListCell *indexoidscan; int i; indexoidlist = RelationGetIndexList(relation); - *nindexes = length(indexoidlist); + *nindexes = list_length(indexoidlist); if (*nindexes > 0) *Irel = (Relation *) palloc(*nindexes * sizeof(Relation)); @@ -3077,13 +3077,13 @@ vac_open_indexes(Relation relation, int *nindexes, Relation **Irel) i = 0; foreach(indexoidscan, indexoidlist) { - Oid indexoid = lfirsto(indexoidscan); + Oid indexoid = lfirst_oid(indexoidscan); (*Irel)[i] = index_open(indexoid); i++; } - freeList(indexoidlist); + list_free(indexoidlist); } diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c index 58cf97408f3..4a58419079a 100644 --- a/src/backend/commands/variable.c +++ b/src/backend/commands/variable.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.96 2004/05/23 23:12:11 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.97 2004/05/26 04:41:13 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -48,7 +48,7 @@ assign_datestyle(const char *value, bool doit, GucSource source) char *rawstring; char *result; List *elemlist; - List *l; + ListCell *l; /* Need a modifiable copy of string */ rawstring = pstrdup(value); @@ -58,7 +58,7 @@ assign_datestyle(const char *value, bool doit, GucSource source) { /* syntax error in list */ pfree(rawstring); - freeList(elemlist); + list_free(elemlist); if (source >= PGC_S_INTERACTIVE) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), @@ -159,7 +159,7 @@ assign_datestyle(const char *value, bool doit, GucSource source) ok = false; pfree(rawstring); - freeList(elemlist); + list_free(elemlist); if (!ok) { diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c index a8c3cb5ce07..4c27bd67199 100644 --- a/src/backend/commands/view.c +++ b/src/backend/commands/view.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.81 2004/01/14 23:01:54 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.82 2004/05/26 04:41:13 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -47,8 +47,8 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace) Oid viewOid, namespaceId; CreateStmt *createStmt = makeNode(CreateStmt); - List *attrList, - *t; + List *attrList; + ListCell *t; /* * create a list of ColumnDef nodes based on the names and types of @@ -217,7 +217,7 @@ FormViewRetrieveRule(const RangeVar *view, Query *viewParse, bool replace) rule->whereClause = NULL; rule->event = CMD_SELECT; rule->instead = true; - rule->actions = makeList1(viewParse); + rule->actions = list_make1(viewParse); rule->replace = replace; return rule; -- cgit v1.2.3