2006-05-02 13:28:56 +02:00
|
|
|
/*--------------------------------------------------------------------------
|
|
|
|
* gin.h
|
2006-10-04 02:30:14 +02:00
|
|
|
* header file for postgres inverted index access method implementation.
|
2006-05-02 13:28:56 +02:00
|
|
|
*
|
2009-01-01 18:24:05 +01:00
|
|
|
* Copyright (c) 2006-2009, PostgreSQL Global Development Group
|
2007-08-21 03:11:32 +02:00
|
|
|
*
|
2009-03-25 23:19:02 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/gin.h,v 1.31 2009/03/25 22:19:01 tgl Exp $
|
2006-05-02 13:28:56 +02:00
|
|
|
*--------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#ifndef GIN_H
|
|
|
|
#define GIN_H
|
|
|
|
|
2008-06-19 02:46:06 +02:00
|
|
|
#include "access/genam.h"
|
2006-05-02 13:28:56 +02:00
|
|
|
#include "access/itup.h"
|
2008-06-07 00:35:22 +02:00
|
|
|
#include "access/xlog.h"
|
2006-05-02 13:28:56 +02:00
|
|
|
#include "fmgr.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* amproc indexes for inverted indexes.
|
|
|
|
*/
|
2006-10-04 02:30:14 +02:00
|
|
|
#define GIN_COMPARE_PROC 1
|
|
|
|
#define GIN_EXTRACTVALUE_PROC 2
|
|
|
|
#define GIN_EXTRACTQUERY_PROC 3
|
|
|
|
#define GIN_CONSISTENT_PROC 4
|
2008-05-16 18:31:02 +02:00
|
|
|
#define GIN_COMPARE_PARTIAL_PROC 5
|
|
|
|
#define GINNProcs 5
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2009-03-24 23:06:03 +01:00
|
|
|
/*
|
|
|
|
* Max depth allowed in search tree during bulk inserts. This is to keep from
|
|
|
|
* degenerating to O(N^2) behavior when the tree is unbalanced due to sorted
|
|
|
|
* or nearly-sorted input. (Perhaps it would be better to use a balanced-tree
|
|
|
|
* algorithm, but in common cases that would only add useless overhead.)
|
|
|
|
*/
|
|
|
|
#define GIN_MAX_TREE_DEPTH 100
|
|
|
|
|
2006-05-02 13:28:56 +02:00
|
|
|
/*
|
|
|
|
* Page opaque data in a inverted index page.
|
2007-04-10 00:04:08 +02:00
|
|
|
*
|
|
|
|
* Note: GIN does not include a page ID word as do the other index types.
|
|
|
|
* This is OK because the opaque data is only 8 bytes and so can be reliably
|
|
|
|
* distinguished by size. Revisit this if the size ever increases.
|
2006-05-02 13:28:56 +02:00
|
|
|
*/
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct GinPageOpaqueData
|
|
|
|
{
|
2007-04-10 00:04:08 +02:00
|
|
|
BlockNumber rightlink; /* next page if any */
|
2009-03-24 21:17:18 +01:00
|
|
|
OffsetNumber maxoff; /* number entries on GIN_DATA page; number of
|
2006-10-04 02:30:14 +02:00
|
|
|
* heap ItemPointer on GIN_DATA|GIN_LEAF page
|
|
|
|
* and number of records on GIN_DATA &
|
2009-03-24 21:17:18 +01:00
|
|
|
* ~GIN_LEAF page. On GIN_LIST page, number of
|
|
|
|
* heap tuples. */
|
2007-04-10 00:04:08 +02:00
|
|
|
uint16 flags; /* see bit definitions below */
|
2006-05-02 13:28:56 +02:00
|
|
|
} GinPageOpaqueData;
|
|
|
|
|
|
|
|
typedef GinPageOpaqueData *GinPageOpaque;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
#define GIN_DATA (1 << 0)
|
|
|
|
#define GIN_LEAF (1 << 1)
|
|
|
|
#define GIN_DELETED (1 << 2)
|
2009-03-24 21:17:18 +01:00
|
|
|
#define GIN_META (1 << 3)
|
|
|
|
#define GIN_LIST (1 << 4)
|
|
|
|
#define GIN_LIST_FULLROW (1 << 5) /* makes sense only on GIN_LIST page */
|
|
|
|
|
|
|
|
/* Page numbers of fixed-location pages */
|
|
|
|
#define GIN_METAPAGE_BLKNO (0)
|
|
|
|
#define GIN_ROOT_BLKNO (1)
|
|
|
|
|
|
|
|
typedef struct GinMetaPageData
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Pointers to head and tail of pending list, which consists of GIN_LIST
|
|
|
|
* pages. These store fast-inserted entries that haven't yet been moved
|
|
|
|
* into the regular GIN structure.
|
|
|
|
*/
|
|
|
|
BlockNumber head;
|
|
|
|
BlockNumber tail;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Free space in bytes in the pending list's tail page.
|
|
|
|
*/
|
|
|
|
uint32 tailFreeSize;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We store both number of pages and number of heap tuples
|
|
|
|
* that are in the pending list.
|
|
|
|
*/
|
|
|
|
BlockNumber nPendingPages;
|
|
|
|
int64 nPendingHeapTuples;
|
|
|
|
} GinMetaPageData;
|
|
|
|
|
|
|
|
#define GinPageGetMeta(p) \
|
|
|
|
((GinMetaPageData *) PageGetContents(p))
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/*
|
2006-10-04 02:30:14 +02:00
|
|
|
* Works on page
|
2006-05-02 13:28:56 +02:00
|
|
|
*/
|
|
|
|
#define GinPageGetOpaque(page) ( (GinPageOpaque) PageGetSpecialPointer(page) )
|
|
|
|
|
|
|
|
#define GinPageIsLeaf(page) ( GinPageGetOpaque(page)->flags & GIN_LEAF )
|
|
|
|
#define GinPageSetLeaf(page) ( GinPageGetOpaque(page)->flags |= GIN_LEAF )
|
|
|
|
#define GinPageSetNonLeaf(page) ( GinPageGetOpaque(page)->flags &= ~GIN_LEAF )
|
|
|
|
#define GinPageIsData(page) ( GinPageGetOpaque(page)->flags & GIN_DATA )
|
|
|
|
#define GinPageSetData(page) ( GinPageGetOpaque(page)->flags |= GIN_DATA )
|
2009-03-24 21:17:18 +01:00
|
|
|
#define GinPageHasFullRow(page) ( GinPageGetOpaque(page)->flags & GIN_LIST_FULLROW )
|
|
|
|
#define GinPageSetFullRow(page) ( GinPageGetOpaque(page)->flags |= GIN_LIST_FULLROW )
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
#define GinPageIsDeleted(page) ( GinPageGetOpaque(page)->flags & GIN_DELETED)
|
|
|
|
#define GinPageSetDeleted(page) ( GinPageGetOpaque(page)->flags |= GIN_DELETED)
|
|
|
|
#define GinPageSetNonDeleted(page) ( GinPageGetOpaque(page)->flags &= ~GIN_DELETED)
|
|
|
|
|
|
|
|
#define GinPageRightMost(page) ( GinPageGetOpaque(page)->rightlink == InvalidBlockNumber)
|
|
|
|
|
|
|
|
/*
|
2009-03-24 21:17:18 +01:00
|
|
|
* We use our own ItemPointerGet(BlockNumber|GetOffsetNumber)
|
|
|
|
* to avoid Asserts, since sometimes the ip_posid isn't "valid"
|
2006-05-02 13:28:56 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define GinItemPointerGetBlockNumber(pointer) \
|
|
|
|
BlockIdGetBlockNumber(&(pointer)->ip_blkid)
|
|
|
|
|
|
|
|
#define GinItemPointerGetOffsetNumber(pointer) \
|
|
|
|
((pointer)->ip_posid)
|
|
|
|
|
2009-03-24 21:17:18 +01:00
|
|
|
#define ItemPointerSetMin(p) \
|
|
|
|
ItemPointerSet((p), (BlockNumber)0, (OffsetNumber)0)
|
|
|
|
#define ItemPointerIsMin(p) \
|
|
|
|
(ItemPointerGetOffsetNumber(p) == (OffsetNumber)0 && \
|
|
|
|
ItemPointerGetBlockNumber(p) == (BlockNumber)0)
|
|
|
|
#define ItemPointerSetMax(p) \
|
|
|
|
ItemPointerSet((p), InvalidBlockNumber, (OffsetNumber)0xffff)
|
|
|
|
#define ItemPointerIsMax(p) \
|
|
|
|
(ItemPointerGetOffsetNumber(p) == (OffsetNumber)0xffff && \
|
|
|
|
ItemPointerGetBlockNumber(p) == InvalidBlockNumber)
|
|
|
|
#define ItemPointerSetLossyPage(p, b) \
|
|
|
|
ItemPointerSet((p), (b), (OffsetNumber)0xffff)
|
|
|
|
#define ItemPointerIsLossyPage(p) \
|
|
|
|
(ItemPointerGetOffsetNumber(p) == (OffsetNumber)0xffff && \
|
|
|
|
ItemPointerGetBlockNumber(p) != InvalidBlockNumber)
|
|
|
|
|
2007-04-10 00:04:08 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BlockIdData child_blkno; /* use it instead of BlockNumber to save space
|
|
|
|
* on page */
|
|
|
|
ItemPointerData key;
|
|
|
|
} PostingItem;
|
|
|
|
|
|
|
|
#define PostingItemGetBlockNumber(pointer) \
|
|
|
|
BlockIdGetBlockNumber(&(pointer)->child_blkno)
|
|
|
|
|
|
|
|
#define PostingItemSetBlockNumber(pointer, blockNumber) \
|
|
|
|
BlockIdSet(&((pointer)->child_blkno), (blockNumber))
|
|
|
|
|
2006-05-02 13:28:56 +02:00
|
|
|
/*
|
2007-04-10 00:04:08 +02:00
|
|
|
* Support work on IndexTuple on leaf pages
|
2006-05-02 13:28:56 +02:00
|
|
|
*/
|
|
|
|
#define GinGetNPosting(itup) GinItemPointerGetOffsetNumber(&(itup)->t_tid)
|
|
|
|
#define GinSetNPosting(itup,n) ItemPointerSetOffsetNumber(&(itup)->t_tid,(n))
|
|
|
|
#define GIN_TREE_POSTING ((OffsetNumber)0xffff)
|
|
|
|
#define GinIsPostingTree(itup) ( GinGetNPosting(itup)==GIN_TREE_POSTING )
|
2006-10-04 02:30:14 +02:00
|
|
|
#define GinSetPostingTree(itup, blkno) ( GinSetNPosting((itup),GIN_TREE_POSTING ), ItemPointerSetBlockNumber(&(itup)->t_tid, blkno) )
|
|
|
|
#define GinGetPostingTree(itup) GinItemPointerGetBlockNumber(&(itup)->t_tid)
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
#define GinGetOrigSizePosting(itup) GinItemPointerGetBlockNumber(&(itup)->t_tid)
|
2006-05-02 13:28:56 +02:00
|
|
|
#define GinSetOrigSizePosting(itup,n) ItemPointerSetBlockNumber(&(itup)->t_tid,(n))
|
|
|
|
#define GinGetPosting(itup) ( (ItemPointer)(( ((char*)(itup)) + SHORTALIGN(GinGetOrigSizePosting(itup)) )) )
|
|
|
|
|
|
|
|
#define GinMaxItemSize \
|
2006-10-04 02:30:14 +02:00
|
|
|
((BLCKSZ - SizeOfPageHeaderData - \
|
2006-05-02 13:28:56 +02:00
|
|
|
MAXALIGN(sizeof(GinPageOpaqueData))) / 3 - sizeof(ItemIdData))
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Data (posting tree) pages
|
|
|
|
*/
|
2008-07-13 23:50:04 +02:00
|
|
|
#define GinDataPageGetRightBound(page) ((ItemPointer) PageGetContents(page))
|
2006-05-02 13:28:56 +02:00
|
|
|
#define GinDataPageGetData(page) \
|
2008-07-13 23:50:04 +02:00
|
|
|
(PageGetContents(page) + MAXALIGN(sizeof(ItemPointerData)))
|
|
|
|
#define GinSizeOfItem(page) \
|
|
|
|
(GinPageIsLeaf(page) ? sizeof(ItemPointerData) : sizeof(PostingItem))
|
|
|
|
#define GinDataPageGetItem(page,i) \
|
|
|
|
(GinDataPageGetData(page) + ((i)-1) * GinSizeOfItem(page))
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
#define GinDataPageGetFreeSpace(page) \
|
2008-07-13 23:50:04 +02:00
|
|
|
(BLCKSZ - MAXALIGN(SizeOfPageHeaderData) \
|
|
|
|
- MAXALIGN(sizeof(ItemPointerData)) \
|
|
|
|
- GinPageGetOpaque(page)->maxoff * GinSizeOfItem(page) \
|
|
|
|
- MAXALIGN(sizeof(GinPageOpaqueData)))
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2009-03-24 21:17:18 +01:00
|
|
|
/*
|
|
|
|
* List pages
|
|
|
|
*/
|
|
|
|
#define GinListPageSize \
|
|
|
|
( BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(GinPageOpaqueData)) )
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Storage type for GIN's reloptions
|
|
|
|
*/
|
|
|
|
typedef struct GinOptions
|
|
|
|
{
|
|
|
|
int32 vl_len_; /* varlena header (do not touch directly!) */
|
|
|
|
bool useFastUpdate; /* use fast updates? */
|
|
|
|
} GinOptions;
|
|
|
|
|
|
|
|
#define GIN_DEFAULT_USE_FASTUPDATE true
|
|
|
|
#define GinGetUseFastUpdate(relation) \
|
|
|
|
((relation)->rd_options ? \
|
|
|
|
((GinOptions *) (relation)->rd_options)->useFastUpdate : GIN_DEFAULT_USE_FASTUPDATE)
|
|
|
|
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
#define GIN_UNLOCK BUFFER_LOCK_UNLOCK
|
|
|
|
#define GIN_SHARE BUFFER_LOCK_SHARE
|
2006-05-02 13:28:56 +02:00
|
|
|
#define GIN_EXCLUSIVE BUFFER_LOCK_EXCLUSIVE
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct GinState
|
|
|
|
{
|
2008-07-11 23:06:29 +02:00
|
|
|
FmgrInfo compareFn[INDEX_MAX_KEYS];
|
|
|
|
FmgrInfo extractValueFn[INDEX_MAX_KEYS];
|
|
|
|
FmgrInfo extractQueryFn[INDEX_MAX_KEYS];
|
|
|
|
FmgrInfo consistentFn[INDEX_MAX_KEYS];
|
|
|
|
FmgrInfo comparePartialFn[INDEX_MAX_KEYS]; /* optional method */
|
|
|
|
|
|
|
|
bool canPartialMatch[INDEX_MAX_KEYS]; /* can opclass perform partial
|
|
|
|
* match (prefix search)? */
|
|
|
|
|
|
|
|
TupleDesc tupdesc[INDEX_MAX_KEYS];
|
|
|
|
TupleDesc origTupdesc;
|
|
|
|
bool oneCol;
|
2006-05-02 13:28:56 +02:00
|
|
|
} GinState;
|
|
|
|
|
|
|
|
/* XLog stuff */
|
|
|
|
|
|
|
|
#define XLOG_GIN_CREATE_INDEX 0x00
|
|
|
|
|
|
|
|
#define XLOG_GIN_CREATE_PTREE 0x10
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct ginxlogCreatePostingTree
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber blkno;
|
|
|
|
uint32 nitem;
|
2006-05-02 13:28:56 +02:00
|
|
|
/* follows list of heap's ItemPointer */
|
|
|
|
} ginxlogCreatePostingTree;
|
|
|
|
|
|
|
|
#define XLOG_GIN_INSERT 0x20
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct ginxlogInsert
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber blkno;
|
|
|
|
BlockNumber updateBlkno;
|
|
|
|
OffsetNumber offset;
|
|
|
|
bool isDelete;
|
|
|
|
bool isData;
|
|
|
|
bool isLeaf;
|
|
|
|
OffsetNumber nitem;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* follows: tuples or ItemPointerData or PostingItem or list of
|
|
|
|
* ItemPointerData
|
|
|
|
*/
|
2006-05-02 13:28:56 +02:00
|
|
|
} ginxlogInsert;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
#define XLOG_GIN_SPLIT 0x30
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct ginxlogSplit
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber lblkno;
|
|
|
|
BlockNumber rootBlkno;
|
|
|
|
BlockNumber rblkno;
|
|
|
|
BlockNumber rrlink;
|
|
|
|
OffsetNumber separator;
|
|
|
|
OffsetNumber nitem;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
bool isData;
|
|
|
|
bool isLeaf;
|
|
|
|
bool isRootSplit;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
BlockNumber leftChildBlkno;
|
|
|
|
BlockNumber updateBlkno;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
ItemPointerData rightbound; /* used only in posting tree */
|
2006-05-02 13:28:56 +02:00
|
|
|
/* follows: list of tuple or ItemPointerData or PostingItem */
|
|
|
|
} ginxlogSplit;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
#define XLOG_GIN_VACUUM_PAGE 0x40
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct ginxlogVacuumPage
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber blkno;
|
|
|
|
OffsetNumber nitem;
|
2006-05-02 13:28:56 +02:00
|
|
|
/* follows content of page */
|
|
|
|
} ginxlogVacuumPage;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
#define XLOG_GIN_DELETE_PAGE 0x50
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct ginxlogDeletePage
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber blkno;
|
|
|
|
BlockNumber parentBlkno;
|
|
|
|
OffsetNumber parentOffset;
|
|
|
|
BlockNumber leftBlkno;
|
|
|
|
BlockNumber rightLink;
|
2006-05-02 13:28:56 +02:00
|
|
|
} ginxlogDeletePage;
|
|
|
|
|
2009-03-24 21:17:18 +01:00
|
|
|
#define XLOG_GIN_UPDATE_META_PAGE 0x60
|
|
|
|
|
|
|
|
typedef struct ginxlogUpdateMeta
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
GinMetaPageData metadata;
|
|
|
|
BlockNumber prevTail;
|
|
|
|
BlockNumber newRightlink;
|
|
|
|
int32 ntuples; /* if ntuples > 0 then metadata.tail was updated
|
|
|
|
* with that many tuples; else new sub list was
|
|
|
|
* inserted */
|
|
|
|
/* array of inserted tuples follows */
|
|
|
|
} ginxlogUpdateMeta;
|
|
|
|
|
|
|
|
#define XLOG_GIN_INSERT_LISTPAGE 0x70
|
|
|
|
|
|
|
|
typedef struct ginxlogInsertListPage
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
BlockNumber blkno;
|
|
|
|
BlockNumber rightlink;
|
|
|
|
int32 ntuples;
|
|
|
|
/* array of inserted tuples follows */
|
|
|
|
} ginxlogInsertListPage;
|
|
|
|
|
|
|
|
#define XLOG_GIN_DELETE_LISTPAGE 0x80
|
|
|
|
|
|
|
|
#define GIN_NDELETE_AT_ONCE 16
|
|
|
|
typedef struct ginxlogDeleteListPages
|
|
|
|
{
|
|
|
|
RelFileNode node;
|
|
|
|
GinMetaPageData metadata;
|
|
|
|
int32 ndeleted;
|
|
|
|
BlockNumber toDelete[GIN_NDELETE_AT_ONCE];
|
|
|
|
} ginxlogDeleteListPages;
|
|
|
|
|
|
|
|
|
2006-05-02 13:28:56 +02:00
|
|
|
/* ginutil.c */
|
2006-07-04 00:45:41 +02:00
|
|
|
extern Datum ginoptions(PG_FUNCTION_ARGS);
|
2006-10-04 02:30:14 +02:00
|
|
|
extern void initGinState(GinState *state, Relation index);
|
2006-05-02 13:28:56 +02:00
|
|
|
extern Buffer GinNewBuffer(Relation index);
|
|
|
|
extern void GinInitBuffer(Buffer b, uint32 f);
|
|
|
|
extern void GinInitPage(Page page, uint32 f, Size pageSize);
|
2009-03-24 21:17:18 +01:00
|
|
|
extern void GinInitMetabuffer(Buffer b);
|
2008-07-11 23:06:29 +02:00
|
|
|
extern int compareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, Datum b);
|
2009-03-24 21:17:18 +01:00
|
|
|
extern int compareAttEntries(GinState *ginstate, OffsetNumber attnum_a, Datum a,
|
2008-07-11 23:06:29 +02:00
|
|
|
OffsetNumber attnum_b, Datum b);
|
|
|
|
extern Datum *extractEntriesS(GinState *ginstate, OffsetNumber attnum, Datum value,
|
2007-11-15 22:14:46 +01:00
|
|
|
int32 *nentries, bool *needUnique);
|
2008-07-11 23:06:29 +02:00
|
|
|
extern Datum *extractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nentries);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2008-07-11 23:06:29 +02:00
|
|
|
extern Datum gin_index_getattr(GinState *ginstate, IndexTuple tuple);
|
|
|
|
extern OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple);
|
2009-03-24 21:17:18 +01:00
|
|
|
|
2006-05-02 13:28:56 +02:00
|
|
|
/* gininsert.c */
|
|
|
|
extern Datum ginbuild(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum gininsert(PG_FUNCTION_ARGS);
|
2009-03-24 21:17:18 +01:00
|
|
|
extern void ginEntryInsert(Relation index, GinState *ginstate,
|
|
|
|
OffsetNumber attnum, Datum value,
|
|
|
|
ItemPointerData *items, uint32 nitem,
|
|
|
|
bool isBuild);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* ginxlog.c */
|
|
|
|
extern void gin_redo(XLogRecPtr lsn, XLogRecord *record);
|
|
|
|
extern void gin_desc(StringInfo buf, uint8 xl_info, char *rec);
|
|
|
|
extern void gin_xlog_startup(void);
|
|
|
|
extern void gin_xlog_cleanup(void);
|
2006-08-07 18:57:57 +02:00
|
|
|
extern bool gin_safe_restartpoint(void);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* ginbtree.c */
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct GinBtreeStack
|
|
|
|
{
|
|
|
|
BlockNumber blkno;
|
|
|
|
Buffer buffer;
|
|
|
|
OffsetNumber off;
|
|
|
|
/* predictNumber contains prediction number of pages on current level */
|
|
|
|
uint32 predictNumber;
|
2006-05-02 13:28:56 +02:00
|
|
|
struct GinBtreeStack *parent;
|
|
|
|
} GinBtreeStack;
|
|
|
|
|
|
|
|
typedef struct GinBtreeData *GinBtree;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct GinBtreeData
|
|
|
|
{
|
2006-05-02 13:28:56 +02:00
|
|
|
/* search methods */
|
2006-10-04 02:30:14 +02:00
|
|
|
BlockNumber (*findChildPage) (GinBtree, GinBtreeStack *);
|
|
|
|
bool (*isMoveRight) (GinBtree, Page);
|
|
|
|
bool (*findItem) (GinBtree, GinBtreeStack *);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* insert methods */
|
2006-10-04 02:30:14 +02:00
|
|
|
OffsetNumber (*findChildPtr) (GinBtree, Page, BlockNumber, OffsetNumber);
|
|
|
|
BlockNumber (*getLeftMostPage) (GinBtree, Page);
|
|
|
|
bool (*isEnoughSpace) (GinBtree, Buffer, OffsetNumber);
|
|
|
|
void (*placeToPage) (GinBtree, Buffer, OffsetNumber, XLogRecData **);
|
|
|
|
Page (*splitPage) (GinBtree, Buffer, Buffer, OffsetNumber, XLogRecData **);
|
|
|
|
void (*fillRoot) (GinBtree, Buffer, Buffer, Buffer);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
bool searchMode;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
Relation index;
|
|
|
|
GinState *ginstate;
|
|
|
|
bool fullScan;
|
|
|
|
bool isBuild;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
BlockNumber rightblkno;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* Entry options */
|
2008-07-11 23:06:29 +02:00
|
|
|
OffsetNumber entryAttnum;
|
2006-10-04 02:30:14 +02:00
|
|
|
Datum entryValue;
|
|
|
|
IndexTuple entry;
|
|
|
|
bool isDelete;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* Data (posting tree) option */
|
2006-10-04 02:30:14 +02:00
|
|
|
ItemPointerData *items;
|
|
|
|
uint32 nitem;
|
|
|
|
uint32 curitem;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
PostingItem pitem;
|
2006-05-02 13:28:56 +02:00
|
|
|
} GinBtreeData;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
extern GinBtreeStack *ginPrepareFindLeafPage(GinBtree btree, BlockNumber blkno);
|
|
|
|
extern GinBtreeStack *ginFindLeafPage(GinBtree btree, GinBtreeStack *stack);
|
|
|
|
extern void freeGinBtreeStack(GinBtreeStack *stack);
|
2006-05-02 13:28:56 +02:00
|
|
|
extern void ginInsertValue(GinBtree btree, GinBtreeStack *stack);
|
2006-10-04 02:30:14 +02:00
|
|
|
extern void findParents(GinBtree btree, GinBtreeStack *stack, BlockNumber rootBlkno);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* ginentrypage.c */
|
2009-03-24 21:17:18 +01:00
|
|
|
extern IndexTuple GinFormTuple(GinState *ginstate, OffsetNumber attnum, Datum key,
|
2008-07-11 23:06:29 +02:00
|
|
|
ItemPointerData *ipd, uint32 nipd);
|
|
|
|
extern void prepareEntryScan(GinBtree btree, Relation index, OffsetNumber attnum,
|
|
|
|
Datum value, GinState *ginstate);
|
2006-05-02 13:28:56 +02:00
|
|
|
extern void entryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf);
|
|
|
|
extern IndexTuple ginPageGetLinkItup(Buffer buf);
|
|
|
|
|
|
|
|
/* gindatapage.c */
|
2006-10-04 02:30:14 +02:00
|
|
|
extern int compareItemPointers(ItemPointer a, ItemPointer b);
|
2009-03-24 23:06:03 +01:00
|
|
|
extern void MergeItemPointers(ItemPointerData *dst,
|
2006-10-04 02:30:14 +02:00
|
|
|
ItemPointerData *a, uint32 na,
|
2009-03-24 23:06:03 +01:00
|
|
|
ItemPointerData *b, uint32 nb);
|
2006-10-04 02:30:14 +02:00
|
|
|
|
|
|
|
extern void GinDataPageAddItem(Page page, void *data, OffsetNumber offset);
|
2006-05-02 13:28:56 +02:00
|
|
|
extern void PageDeletePostingItem(Page page, OffsetNumber offset);
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GinBtreeData btree;
|
|
|
|
GinBtreeStack *stack;
|
2006-05-02 13:28:56 +02:00
|
|
|
} GinPostingTreeScan;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
extern GinPostingTreeScan *prepareScanPostingTree(Relation index,
|
|
|
|
BlockNumber rootBlkno, bool searchMode);
|
|
|
|
extern void insertItemPointer(GinPostingTreeScan *gdi,
|
|
|
|
ItemPointerData *items, uint32 nitem);
|
|
|
|
extern Buffer scanBeginPostingTree(GinPostingTreeScan *gdi);
|
2006-05-02 13:28:56 +02:00
|
|
|
extern void dataFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf);
|
2006-10-04 02:30:14 +02:00
|
|
|
extern void prepareDataScan(GinBtree btree, Relation index);
|
|
|
|
|
2006-05-02 13:28:56 +02:00
|
|
|
/* ginscan.c */
|
|
|
|
|
|
|
|
typedef struct GinScanEntryData *GinScanEntry;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct GinScanEntryData
|
|
|
|
{
|
2006-05-02 13:28:56 +02:00
|
|
|
/* link to the equals entry in current scan key */
|
2006-10-04 02:30:14 +02:00
|
|
|
GinScanEntry master;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
/*
|
|
|
|
* link to values reported to consistentFn, points to
|
|
|
|
* GinScanKey->entryRes[i]
|
|
|
|
*/
|
|
|
|
bool *pval;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
/* entry, got from extractQueryFn */
|
|
|
|
Datum entry;
|
2008-07-11 23:06:29 +02:00
|
|
|
OffsetNumber attnum;
|
2009-03-25 23:19:02 +01:00
|
|
|
Pointer extra_data;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2008-04-22 19:52:43 +02:00
|
|
|
/* Current page in posting tree */
|
2006-10-04 02:30:14 +02:00
|
|
|
Buffer buffer;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2008-04-22 19:52:43 +02:00
|
|
|
/* current ItemPointer to heap */
|
|
|
|
ItemPointerData curItem;
|
|
|
|
|
2008-05-16 18:31:02 +02:00
|
|
|
/* partial match support */
|
|
|
|
bool isPartialMatch;
|
|
|
|
TIDBitmap *partialMatch;
|
2009-01-10 22:08:36 +01:00
|
|
|
TBMIterator *partialMatchIterator;
|
2008-05-16 18:31:02 +02:00
|
|
|
TBMIterateResult *partialMatchResult;
|
|
|
|
StrategyNumber strategy;
|
|
|
|
|
2008-04-22 19:52:43 +02:00
|
|
|
/* used for Posting list and one page in Posting tree */
|
2006-10-04 02:30:14 +02:00
|
|
|
ItemPointerData *list;
|
2008-04-22 19:52:43 +02:00
|
|
|
uint32 nlist;
|
|
|
|
OffsetNumber offset;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
bool isFinished;
|
|
|
|
bool reduceResult;
|
|
|
|
uint32 predictNumberResult;
|
2006-05-02 13:28:56 +02:00
|
|
|
} GinScanEntryData;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct GinScanKeyData
|
|
|
|
{
|
|
|
|
/* Number of entries in query (got by extractQueryFn) */
|
|
|
|
uint32 nentries;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* array of ItemPointer result, reported to consistentFn */
|
2006-10-04 02:30:14 +02:00
|
|
|
bool *entryRes;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
/* array of scans per entry */
|
|
|
|
GinScanEntry scanEntry;
|
2009-03-25 23:19:02 +01:00
|
|
|
Pointer *extra_data;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* for calling consistentFn(GinScanKey->entryRes, strategy, query) */
|
2006-10-04 02:30:14 +02:00
|
|
|
StrategyNumber strategy;
|
|
|
|
Datum query;
|
2008-07-11 23:06:29 +02:00
|
|
|
OffsetNumber attnum;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
ItemPointerData curItem;
|
|
|
|
bool firstCall;
|
|
|
|
bool isFinished;
|
2006-05-02 13:28:56 +02:00
|
|
|
} GinScanKeyData;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef GinScanKeyData *GinScanKey;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct GinScanOpaqueData
|
|
|
|
{
|
|
|
|
MemoryContext tempCtx;
|
|
|
|
GinState ginstate;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
GinScanKey keys;
|
|
|
|
uint32 nkeys;
|
2007-11-15 22:14:46 +01:00
|
|
|
bool isVoidRes; /* true if ginstate.extractQueryFn guarantees
|
|
|
|
* that nothing will be found */
|
2006-05-02 13:28:56 +02:00
|
|
|
} GinScanOpaqueData;
|
|
|
|
|
|
|
|
typedef GinScanOpaqueData *GinScanOpaque;
|
|
|
|
|
|
|
|
extern Datum ginbeginscan(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum ginendscan(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum ginrescan(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum ginmarkpos(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum ginrestrpos(PG_FUNCTION_ARGS);
|
2006-07-11 15:54:25 +02:00
|
|
|
extern void newScanKey(IndexScanDesc scan);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* ginget.c */
|
2007-07-25 14:22:54 +02:00
|
|
|
extern PGDLLIMPORT int GinFuzzySearchLimit;
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2008-04-11 00:25:26 +02:00
|
|
|
extern Datum gingetbitmap(PG_FUNCTION_ARGS);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
|
|
|
/* ginvacuum.c */
|
|
|
|
extern Datum ginbulkdelete(PG_FUNCTION_ARGS);
|
|
|
|
extern Datum ginvacuumcleanup(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
/* ginarrayproc.c */
|
|
|
|
extern Datum ginarrayextract(PG_FUNCTION_ARGS);
|
2007-08-21 03:11:32 +02:00
|
|
|
extern Datum ginqueryarrayextract(PG_FUNCTION_ARGS);
|
2006-05-02 13:28:56 +02:00
|
|
|
extern Datum ginarrayconsistent(PG_FUNCTION_ARGS);
|
|
|
|
|
|
|
|
/* ginbulk.c */
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct EntryAccumulator
|
|
|
|
{
|
2008-07-11 23:06:29 +02:00
|
|
|
OffsetNumber attnum;
|
|
|
|
Datum value;
|
|
|
|
uint32 length;
|
|
|
|
uint32 number;
|
2006-05-02 13:28:56 +02:00
|
|
|
ItemPointerData *list;
|
2008-07-11 23:06:29 +02:00
|
|
|
bool shouldSort;
|
2006-10-04 02:30:14 +02:00
|
|
|
struct EntryAccumulator *left;
|
|
|
|
struct EntryAccumulator *right;
|
2006-05-02 13:28:56 +02:00
|
|
|
} EntryAccumulator;
|
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GinState *ginstate;
|
|
|
|
EntryAccumulator *entries;
|
2006-07-11 18:55:34 +02:00
|
|
|
uint32 maxdepth;
|
2006-10-04 02:30:14 +02:00
|
|
|
EntryAccumulator **stack;
|
|
|
|
uint32 stackpos;
|
2007-11-16 22:50:06 +01:00
|
|
|
long allocatedMemory;
|
2006-07-11 18:55:34 +02:00
|
|
|
|
2006-10-04 02:30:14 +02:00
|
|
|
uint32 length;
|
|
|
|
EntryAccumulator *entryallocator;
|
2006-05-02 13:28:56 +02:00
|
|
|
} BuildAccumulator;
|
|
|
|
|
|
|
|
extern void ginInitBA(BuildAccumulator *accum);
|
2006-10-04 02:30:14 +02:00
|
|
|
extern void ginInsertRecordBA(BuildAccumulator *accum,
|
2009-03-24 21:17:18 +01:00
|
|
|
ItemPointer heapptr,
|
2008-07-11 23:06:29 +02:00
|
|
|
OffsetNumber attnum, Datum *entries, int32 nentry);
|
|
|
|
extern ItemPointerData *ginGetEntry(BuildAccumulator *accum, OffsetNumber *attnum, Datum *entry, uint32 *n);
|
2006-05-02 13:28:56 +02:00
|
|
|
|
2009-03-24 21:17:18 +01:00
|
|
|
/* ginfast.c */
|
|
|
|
|
|
|
|
typedef struct GinTupleCollector
|
|
|
|
{
|
|
|
|
IndexTuple *tuples;
|
|
|
|
uint32 ntuples;
|
|
|
|
uint32 lentuples;
|
|
|
|
uint32 sumsize;
|
|
|
|
} GinTupleCollector;
|
|
|
|
|
|
|
|
extern void ginHeapTupleFastInsert(Relation index, GinState *ginstate,
|
|
|
|
GinTupleCollector *collector);
|
|
|
|
extern uint32 ginHeapTupleFastCollect(Relation index, GinState *ginstate,
|
|
|
|
GinTupleCollector *collector,
|
|
|
|
OffsetNumber attnum, Datum value, ItemPointer item);
|
|
|
|
extern void ginInsertCleanup(Relation index, GinState *ginstate,
|
|
|
|
bool vac_delay, IndexBulkDeleteResult *stats);
|
|
|
|
|
|
|
|
#endif /* GIN_H */
|