diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2011-09-30 19:48:57 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2011-09-30 19:48:57 -0400 |
commit | d22a09dc70f9830fa78c1cd1a3a453e4e473d354 (patch) | |
tree | 0867ec67a9643663d27f90ef8df2d58cb6cd9c3a /src/include/access/gist_private.h | |
parent | 79edb2b1dc33166b576f51a8255a7614f748d9c9 (diff) |
Support GiST index support functions that want to cache data across calls.
pg_trgm was already doing this unofficially, but the implementation hadn't
been thought through very well and leaked memory. Restructure the core
GiST code so that it actually works, and document it. Ordinarily this
would have required an extra memory context creation/destruction for each
GiST index search, but I was able to avoid that in the normal case of a
non-rescanned search by finessing the handling of the RBTree. It used to
have its own context always, but now shares a context with the
scan-lifespan data structures, unless there is more than one rescan call.
This should make the added overhead unnoticeable in typical cases.
Diffstat (limited to 'src/include/access/gist_private.h')
-rw-r--r-- | src/include/access/gist_private.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/include/access/gist_private.h b/src/include/access/gist_private.h index 8b3cb01ae41..e98838227f9 100644 --- a/src/include/access/gist_private.h +++ b/src/include/access/gist_private.h @@ -48,9 +48,21 @@ typedef struct * * This struct retains call info for the index's opclass-specific support * functions (per index column), plus the index's tuple descriptor. + * + * scanCxt holds the GISTSTATE itself as well as any data that lives for the + * lifetime of the index operation. We pass this to the support functions + * via fn_mcxt, so that they can store scan-lifespan data in it. The + * functions are invoked in tempCxt, which is typically short-lifespan + * (that is, it's reset after each tuple). However, tempCxt can be the same + * as scanCxt if we're not bothering with per-tuple context resets. */ typedef struct GISTSTATE { + MemoryContext scanCxt; /* context for scan-lifespan data */ + MemoryContext tempCxt; /* short-term context for calling functions */ + + TupleDesc tupdesc; /* index's tuple descriptor */ + FmgrInfo consistentFn[INDEX_MAX_KEYS]; FmgrInfo unionFn[INDEX_MAX_KEYS]; FmgrInfo compressFn[INDEX_MAX_KEYS]; @@ -62,8 +74,6 @@ typedef struct GISTSTATE /* Collations to pass to the support functions */ Oid supportCollation[INDEX_MAX_KEYS]; - - TupleDesc tupdesc; } GISTSTATE; @@ -132,7 +142,6 @@ typedef struct GISTScanOpaqueData GISTSTATE *giststate; /* index information, see above */ RBTree *queue; /* queue of unvisited items */ MemoryContext queueCxt; /* context holding the queue */ - MemoryContext tempCxt; /* workspace context for calling functions */ bool qual_ok; /* false if qual can never be satisfied */ bool firstCall; /* true until first gistgettuple call */ @@ -422,7 +431,7 @@ typedef struct GiSTOptions extern Datum gistbuildempty(PG_FUNCTION_ARGS); extern Datum gistinsert(PG_FUNCTION_ARGS); extern MemoryContext createTempGistContext(void); -extern void initGISTstate(GISTSTATE *giststate, Relation index); +extern GISTSTATE *initGISTstate(Relation index); extern void freeGISTstate(GISTSTATE *giststate); extern void gistdoinsert(Relation r, IndexTuple itup, |