aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-12-19 14:58:41 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2011-12-19 14:58:41 -0500
commit92203624934095163f8b57b5b3d7bbd2645da2c8 (patch)
tree8570ad85adefe211f46f295b86aaf05d461f3e8a /src/include
parent3695a555136a6d179cac8ae48d5f90171d5b30e9 (diff)
downloadpostgresql-92203624934095163f8b57b5b3d7bbd2645da2c8.tar.gz
postgresql-92203624934095163f8b57b5b3d7bbd2645da2c8.zip
Teach SP-GiST to do index-only scans.
Operator classes can specify whether or not they support this; this preserves the flexibility to use lossy representations within an index. In passing, move constant data about a given index into the rd_amcache cache area, instead of doing fresh lookups each time we start an index operation. This is mainly to try to make sure that spgcanreturn() has insignificant cost; I still don't have any proof that it matters for actual index accesses. Also, get rid of useless copying of FmgrInfo pointers; we can perfectly well use the relcache's versions in-place.
Diffstat (limited to 'src/include')
-rw-r--r--src/include/access/spgist.h4
-rw-r--r--src/include/access/spgist_private.h31
2 files changed, 26 insertions, 9 deletions
diff --git a/src/include/access/spgist.h b/src/include/access/spgist.h
index df6fec6cf45..d2f0a72c36b 100644
--- a/src/include/access/spgist.h
+++ b/src/include/access/spgist.h
@@ -43,6 +43,7 @@ typedef struct spgConfigOut
{
Oid prefixType; /* Data type of inner-tuple prefixes */
Oid labelType; /* Data type of inner-tuple node labels */
+ bool canReturnData; /* Opclass can reconstruct original data */
bool longValuesOK; /* Opclass can cope with values > 1 page */
} spgConfigOut;
@@ -132,6 +133,7 @@ typedef struct spgInnerConsistentIn
Datum reconstructedValue; /* value reconstructed at parent */
int level; /* current level (counting from zero) */
+ bool returnData; /* original data must be returned? */
/* Data from current inner tuple */
bool allTheSame; /* tuple is marked all-the-same? */
@@ -159,12 +161,14 @@ typedef struct spgLeafConsistentIn
Datum reconstructedValue; /* value reconstructed at parent */
int level; /* current level (counting from zero) */
+ bool returnData; /* original data must be returned? */
Datum leafDatum; /* datum in leaf tuple */
} spgLeafConsistentIn;
typedef struct spgLeafConsistentOut
{
+ Datum leafValue; /* reconstructed original data, if any */
bool recheck; /* set true if operator must be rechecked */
} spgLeafConsistentOut;
diff --git a/src/include/access/spgist_private.h b/src/include/access/spgist_private.h
index 5c57799f09c..ec6d2d07fc7 100644
--- a/src/include/access/spgist_private.h
+++ b/src/include/access/spgist_private.h
@@ -71,11 +71,11 @@ typedef struct SpGistLastUsedPage
int freeSpace; /* its free space (could be obsolete!) */
} SpGistLastUsedPage;
-typedef struct SpGistCache
+typedef struct SpGistLUPCache
{
SpGistLastUsedPage innerPage[3]; /* one per triple-parity group */
SpGistLastUsedPage leafPage;
-} SpGistCache;
+} SpGistLUPCache;
/*
* metapage
@@ -83,7 +83,7 @@ typedef struct SpGistCache
typedef struct SpGistMetaPageData
{
uint32 magicNumber; /* for identity cross-check */
- SpGistCache lastUsedPages; /* shared storage of last-used info */
+ SpGistLUPCache lastUsedPages; /* shared storage of last-used info */
} SpGistMetaPageData;
#define SPGIST_MAGIC_NUMBER (0xBA0BABED)
@@ -112,12 +112,6 @@ typedef struct SpGistState
SpGistTypeDesc attPrefixType; /* type of inner-tuple prefix values */
SpGistTypeDesc attLabelType; /* type of node label values */
- /* lookup data for the opclass support functions, except config */
- FmgrInfo chooseFn;
- FmgrInfo picksplitFn;
- FmgrInfo innerConsistentFn;
- FmgrInfo leafConsistentFn;
-
char *deadTupleStorage; /* workspace for spgFormDeadTuple */
TransactionId myXid; /* XID to use when creating a redirect tuple */
@@ -144,10 +138,13 @@ typedef struct SpGistScanOpaqueData
int64 ntids; /* number of TIDs passed to bitmap */
/* These fields are only used in amgettuple scans: */
+ bool want_itup; /* are we reconstructing tuples? */
+ TupleDesc indexTupDesc; /* if so, tuple descriptor for them */
int nPtrs; /* number of TIDs found on current page */
int iPtr; /* index for scanning through same */
ItemPointerData heapPtrs[MaxIndexTuplesPerPage]; /* TIDs from cur page */
bool recheck[MaxIndexTuplesPerPage]; /* their recheck flags */
+ IndexTuple indexTups[MaxIndexTuplesPerPage]; /* reconstructed tuples */
/*
* Note: using MaxIndexTuplesPerPage above is a bit hokey since
@@ -158,6 +155,21 @@ typedef struct SpGistScanOpaqueData
typedef SpGistScanOpaqueData *SpGistScanOpaque;
+/*
+ * This struct is what we actually keep in index->rd_amcache. It includes
+ * static configuration information as well as the lastUsedPages cache.
+ */
+typedef struct SpGistCache
+{
+ spgConfigOut config; /* filled in by opclass config method */
+
+ SpGistTypeDesc attType; /* type of input data and leaf values */
+ SpGistTypeDesc attPrefixType; /* type of inner-tuple prefix values */
+ SpGistTypeDesc attLabelType; /* type of node label values */
+
+ SpGistLUPCache lastUsedPages; /* local storage of last-used info */
+} SpGistCache;
+
/*
* SPGiST tuple types. Note: inner, leaf, and dead tuple structs
@@ -570,6 +582,7 @@ typedef struct spgxlogVacuumRedirect
#define GBUF_INNER_PARITY(x) ((x) % 3)
/* spgutils.c */
+extern SpGistCache *spgGetCache(Relation index);
extern void initSpGistState(SpGistState *state, Relation index);
extern Buffer SpGistNewBuffer(Relation index);
extern void SpGistUpdateMetaPage(Relation index);