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/executor/nodeMergejoin.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/executor/nodeMergejoin.c')
-rw-r--r-- | src/backend/executor/nodeMergejoin.c | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/backend/executor/nodeMergejoin.c b/src/backend/executor/nodeMergejoin.c index 9c44102611a..e9ca17317e3 100644 --- a/src/backend/executor/nodeMergejoin.c +++ b/src/backend/executor/nodeMergejoin.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.64 2004/03/17 01:02:23 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.65 2004/05/26 04:41:16 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -104,10 +104,10 @@ static void MJFormSkipQuals(List *qualList, List **ltQuals, List **gtQuals, PlanState *parent) { - List *ltexprs, - *gtexprs, - *ltcdr, - *gtcdr; + List *ltexprs, + *gtexprs; + ListCell *ltcdr, + *gtcdr; /* * Make modifiable copies of the qualList. @@ -119,8 +119,7 @@ MJFormSkipQuals(List *qualList, List **ltQuals, List **gtQuals, * Scan both lists in parallel, so that we can update the operators * with the minimum number of syscache searches. */ - ltcdr = ltexprs; - foreach(gtcdr, gtexprs) + forboth(ltcdr, ltexprs, gtcdr, gtexprs) { OpExpr *ltop = (OpExpr *) lfirst(ltcdr); OpExpr *gtop = (OpExpr *) lfirst(gtcdr); @@ -140,8 +139,6 @@ MJFormSkipQuals(List *qualList, List **ltQuals, List **gtQuals, >op->opno, <op->opfuncid, >op->opfuncid); - - ltcdr = lnext(ltcdr); } /* @@ -173,8 +170,8 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) { bool result; MemoryContext oldContext; - List *clause; - List *eqclause; + ListCell *clause; + ListCell *eqclause; /* * Do expression eval in short-lived context. @@ -188,8 +185,12 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) */ result = false; /* assume 'false' result */ - eqclause = eqQual; - foreach(clause, compareQual) + /* + * We can't run out of one list before the other + */ + Assert(length(compareQual) == length(eqQual)); + + forboth(clause, compareQual, eqclause, eqQual) { ExprState *clauseexpr = (ExprState *) lfirst(clause); ExprState *eqclauseexpr = (ExprState *) lfirst(eqclause); @@ -220,8 +221,6 @@ MergeCompare(List *eqQual, List *compareQual, ExprContext *econtext) if (!DatumGetBool(const_value) || isNull) break; /* return false */ - - eqclause = lnext(eqclause); } MemoryContextSwitchTo(oldContext); |