1
0
mirror of https://github.com/postgres/postgres.git synced 2025-08-27 07:42:10 +03:00

Embedded list interface

Provide a common implementation of embedded singly-linked and
doubly-linked lists.  "Embedded" in the sense that the nodes'
next/previous pointers exist within some larger struct; this design
choice reduces memory allocation overhead.

Most of the implementation uses inlineable functions (where supported),
for performance.

Some existing uses of both types of lists have been converted to the new
code, for demonstration purposes.  Other uses can (and probably will) be
converted in the future.  Since dllist.c is unused after this conversion,
it has been removed.

Author: Andres Freund
Some tweaks by me
Reviewed by Tom Lane, Peter Geoghegan
This commit is contained in:
Alvaro Herrera
2012-10-16 17:36:30 -03:00
parent f862a326ef
commit a66ee69add
9 changed files with 1080 additions and 531 deletions

View File

@@ -22,7 +22,7 @@
#include "access/htup.h"
#include "access/skey.h"
#include "lib/dllist.h"
#include "lib/ilist.h"
#include "utils/relcache.h"
/*
@@ -37,7 +37,7 @@
typedef struct catcache
{
int id; /* cache identifier --- see syscache.h */
struct catcache *cc_next; /* link to next catcache */
slist_node cc_next; /* list link */
const char *cc_relname; /* name of relation the tuples come from */
Oid cc_reloid; /* OID of relation the tuples come from */
Oid cc_indexoid; /* OID of index matching cache keys */
@@ -51,7 +51,7 @@ typedef struct catcache
ScanKeyData cc_skey[CATCACHE_MAXKEYS]; /* precomputed key info for
* heap scans */
bool cc_isname[CATCACHE_MAXKEYS]; /* flag "name" key columns */
Dllist cc_lists; /* list of CatCList structs */
dlist_head cc_lists; /* list of CatCList structs */
#ifdef CATCACHE_STATS
long cc_searches; /* total # searches against this cache */
long cc_hits; /* # of matches against existing entry */
@@ -66,7 +66,7 @@ typedef struct catcache
long cc_lsearches; /* total # list-searches */
long cc_lhits; /* # of matches against existing lists */
#endif
Dllist cc_bucket[1]; /* hash buckets --- VARIABLE LENGTH ARRAY */
dlist_head cc_bucket[1]; /* hash buckets --- VARIABLE LENGTH ARRAY */
} CatCache; /* VARIABLE LENGTH STRUCT */
@@ -77,11 +77,12 @@ typedef struct catctup
CatCache *my_cache; /* link to owning catcache */
/*
* Each tuple in a cache is a member of a Dllist that stores the elements
* of its hash bucket. We keep each Dllist in LRU order to speed repeated
* Each tuple in a cache is a member of a dlist that stores the elements
* of its hash bucket. We keep each dlist in LRU order to speed repeated
* lookups.
*/
Dlelem cache_elem; /* list member of per-bucket list */
dlist_node cache_elem; /* list member of per-bucket list */
dlist_head *cache_bucket; /* containing bucket dlist */
/*
* The tuple may also be a member of at most one CatCList. (If a single
@@ -139,7 +140,7 @@ typedef struct catclist
* might not be true during bootstrap or recovery operations. (namespace.c
* is able to save some cycles when it is true.)
*/
Dlelem cache_elem; /* list member of per-catcache list */
dlist_node cache_elem; /* list member of per-catcache list */
int refcount; /* number of active references */
bool dead; /* dead but not yet removed? */
bool ordered; /* members listed in index order? */
@@ -153,7 +154,7 @@ typedef struct catclist
typedef struct catcacheheader
{
CatCache *ch_caches; /* head of list of CatCache structs */
slist_head ch_caches; /* head of list of CatCache structs */
int ch_ntup; /* # of tuples in all caches */
} CatCacheHeader;