mirror of
https://github.com/postgres/postgres.git
synced 2025-08-21 10:42:50 +03:00
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.
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user