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/optimizer/path/joinpath.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/backend/optimizer/path/joinpath.c') diff --git a/src/backend/optimizer/path/joinpath.c b/src/backend/optimizer/path/joinpath.c index ac6838d26e0..e854fe03b77 100644 --- a/src/backend/optimizer/path/joinpath.c +++ b/src/backend/optimizer/path/joinpath.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.86 2004/04/06 18:46:03 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/optimizer/path/joinpath.c,v 1.87 2004/05/26 04:41:22 neilc Exp $ * *------------------------------------------------------------------------- */ @@ -145,7 +145,7 @@ sort_inner_and_outer(Query *root, Path *outer_path; Path *inner_path; List *all_pathkeys; - List *i; + ListCell *l; /* * If we are doing a right or full join, we must use *all* the @@ -224,9 +224,9 @@ sort_inner_and_outer(Query *root, mergeclause_list, outerrel); - foreach(i, all_pathkeys) + foreach(l, all_pathkeys) { - List *front_pathkey = lfirst(i); + List *front_pathkey = (List *) lfirst(l); List *cur_pathkeys; List *cur_mergeclauses; List *outerkeys; @@ -234,7 +234,7 @@ sort_inner_and_outer(Query *root, List *merge_pathkeys; /* Make a pathkey list with this guy first. */ - if (i != all_pathkeys) + if (l != list_head(all_pathkeys)) cur_pathkeys = lcons(front_pathkey, lremove(front_pathkey, listCopy(all_pathkeys))); @@ -338,7 +338,7 @@ match_unsorted_outer(Query *root, Path *inner_cheapest_total = innerrel->cheapest_total_path; Path *matpath = NULL; Path *bestinnerjoin = NULL; - List *i; + ListCell *l; /* * Nestloop only supports inner, left, and IN joins. Also, if we are @@ -402,9 +402,9 @@ match_unsorted_outer(Query *root, outerrel->relids, jointype); } - foreach(i, outerrel->pathlist) + foreach(l, outerrel->pathlist) { - Path *outerpath = (Path *) lfirst(i); + Path *outerpath = (Path *) lfirst(l); List *merge_pathkeys; List *mergeclauses; List *innersortkeys; @@ -676,7 +676,7 @@ hash_inner_and_outer(Query *root, { bool isouterjoin; List *hashclauses; - List *i; + ListCell *l; /* * Hashjoin only supports inner, left, and IN joins. @@ -704,9 +704,9 @@ hash_inner_and_outer(Query *root, * are usable with this pair of sub-relations. */ hashclauses = NIL; - foreach(i, restrictlist) + foreach(l, restrictlist) { - RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(i); + RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(l); if (!restrictinfo->can_join || restrictinfo->hashjoinoperator == InvalidOid) @@ -803,11 +803,11 @@ select_mergejoin_clauses(RelOptInfo *joinrel, { List *result_list = NIL; bool isouterjoin = IS_OUTER_JOIN(jointype); - List *i; + ListCell *l; - foreach(i, restrictlist) + foreach(l, restrictlist) { - RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(i); + RestrictInfo *restrictinfo = (RestrictInfo *) lfirst(l); /* * If processing an outer join, only use its own join clauses in -- cgit v1.2.3