diff options
author | Neil Conway <neilc@samurai.com> | 2004-05-26 04:41:50 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2004-05-26 04:41:50 +0000 |
commit | d0b4399d81f39decccb23fa38f772b71b51bf96a (patch) | |
tree | 71d3b737f5d93f6c3984412a4910b5810156c5ca /src/backend/utils/adt/ri_triggers.c | |
parent | 18d0d105635fbc7e476063e662b449f296953a04 (diff) | |
download | postgresql-d0b4399d81f39decccb23fa38f772b71b51bf96a.tar.gz postgresql-d0b4399d81f39decccb23fa38f772b71b51bf96a.zip |
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.
Diffstat (limited to 'src/backend/utils/adt/ri_triggers.c')
-rw-r--r-- | src/backend/utils/adt/ri_triggers.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 47384fbb89f..9e3a06cd822 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -17,7 +17,7 @@ * * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.67 2004/02/03 17:34:03 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/ri_triggers.c,v 1.68 2004/05/26 04:41:38 neilc Exp $ * * ---------- */ @@ -2571,8 +2571,8 @@ RI_Initial_Check(FkConstraint *fkconstraint, Relation rel, Relation pkrel) char attname[MAX_QUOTED_NAME_LEN]; char fkattname[MAX_QUOTED_NAME_LEN]; const char *sep; - List *list; - List *list2; + ListCell *l; + ListCell *l2; int old_work_mem; char workmembuf[32]; int spi_result; @@ -2605,9 +2605,9 @@ RI_Initial_Check(FkConstraint *fkconstraint, Relation rel, Relation pkrel) sprintf(querystr, "SELECT "); sep=""; - foreach(list, fkconstraint->fk_attrs) + foreach(l, fkconstraint->fk_attrs) { - quoteOneName(attname, strVal(lfirst(list))); + quoteOneName(attname, strVal(lfirst(l))); snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), "%sfk.%s", sep, attname); sep = ", "; @@ -2620,12 +2620,10 @@ RI_Initial_Check(FkConstraint *fkconstraint, Relation rel, Relation pkrel) relname, pkrelname); sep=""; - for (list=fkconstraint->pk_attrs, list2=fkconstraint->fk_attrs; - list != NIL && list2 != NIL; - list=lnext(list), list2=lnext(list2)) + forboth(l, fkconstraint->pk_attrs, l2, fkconstraint->fk_attrs) { - quoteOneName(attname, strVal(lfirst(list))); - quoteOneName(fkattname, strVal(lfirst(list2))); + quoteOneName(attname, strVal(lfirst(l))); + quoteOneName(fkattname, strVal(lfirst(l2))); snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), "%spk.%s=fk.%s", sep, attname, fkattname); @@ -2635,14 +2633,14 @@ RI_Initial_Check(FkConstraint *fkconstraint, Relation rel, Relation pkrel) * It's sufficient to test any one pk attribute for null to detect a * join failure. */ - quoteOneName(attname, strVal(lfirst(fkconstraint->pk_attrs))); + quoteOneName(attname, strVal(linitial(fkconstraint->pk_attrs))); snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), ") WHERE pk.%s IS NULL AND (", attname); sep=""; - foreach(list, fkconstraint->fk_attrs) + foreach(l, fkconstraint->fk_attrs) { - quoteOneName(attname, strVal(lfirst(list))); + quoteOneName(attname, strVal(lfirst(l))); snprintf(querystr + strlen(querystr), sizeof(querystr) - strlen(querystr), "%sfk.%s IS NOT NULL", sep, attname); |