| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef GIST_PRIVATE_H |
| #define GIST_PRIVATE_H |
|
|
| #include "access/amapi.h" |
| #include "access/gist.h" |
| #include "access/itup.h" |
| #include "lib/pairingheap.h" |
| #include "storage/bufmgr.h" |
| #include "storage/buffile.h" |
| #include "utils/hsearch.h" |
| #include "access/genam.h" |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define GIST_MAX_SPLIT_PAGES 75 |
|
|
| |
| #define GIST_SHARE BUFFER_LOCK_SHARE |
| #define GIST_EXCLUSIVE BUFFER_LOCK_EXCLUSIVE |
| #define GIST_UNLOCK BUFFER_LOCK_UNLOCK |
|
|
| typedef struct |
| { |
| BlockNumber prev; |
| uint32 freespace; |
| char tupledata[FLEXIBLE_ARRAY_MEMBER]; |
| } GISTNodeBufferPage; |
|
|
| #define BUFFER_PAGE_DATA_OFFSET MAXALIGN(offsetof(GISTNodeBufferPage, tupledata)) |
| |
| #define PAGE_FREE_SPACE(nbp) (nbp->freespace) |
| |
| #define PAGE_IS_EMPTY(nbp) (nbp->freespace == BLCKSZ - BUFFER_PAGE_DATA_OFFSET) |
| |
| #define PAGE_NO_SPACE(nbp, itup) (PAGE_FREE_SPACE(nbp) < \ |
| MAXALIGN(IndexTupleSize(itup))) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| typedef struct GISTSTATE |
| { |
| MemoryContext scanCxt; |
| MemoryContext tempCxt; |
|
|
| TupleDesc leafTupdesc; |
| TupleDesc nonLeafTupdesc; |
| |
| TupleDesc fetchTupdesc; |
| |
|
|
| FmgrInfo consistentFn[INDEX_MAX_KEYS]; |
| FmgrInfo unionFn[INDEX_MAX_KEYS]; |
| FmgrInfo compressFn[INDEX_MAX_KEYS]; |
| FmgrInfo decompressFn[INDEX_MAX_KEYS]; |
| FmgrInfo penaltyFn[INDEX_MAX_KEYS]; |
| FmgrInfo picksplitFn[INDEX_MAX_KEYS]; |
| FmgrInfo equalFn[INDEX_MAX_KEYS]; |
| FmgrInfo distanceFn[INDEX_MAX_KEYS]; |
| FmgrInfo fetchFn[INDEX_MAX_KEYS]; |
|
|
| |
| Oid supportCollation[INDEX_MAX_KEYS]; |
| } GISTSTATE; |
|
|
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| typedef struct GISTSearchHeapItem |
| { |
| ItemPointerData heapPtr; |
| bool recheck; |
| bool recheckDistances; |
| HeapTuple recontup; |
| |
| OffsetNumber offnum; |
| |
| } GISTSearchHeapItem; |
|
|
| |
| typedef struct GISTSearchItem |
| { |
| pairingheap_node phNode; |
| BlockNumber blkno; |
| union |
| { |
| GistNSN parentlsn; |
| |
| GISTSearchHeapItem heap; |
| } data; |
|
|
| |
| IndexOrderByDistance distances[FLEXIBLE_ARRAY_MEMBER]; |
| } GISTSearchItem; |
|
|
| #define GISTSearchItemIsHeap(item) ((item).blkno == InvalidBlockNumber) |
|
|
| #define SizeOfGISTSearchItem(n_distances) \ |
| (offsetof(GISTSearchItem, distances) + \ |
| sizeof(IndexOrderByDistance) * (n_distances)) |
|
|
| |
| |
| |
| typedef struct GISTScanOpaqueData |
| { |
| GISTSTATE *giststate; |
| Oid *orderByTypes; |
|
|
| pairingheap *queue; |
| MemoryContext queueCxt; |
| bool qual_ok; |
| bool firstCall; |
|
|
| |
| IndexOrderByDistance *distances; |
|
|
| |
| OffsetNumber *killedItems; |
| int numKilled; |
| BlockNumber curBlkno; |
| GistNSN curPageLSN; |
|
|
| |
| GISTSearchHeapItem pageData[BLCKSZ / sizeof(IndexTupleData)]; |
| OffsetNumber nPageData; |
| OffsetNumber curPageData; |
| MemoryContext pageDataCxt; |
| |
| } GISTScanOpaqueData; |
|
|
| typedef GISTScanOpaqueData *GISTScanOpaque; |
|
|
| |
| typedef struct gistxlogPage |
| { |
| BlockNumber blkno; |
| int num; |
| } gistxlogPage; |
|
|
| |
| typedef struct SplitedPageLayout |
| { |
| gistxlogPage block; |
| IndexTupleData *list; |
| int lenlist; |
| IndexTuple itup; |
| Page page; |
| Buffer buffer; |
|
|
| struct SplitedPageLayout *next; |
| } SplitedPageLayout; |
|
|
| |
| |
| |
| |
| typedef struct GISTInsertStack |
| { |
| |
| BlockNumber blkno; |
| Buffer buffer; |
| Page page; |
|
|
| |
| |
| |
| |
| GistNSN lsn; |
|
|
| |
| |
| |
| |
| |
| bool retry_from_parent; |
|
|
| |
| OffsetNumber downlinkoffnum; |
|
|
| |
| struct GISTInsertStack *parent; |
| } GISTInsertStack; |
|
|
| |
| typedef struct GistSplitVector |
| { |
| GIST_SPLITVEC splitVector; |
|
|
| Datum spl_lattr[INDEX_MAX_KEYS]; |
| |
| bool spl_lisnull[INDEX_MAX_KEYS]; |
|
|
| Datum spl_rattr[INDEX_MAX_KEYS]; |
| |
| bool spl_risnull[INDEX_MAX_KEYS]; |
|
|
| bool *spl_dontcare; |
| |
| } GistSplitVector; |
|
|
| typedef struct |
| { |
| Relation r; |
| Relation heapRel; |
| Size freespace; |
| bool is_build; |
|
|
| GISTInsertStack *stack; |
| } GISTInsertState; |
|
|
| |
| #define GIST_ROOT_BLKNO 0 |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define TUPLE_IS_VALID 0xffff |
| #define TUPLE_IS_INVALID 0xfffe |
|
|
| #define GistTupleIsInvalid(itup) ( ItemPointerGetOffsetNumber( &((itup)->t_tid) ) == TUPLE_IS_INVALID ) |
| #define GistTupleSetValid(itup) ItemPointerSetOffsetNumber( &((itup)->t_tid), TUPLE_IS_VALID ) |
|
|
|
|
|
|
|
|
| |
| |
| |
| |
| typedef struct |
| { |
| BlockNumber nodeBlocknum; |
| int32 blocksCount; |
|
|
| BlockNumber pageBlocknum; |
| GISTNodeBufferPage *pageBuffer; |
|
|
| |
| bool queuedForEmptying; |
|
|
| |
| bool isTemp; |
|
|
| int level; |
| } GISTNodeBuffer; |
|
|
| |
| |
| |
| |
| #define LEVEL_HAS_BUFFERS(nlevel, gfbb) \ |
| ((nlevel) != 0 && (nlevel) % (gfbb)->levelStep == 0 && \ |
| (nlevel) != (gfbb)->rootlevel) |
|
|
| |
| #define BUFFER_HALF_FILLED(nodeBuffer, gfbb) \ |
| ((nodeBuffer)->blocksCount > (gfbb)->pagesPerBuffer / 2) |
|
|
| |
| |
| |
| |
| |
| #define BUFFER_OVERFLOWED(nodeBuffer, gfbb) \ |
| ((nodeBuffer)->blocksCount > (gfbb)->pagesPerBuffer) |
|
|
| |
| |
| |
| typedef struct GISTBuildBuffers |
| { |
| |
| MemoryContext context; |
|
|
| BufFile *pfile; |
| long nFileBlocks; |
|
|
| |
| |
| |
| long *freeBlocks; |
| int nFreeBlocks; |
| int freeBlocksLen; |
|
|
| |
| HTAB *nodeBuffersTab; |
|
|
| |
| List *bufferEmptyingQueue; |
|
|
| |
| |
| |
| |
| |
| int levelStep; |
| int pagesPerBuffer; |
|
|
| |
| List **buffersOnLevels; |
| int buffersOnLevelsLen; |
|
|
| |
| |
| |
| |
| GISTNodeBuffer **loadedBuffers; |
| int loadedBuffersCount; |
| int loadedBuffersLen; |
|
|
| |
| int rootlevel; |
| } GISTBuildBuffers; |
|
|
| |
| typedef enum GistOptBufferingMode |
| { |
| GIST_OPTION_BUFFERING_AUTO, |
| GIST_OPTION_BUFFERING_ON, |
| GIST_OPTION_BUFFERING_OFF |
| } GistOptBufferingMode; |
|
|
| |
| |
| |
| typedef struct GiSTOptions |
| { |
| int32 vl_len_; |
| int fillfactor; |
| GistOptBufferingMode buffering_mode; |
| } GiSTOptions; |
|
|
| |
| extern void gistbuildempty(Relation index); |
| extern bool gistinsert(Relation r, Datum *values, bool *isnull, |
| ItemPointer ht_ctid, Relation heapRel, |
| IndexUniqueCheck checkUnique, |
| bool indexUnchanged, |
| struct IndexInfo *indexInfo); |
| extern MemoryContext createTempGistContext(void); |
| extern GISTSTATE *initGISTstate(Relation index); |
| extern void freeGISTstate(GISTSTATE *giststate); |
| extern void gistdoinsert(Relation r, |
| IndexTuple itup, |
| Size freespace, |
| GISTSTATE *giststate, |
| Relation heapRel, |
| bool is_build); |
|
|
| |
| typedef struct |
| { |
| Buffer buf; |
| IndexTuple downlink; |
| } GISTPageSplitInfo; |
|
|
| extern bool gistplacetopage(Relation rel, Size freespace, GISTSTATE *giststate, |
| Buffer buffer, |
| IndexTuple *itup, int ntup, |
| OffsetNumber oldoffnum, BlockNumber *newblkno, |
| Buffer leftchildbuf, |
| List **splitinfo, |
| bool markfollowright, |
| Relation heapRel, |
| bool is_build); |
|
|
| extern SplitedPageLayout *gistSplit(Relation r, Page page, IndexTuple *itup, |
| int len, GISTSTATE *giststate); |
|
|
| |
| extern XLogRecPtr gistXLogPageDelete(Buffer buffer, |
| FullTransactionId xid, Buffer parentBuffer, |
| OffsetNumber downlinkOffset); |
|
|
| extern void gistXLogPageReuse(Relation rel, Relation heaprel, BlockNumber blkno, |
| FullTransactionId deleteXid); |
|
|
| extern XLogRecPtr gistXLogUpdate(Buffer buffer, |
| OffsetNumber *todelete, int ntodelete, |
| IndexTuple *itup, int ituplen, |
| Buffer leftchildbuf); |
|
|
| extern XLogRecPtr gistXLogDelete(Buffer buffer, OffsetNumber *todelete, |
| int ntodelete, TransactionId snapshotConflictHorizon, |
| Relation heaprel); |
|
|
| extern XLogRecPtr gistXLogSplit(bool page_is_leaf, |
| SplitedPageLayout *dist, |
| BlockNumber origrlink, GistNSN orignsn, |
| Buffer leftchildbuf, bool markfollowright); |
|
|
| extern XLogRecPtr gistXLogAssignLSN(void); |
|
|
| |
| extern bool gistgettuple(IndexScanDesc scan, ScanDirection dir); |
| extern int64 gistgetbitmap(IndexScanDesc scan, TIDBitmap *tbm); |
| extern bool gistcanreturn(Relation index, int attno); |
|
|
| |
| extern bool gistvalidate(Oid opclassoid); |
| extern void gistadjustmembers(Oid opfamilyoid, |
| Oid opclassoid, |
| List *operators, |
| List *functions); |
|
|
| |
|
|
| #define GiSTPageSize \ |
| ( BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(GISTPageOpaqueData)) ) |
|
|
| #define GIST_MIN_FILLFACTOR 10 |
| #define GIST_DEFAULT_FILLFACTOR 90 |
|
|
| extern bytea *gistoptions(Datum reloptions, bool validate); |
| extern bool gistproperty(Oid index_oid, int attno, |
| IndexAMProperty prop, const char *propname, |
| bool *res, bool *isnull); |
| extern bool gistfitpage(IndexTuple *itvec, int len); |
| extern bool gistnospace(Page page, IndexTuple *itvec, int len, OffsetNumber todelete, Size freespace); |
| extern void gistcheckpage(Relation rel, Buffer buf); |
| extern Buffer gistNewBuffer(Relation r, Relation heaprel); |
| extern bool gistPageRecyclable(Page page); |
| extern void gistfillbuffer(Page page, IndexTuple *itup, int len, |
| OffsetNumber off); |
| extern IndexTuple *gistextractpage(Page page, int *len ); |
| extern IndexTuple *gistjoinvector(IndexTuple *itvec, int *len, |
| IndexTuple *additvec, int addlen); |
| extern IndexTupleData *gistfillitupvec(IndexTuple *vec, int veclen, int *memlen); |
|
|
| extern IndexTuple gistunion(Relation r, IndexTuple *itvec, |
| int len, GISTSTATE *giststate); |
| extern IndexTuple gistgetadjusted(Relation r, |
| IndexTuple oldtup, |
| IndexTuple addtup, |
| GISTSTATE *giststate); |
| extern IndexTuple gistFormTuple(GISTSTATE *giststate, |
| Relation r, Datum *attdata, bool *isnull, bool isleaf); |
| extern void gistCompressValues(GISTSTATE *giststate, Relation r, |
| Datum *attdata, bool *isnull, bool isleaf, Datum *compatt); |
|
|
| extern OffsetNumber gistchoose(Relation r, Page p, |
| IndexTuple it, |
| GISTSTATE *giststate); |
|
|
| extern void GISTInitBuffer(Buffer b, uint32 f); |
| extern void gistinitpage(Page page, uint32 f); |
| extern void gistdentryinit(GISTSTATE *giststate, int nkey, GISTENTRY *e, |
| Datum k, Relation r, Page pg, OffsetNumber o, |
| bool l, bool isNull); |
|
|
| extern float gistpenalty(GISTSTATE *giststate, int attno, |
| GISTENTRY *orig, bool isNullOrig, |
| GISTENTRY *add, bool isNullAdd); |
| extern void gistMakeUnionItVec(GISTSTATE *giststate, IndexTuple *itvec, int len, |
| Datum *attr, bool *isnull); |
| extern bool gistKeyIsEQ(GISTSTATE *giststate, int attno, Datum a, Datum b); |
| extern void gistDeCompressAtt(GISTSTATE *giststate, Relation r, IndexTuple tuple, Page p, |
| OffsetNumber o, GISTENTRY *attdata, bool *isnull); |
| extern HeapTuple gistFetchTuple(GISTSTATE *giststate, Relation r, |
| IndexTuple tuple); |
| extern void gistMakeUnionKey(GISTSTATE *giststate, int attno, |
| GISTENTRY *entry1, bool isnull1, |
| GISTENTRY *entry2, bool isnull2, |
| Datum *dst, bool *dstisnull); |
|
|
| extern XLogRecPtr gistGetFakeLSN(Relation rel); |
|
|
| |
| extern IndexBulkDeleteResult *gistbulkdelete(IndexVacuumInfo *info, |
| IndexBulkDeleteResult *stats, |
| IndexBulkDeleteCallback callback, |
| void *callback_state); |
| extern IndexBulkDeleteResult *gistvacuumcleanup(IndexVacuumInfo *info, |
| IndexBulkDeleteResult *stats); |
|
|
| |
| extern void gistSplitByKey(Relation r, Page page, IndexTuple *itup, |
| int len, GISTSTATE *giststate, |
| GistSplitVector *v, |
| int attno); |
|
|
| |
| extern IndexBuildResult *gistbuild(Relation heap, Relation index, |
| struct IndexInfo *indexInfo); |
|
|
| |
| extern GISTBuildBuffers *gistInitBuildBuffers(int pagesPerBuffer, int levelStep, |
| int maxLevel); |
| extern GISTNodeBuffer *gistGetNodeBuffer(GISTBuildBuffers *gfbb, |
| GISTSTATE *giststate, |
| BlockNumber nodeBlocknum, int level); |
| extern void gistPushItupToNodeBuffer(GISTBuildBuffers *gfbb, |
| GISTNodeBuffer *nodeBuffer, IndexTuple itup); |
| extern bool gistPopItupFromNodeBuffer(GISTBuildBuffers *gfbb, |
| GISTNodeBuffer *nodeBuffer, IndexTuple *itup); |
| extern void gistFreeBuildBuffers(GISTBuildBuffers *gfbb); |
| extern void gistRelocateBuildBuffersOnSplit(GISTBuildBuffers *gfbb, |
| GISTSTATE *giststate, Relation r, |
| int level, Buffer buffer, |
| List *splitinfo); |
| extern void gistUnloadNodeBuffers(GISTBuildBuffers *gfbb); |
|
|
| #endif |
|
|