Commit 419d2374 authored by Tom Lane's avatar Tom Lane

Fix a passel of inappropriately-named global functions in GIN.

The GIN code has absolutely no business exporting GIN-specific functions
with names as generic as compareItemPointers() or newScanKey(); that's
just trouble waiting to happen.  I got annoyed about this again just now
and decided to fix it.  This commit ensures that all global symbols
defined in access/gin/ have names including "gin" or "Gin".  There were a
couple of cases, like names involving "PostingItem", where arguably the
names were already sufficiently nongeneric; but I figured as long as I was
risking creating merge problems for unapplied GIN patches I might as well
impose a uniform policy.

I didn't touch any static symbol names.  There might be some places
where it'd be appropriate to rename some static functions to match
siblings that are exported, but I'll leave that for another time.
parent 48c7d9f6
...@@ -173,8 +173,8 @@ freeGinBtreeStack(GinBtreeStack *stack) ...@@ -173,8 +173,8 @@ freeGinBtreeStack(GinBtreeStack *stack)
* with vacuum process * with vacuum process
*/ */
void void
findParents(GinBtree btree, GinBtreeStack *stack, ginFindParents(GinBtree btree, GinBtreeStack *stack,
BlockNumber rootBlkno) BlockNumber rootBlkno)
{ {
Page page; Page page;
...@@ -456,7 +456,7 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats) ...@@ -456,7 +456,7 @@ ginInsertValue(GinBtree btree, GinBtreeStack *stack, GinStatsData *buildStats)
* rightmost page, but we don't find parent, we should use * rightmost page, but we don't find parent, we should use
* plain search... * plain search...
*/ */
findParents(btree, stack, rootBlkno); ginFindParents(btree, stack, rootBlkno);
parent = stack->parent; parent = stack->parent;
page = BufferGetPage(parent->buffer); page = BufferGetPage(parent->buffer);
break; break;
......
...@@ -48,7 +48,7 @@ ginCombineData(RBNode *existing, const RBNode *newdata, void *arg) ...@@ -48,7 +48,7 @@ ginCombineData(RBNode *existing, const RBNode *newdata, void *arg)
{ {
int res; int res;
res = compareItemPointers(eo->list + eo->number - 1, en->list); res = ginCompareItemPointers(eo->list + eo->number - 1, en->list);
Assert(res != 0); Assert(res != 0);
if (res > 0) if (res > 0)
...@@ -67,8 +67,8 @@ cmpEntryAccumulator(const RBNode *a, const RBNode *b, void *arg) ...@@ -67,8 +67,8 @@ cmpEntryAccumulator(const RBNode *a, const RBNode *b, void *arg)
const EntryAccumulator *eb = (const EntryAccumulator *) b; const EntryAccumulator *eb = (const EntryAccumulator *) b;
BuildAccumulator *accum = (BuildAccumulator *) arg; BuildAccumulator *accum = (BuildAccumulator *) arg;
return compareAttEntries(accum->ginstate, ea->attnum, ea->value, return ginCompareAttEntries(accum->ginstate, ea->attnum, ea->value,
eb->attnum, eb->value); eb->attnum, eb->value);
} }
/* Allocator function for rbtree.c */ /* Allocator function for rbtree.c */
...@@ -226,7 +226,7 @@ ginInsertRecordBA(BuildAccumulator *accum, ItemPointer heapptr, OffsetNumber att ...@@ -226,7 +226,7 @@ ginInsertRecordBA(BuildAccumulator *accum, ItemPointer heapptr, OffsetNumber att
static int static int
qsortCompareItemPointers(const void *a, const void *b) qsortCompareItemPointers(const void *a, const void *b)
{ {
int res = compareItemPointers((ItemPointer) a, (ItemPointer) b); int res = ginCompareItemPointers((ItemPointer) a, (ItemPointer) b);
Assert(res != 0); Assert(res != 0);
return res; return res;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "utils/rel.h" #include "utils/rel.h"
int int
compareItemPointers(ItemPointer a, ItemPointer b) ginCompareItemPointers(ItemPointer a, ItemPointer b)
{ {
if (GinItemPointerGetBlockNumber(a) == GinItemPointerGetBlockNumber(b)) if (GinItemPointerGetBlockNumber(a) == GinItemPointerGetBlockNumber(b))
{ {
...@@ -37,9 +37,9 @@ compareItemPointers(ItemPointer a, ItemPointer b) ...@@ -37,9 +37,9 @@ compareItemPointers(ItemPointer a, ItemPointer b)
* Caller is responsible that there is enough space at *dst. * Caller is responsible that there is enough space at *dst.
*/ */
uint32 uint32
MergeItemPointers(ItemPointerData *dst, ginMergeItemPointers(ItemPointerData *dst,
ItemPointerData *a, uint32 na, ItemPointerData *a, uint32 na,
ItemPointerData *b, uint32 nb) ItemPointerData *b, uint32 nb)
{ {
ItemPointerData *dptr = dst; ItemPointerData *dptr = dst;
ItemPointerData *aptr = a, ItemPointerData *aptr = a,
...@@ -47,7 +47,7 @@ MergeItemPointers(ItemPointerData *dst, ...@@ -47,7 +47,7 @@ MergeItemPointers(ItemPointerData *dst,
while (aptr - a < na && bptr - b < nb) while (aptr - a < na && bptr - b < nb)
{ {
int cmp = compareItemPointers(aptr, bptr); int cmp = ginCompareItemPointers(aptr, bptr);
if (cmp > 0) if (cmp > 0)
*dptr++ = *bptr++; *dptr++ = *bptr++;
...@@ -82,7 +82,7 @@ dataIsMoveRight(GinBtree btree, Page page) ...@@ -82,7 +82,7 @@ dataIsMoveRight(GinBtree btree, Page page)
if (GinPageRightMost(page)) if (GinPageRightMost(page))
return FALSE; return FALSE;
return (compareItemPointers(btree->items + btree->curitem, iptr) > 0) ? TRUE : FALSE; return (ginCompareItemPointers(btree->items + btree->curitem, iptr) > 0) ? TRUE : FALSE;
} }
/* /*
...@@ -131,7 +131,7 @@ dataLocateItem(GinBtree btree, GinBtreeStack *stack) ...@@ -131,7 +131,7 @@ dataLocateItem(GinBtree btree, GinBtreeStack *stack)
else else
{ {
pitem = (PostingItem *) GinDataPageGetItem(page, mid); pitem = (PostingItem *) GinDataPageGetItem(page, mid);
result = compareItemPointers(btree->items + btree->curitem, &(pitem->key)); result = ginCompareItemPointers(btree->items + btree->curitem, &(pitem->key));
} }
if (result == 0) if (result == 0)
...@@ -189,7 +189,7 @@ dataLocateLeafItem(GinBtree btree, GinBtreeStack *stack) ...@@ -189,7 +189,7 @@ dataLocateLeafItem(GinBtree btree, GinBtreeStack *stack)
{ {
OffsetNumber mid = low + ((high - low) / 2); OffsetNumber mid = low + ((high - low) / 2);
result = compareItemPointers(btree->items + btree->curitem, (ItemPointer) GinDataPageGetItem(page, mid)); result = ginCompareItemPointers(btree->items + btree->curitem, (ItemPointer) GinDataPageGetItem(page, mid));
if (result == 0) if (result == 0)
{ {
...@@ -297,7 +297,7 @@ GinDataPageAddItem(Page page, void *data, OffsetNumber offset) ...@@ -297,7 +297,7 @@ GinDataPageAddItem(Page page, void *data, OffsetNumber offset)
* Deletes posting item from non-leaf page * Deletes posting item from non-leaf page
*/ */
void void
PageDeletePostingItem(Page page, OffsetNumber offset) GinPageDeletePostingItem(Page page, OffsetNumber offset)
{ {
OffsetNumber maxoff = GinPageGetOpaque(page)->maxoff; OffsetNumber maxoff = GinPageGetOpaque(page)->maxoff;
...@@ -571,7 +571,7 @@ dataSplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogRe ...@@ -571,7 +571,7 @@ dataSplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogRe
* Also called from ginxlog, should not use btree * Also called from ginxlog, should not use btree
*/ */
void void
dataFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf) ginDataFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf)
{ {
Page page = BufferGetPage(root), Page page = BufferGetPage(root),
lpage = BufferGetPage(lbuf), lpage = BufferGetPage(lbuf),
...@@ -589,7 +589,7 @@ dataFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf) ...@@ -589,7 +589,7 @@ dataFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf)
} }
void void
prepareDataScan(GinBtree btree, Relation index) ginPrepareDataScan(GinBtree btree, Relation index)
{ {
memset(btree, 0, sizeof(GinBtreeData)); memset(btree, 0, sizeof(GinBtreeData));
...@@ -603,7 +603,7 @@ prepareDataScan(GinBtree btree, Relation index) ...@@ -603,7 +603,7 @@ prepareDataScan(GinBtree btree, Relation index)
btree->isEnoughSpace = dataIsEnoughSpace; btree->isEnoughSpace = dataIsEnoughSpace;
btree->placeToPage = dataPlaceToPage; btree->placeToPage = dataPlaceToPage;
btree->splitPage = dataSplitPage; btree->splitPage = dataSplitPage;
btree->fillRoot = dataFillRoot; btree->fillRoot = ginDataFillRoot;
btree->isData = TRUE; btree->isData = TRUE;
btree->searchMode = FALSE; btree->searchMode = FALSE;
...@@ -613,11 +613,11 @@ prepareDataScan(GinBtree btree, Relation index) ...@@ -613,11 +613,11 @@ prepareDataScan(GinBtree btree, Relation index)
} }
GinPostingTreeScan * GinPostingTreeScan *
prepareScanPostingTree(Relation index, BlockNumber rootBlkno, bool searchMode) ginPrepareScanPostingTree(Relation index, BlockNumber rootBlkno, bool searchMode)
{ {
GinPostingTreeScan *gdi = (GinPostingTreeScan *) palloc0(sizeof(GinPostingTreeScan)); GinPostingTreeScan *gdi = (GinPostingTreeScan *) palloc0(sizeof(GinPostingTreeScan));
prepareDataScan(&gdi->btree, index); ginPrepareDataScan(&gdi->btree, index);
gdi->btree.searchMode = searchMode; gdi->btree.searchMode = searchMode;
gdi->btree.fullScan = searchMode; gdi->btree.fullScan = searchMode;
...@@ -665,7 +665,7 @@ ginInsertItemPointer(GinPostingTreeScan *gdi, ...@@ -665,7 +665,7 @@ ginInsertItemPointer(GinPostingTreeScan *gdi,
} }
Buffer Buffer
scanBeginPostingTree(GinPostingTreeScan *gdi) ginScanBeginPostingTree(GinPostingTreeScan *gdi)
{ {
gdi->stack = ginFindLeafPage(&gdi->btree, gdi->stack); gdi->stack = ginFindLeafPage(&gdi->btree, gdi->stack);
return gdi->stack->buffer; return gdi->stack->buffer;
......
...@@ -172,10 +172,10 @@ entryIsMoveRight(GinBtree btree, Page page) ...@@ -172,10 +172,10 @@ entryIsMoveRight(GinBtree btree, Page page)
itup = getRightMostTuple(page); itup = getRightMostTuple(page);
if (compareAttEntries(btree->ginstate, if (ginCompareAttEntries(btree->ginstate,
btree->entryAttnum, btree->entryValue, btree->entryAttnum, btree->entryValue,
gintuple_get_attrnum(btree->ginstate, itup), gintuple_get_attrnum(btree->ginstate, itup),
gin_index_getattr(btree->ginstate, itup)) > 0) gin_index_getattr(btree->ginstate, itup)) > 0)
return TRUE; return TRUE;
return FALSE; return FALSE;
...@@ -221,8 +221,9 @@ entryLocateEntry(GinBtree btree, GinBtreeStack *stack) ...@@ -221,8 +221,9 @@ entryLocateEntry(GinBtree btree, GinBtreeStack *stack)
else else
{ {
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, mid)); itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, mid));
result = compareAttEntries(btree->ginstate, result = ginCompareAttEntries(btree->ginstate,
btree->entryAttnum, btree->entryValue, btree->entryAttnum,
btree->entryValue,
gintuple_get_attrnum(btree->ginstate, itup), gintuple_get_attrnum(btree->ginstate, itup),
gin_index_getattr(btree->ginstate, itup)); gin_index_getattr(btree->ginstate, itup));
} }
...@@ -286,8 +287,9 @@ entryLocateLeafEntry(GinBtree btree, GinBtreeStack *stack) ...@@ -286,8 +287,9 @@ entryLocateLeafEntry(GinBtree btree, GinBtreeStack *stack)
int result; int result;
itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, mid)); itup = (IndexTuple) PageGetItem(page, PageGetItemId(page, mid));
result = compareAttEntries(btree->ginstate, result = ginCompareAttEntries(btree->ginstate,
btree->entryAttnum, btree->entryValue, btree->entryAttnum,
btree->entryValue,
gintuple_get_attrnum(btree->ginstate, itup), gintuple_get_attrnum(btree->ginstate, itup),
gin_index_getattr(btree->ginstate, itup)); gin_index_getattr(btree->ginstate, itup));
if (result == 0) if (result == 0)
...@@ -636,7 +638,7 @@ ginPageGetLinkItup(Buffer buf) ...@@ -636,7 +638,7 @@ ginPageGetLinkItup(Buffer buf)
* Also called from ginxlog, should not use btree * Also called from ginxlog, should not use btree
*/ */
void void
entryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf) ginEntryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf)
{ {
Page page; Page page;
IndexTuple itup; IndexTuple itup;
...@@ -655,7 +657,7 @@ entryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf) ...@@ -655,7 +657,7 @@ entryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf)
} }
void void
prepareEntryScan(GinBtree btree, Relation index, OffsetNumber attnum, Datum value, GinState *ginstate) ginPrepareEntryScan(GinBtree btree, Relation index, OffsetNumber attnum, Datum value, GinState *ginstate)
{ {
memset(btree, 0, sizeof(GinBtreeData)); memset(btree, 0, sizeof(GinBtreeData));
...@@ -670,7 +672,7 @@ prepareEntryScan(GinBtree btree, Relation index, OffsetNumber attnum, Datum valu ...@@ -670,7 +672,7 @@ prepareEntryScan(GinBtree btree, Relation index, OffsetNumber attnum, Datum valu
btree->isEnoughSpace = entryIsEnoughSpace; btree->isEnoughSpace = entryIsEnoughSpace;
btree->placeToPage = entryPlaceToPage; btree->placeToPage = entryPlaceToPage;
btree->splitPage = entrySplitPage; btree->splitPage = entrySplitPage;
btree->fillRoot = entryFillRoot; btree->fillRoot = ginEntryFillRoot;
btree->isData = FALSE; btree->isData = FALSE;
btree->searchMode = FALSE; btree->searchMode = FALSE;
......
...@@ -437,7 +437,7 @@ ginHeapTupleFastCollect(Relation index, GinState *ginstate, ...@@ -437,7 +437,7 @@ ginHeapTupleFastCollect(Relation index, GinState *ginstate,
int32 i, int32 i,
nentries; nentries;
entries = extractEntriesSU(ginstate, attnum, value, &nentries); entries = ginExtractEntriesSU(ginstate, attnum, value, &nentries);
if (nentries == 0) if (nentries == 0)
/* nothing to insert */ /* nothing to insert */
......
...@@ -51,7 +51,7 @@ findItemInPage(Page page, ItemPointer item, OffsetNumber *off) ...@@ -51,7 +51,7 @@ findItemInPage(Page page, ItemPointer item, OffsetNumber *off)
*/ */
for (*off = FirstOffsetNumber; *off <= maxoff; (*off)++) for (*off = FirstOffsetNumber; *off <= maxoff; (*off)++)
{ {
res = compareItemPointers(item, (ItemPointer) GinDataPageGetItem(page, *off)); res = ginCompareItemPointers(item, (ItemPointer) GinDataPageGetItem(page, *off));
if (res <= 0) if (res <= 0)
return true; return true;
...@@ -99,9 +99,9 @@ scanForItems(Relation index, GinScanEntry scanEntry, BlockNumber rootPostingTree ...@@ -99,9 +99,9 @@ scanForItems(Relation index, GinScanEntry scanEntry, BlockNumber rootPostingTree
Page page; Page page;
BlockNumber blkno; BlockNumber blkno;
gdi = prepareScanPostingTree(index, rootPostingTree, TRUE); gdi = ginPrepareScanPostingTree(index, rootPostingTree, TRUE);
buffer = scanBeginPostingTree(gdi); buffer = ginScanBeginPostingTree(gdi);
IncrBufferRefCount(buffer); /* prevent unpin in freeGinBtreeStack */ IncrBufferRefCount(buffer); /* prevent unpin in freeGinBtreeStack */
freeGinBtreeStack(gdi->stack); freeGinBtreeStack(gdi->stack);
...@@ -241,7 +241,8 @@ computePartialMatchList(GinBtreeData *btree, GinBtreeStack *stack, GinScanEntry ...@@ -241,7 +241,8 @@ computePartialMatchList(GinBtreeData *btree, GinBtreeStack *stack, GinScanEntry
if (gintuple_get_attrnum(btree->ginstate, itup) != scanEntry->attnum) if (gintuple_get_attrnum(btree->ginstate, itup) != scanEntry->attnum)
elog(ERROR, "lost saved point in index"); /* must not happen !!! */ elog(ERROR, "lost saved point in index"); /* must not happen !!! */
if (compareEntries(btree->ginstate, scanEntry->attnum, newDatum, savedDatum) == 0) if (ginCompareEntries(btree->ginstate, scanEntry->attnum,
newDatum, savedDatum) == 0)
{ {
/* Found! */ /* Found! */
if (btree->ginstate->origTupdesc->attrs[scanEntry->attnum - 1]->attbyval == false) if (btree->ginstate->origTupdesc->attrs[scanEntry->attnum - 1]->attbyval == false)
...@@ -298,7 +299,7 @@ startScanEntry(Relation index, GinState *ginstate, GinScanEntry entry) ...@@ -298,7 +299,7 @@ startScanEntry(Relation index, GinState *ginstate, GinScanEntry entry)
* posting list in memory * posting list in memory
*/ */
prepareEntryScan(&btreeEntry, index, entry->attnum, entry->entry, ginstate); ginPrepareEntryScan(&btreeEntry, index, entry->attnum, entry->entry, ginstate);
btreeEntry.searchMode = TRUE; btreeEntry.searchMode = TRUE;
stackEntry = ginFindLeafPage(&btreeEntry, NULL); stackEntry = ginFindLeafPage(&btreeEntry, NULL);
page = BufferGetPage(stackEntry->buffer); page = BufferGetPage(stackEntry->buffer);
...@@ -359,9 +360,9 @@ startScanEntry(Relation index, GinState *ginstate, GinScanEntry entry) ...@@ -359,9 +360,9 @@ startScanEntry(Relation index, GinState *ginstate, GinScanEntry entry)
*/ */
LockBuffer(stackEntry->buffer, GIN_UNLOCK); LockBuffer(stackEntry->buffer, GIN_UNLOCK);
needUnlock = FALSE; needUnlock = FALSE;
gdi = prepareScanPostingTree(index, rootPostingTree, TRUE); gdi = ginPrepareScanPostingTree(index, rootPostingTree, TRUE);
entry->buffer = scanBeginPostingTree(gdi); entry->buffer = ginScanBeginPostingTree(gdi);
/* /*
* We keep buffer pinned because we need to prevent deletion of * We keep buffer pinned because we need to prevent deletion of
...@@ -504,8 +505,8 @@ entryGetNextItem(Relation index, GinScanEntry entry) ...@@ -504,8 +505,8 @@ entryGetNextItem(Relation index, GinScanEntry entry)
LockBuffer(entry->buffer, GIN_UNLOCK); LockBuffer(entry->buffer, GIN_UNLOCK);
if (!ItemPointerIsValid(&entry->curItem) || if (!ItemPointerIsValid(&entry->curItem) ||
compareItemPointers(&entry->curItem, ginCompareItemPointers(&entry->curItem,
entry->list + entry->offset - 1) == 0) entry->list + entry->offset - 1) == 0)
{ {
/* /*
* First pages are deleted or empty, or we found exact * First pages are deleted or empty, or we found exact
...@@ -699,11 +700,11 @@ keyGetItem(Relation index, GinState *ginstate, MemoryContext tempCtx, ...@@ -699,11 +700,11 @@ keyGetItem(Relation index, GinState *ginstate, MemoryContext tempCtx,
entry = key->scanEntry + i; entry = key->scanEntry + i;
while (entry->isFinished == FALSE && while (entry->isFinished == FALSE &&
compareItemPointers(&entry->curItem, &myAdvancePast) <= 0) ginCompareItemPointers(&entry->curItem, &myAdvancePast) <= 0)
entryGetItem(index, entry); entryGetItem(index, entry);
if (entry->isFinished == FALSE && if (entry->isFinished == FALSE &&
compareItemPointers(&entry->curItem, &key->curItem) < 0) ginCompareItemPointers(&entry->curItem, &key->curItem) < 0)
key->curItem = entry->curItem; key->curItem = entry->curItem;
} }
...@@ -757,7 +758,7 @@ keyGetItem(Relation index, GinState *ginstate, MemoryContext tempCtx, ...@@ -757,7 +758,7 @@ keyGetItem(Relation index, GinState *ginstate, MemoryContext tempCtx,
{ {
entry = key->scanEntry + i; entry = key->scanEntry + i;
if (entry->isFinished == FALSE && if (entry->isFinished == FALSE &&
compareItemPointers(&entry->curItem, &curPageLossy) == 0) ginCompareItemPointers(&entry->curItem, &curPageLossy) == 0)
{ {
if (haveLossyEntry) if (haveLossyEntry)
{ {
...@@ -810,7 +811,7 @@ keyGetItem(Relation index, GinState *ginstate, MemoryContext tempCtx, ...@@ -810,7 +811,7 @@ keyGetItem(Relation index, GinState *ginstate, MemoryContext tempCtx,
{ {
entry = key->scanEntry + i; entry = key->scanEntry + i;
if (entry->isFinished == FALSE && if (entry->isFinished == FALSE &&
compareItemPointers(&entry->curItem, &key->curItem) == 0) ginCompareItemPointers(&entry->curItem, &key->curItem) == 0)
key->entryRes[i] = TRUE; key->entryRes[i] = TRUE;
else else
key->entryRes[i] = FALSE; key->entryRes[i] = FALSE;
...@@ -1071,10 +1072,10 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos) ...@@ -1071,10 +1072,10 @@ collectDatumForItem(IndexScanDesc scan, pendingPosition *pos)
datum[StopMiddle - 1] = gin_index_getattr(&so->ginstate, itup); datum[StopMiddle - 1] = gin_index_getattr(&so->ginstate, itup);
datumExtracted[StopMiddle - 1] = true; datumExtracted[StopMiddle - 1] = true;
} }
res = compareEntries(&so->ginstate, res = ginCompareEntries(&so->ginstate,
entry->attnum, entry->attnum,
entry->entry, entry->entry,
datum[StopMiddle - 1]); datum[StopMiddle - 1]);
if (res == 0) if (res == 0)
{ {
...@@ -1282,14 +1283,14 @@ scanGetItem(IndexScanDesc scan, ItemPointer advancePast, ...@@ -1282,14 +1283,14 @@ scanGetItem(IndexScanDesc scan, ItemPointer advancePast,
GinScanKey key = so->keys + i; GinScanKey key = so->keys + i;
while (key->isFinished == FALSE && while (key->isFinished == FALSE &&
compareItemPointers(&key->curItem, &myAdvancePast) <= 0) ginCompareItemPointers(&key->curItem, &myAdvancePast) <= 0)
keyGetItem(scan->indexRelation, &so->ginstate, so->tempCtx, keyGetItem(scan->indexRelation, &so->ginstate, so->tempCtx,
key, &myAdvancePast); key, &myAdvancePast);
if (key->isFinished) if (key->isFinished)
return FALSE; /* finished one of keys */ return FALSE; /* finished one of keys */
if (compareItemPointers(&key->curItem, item) < 0) if (ginCompareItemPointers(&key->curItem, item) < 0)
*item = key->curItem; *item = key->curItem;
} }
...@@ -1321,7 +1322,7 @@ scanGetItem(IndexScanDesc scan, ItemPointer advancePast, ...@@ -1321,7 +1322,7 @@ scanGetItem(IndexScanDesc scan, ItemPointer advancePast,
{ {
GinScanKey key = so->keys + i; GinScanKey key = so->keys + i;
if (compareItemPointers(item, &key->curItem) == 0) if (ginCompareItemPointers(item, &key->curItem) == 0)
continue; continue;
if (ItemPointerIsLossyPage(&key->curItem) && if (ItemPointerIsLossyPage(&key->curItem) &&
GinItemPointerGetBlockNumber(&key->curItem) == GinItemPointerGetBlockNumber(&key->curItem) ==
...@@ -1372,7 +1373,7 @@ gingetbitmap(PG_FUNCTION_ARGS) ...@@ -1372,7 +1373,7 @@ gingetbitmap(PG_FUNCTION_ARGS)
bool recheck; bool recheck;
if (GinIsNewKey(scan)) if (GinIsNewKey(scan))
newScanKey(scan); ginNewScanKey(scan);
if (GinIsVoidRes(scan)) if (GinIsVoidRes(scan))
PG_RETURN_INT64(0); PG_RETURN_INT64(0);
......
...@@ -114,9 +114,10 @@ addItemPointersToTuple(Relation index, GinState *ginstate, ...@@ -114,9 +114,10 @@ addItemPointersToTuple(Relation index, GinState *ginstate,
/* good, small enough */ /* good, small enough */
uint32 newnitem; uint32 newnitem;
newnitem = MergeItemPointers(GinGetPosting(res), newnitem = ginMergeItemPointers(GinGetPosting(res),
GinGetPosting(old), GinGetNPosting(old), GinGetPosting(old),
items, nitem); GinGetNPosting(old),
items, nitem);
/* merge might have eliminated some duplicate items */ /* merge might have eliminated some duplicate items */
GinShortenTuple(res, newnitem); GinShortenTuple(res, newnitem);
} }
...@@ -130,7 +131,7 @@ addItemPointersToTuple(Relation index, GinState *ginstate, ...@@ -130,7 +131,7 @@ addItemPointersToTuple(Relation index, GinState *ginstate,
postingRoot = createPostingTree(index, GinGetPosting(old), GinGetNPosting(old)); postingRoot = createPostingTree(index, GinGetPosting(old), GinGetNPosting(old));
GinSetPostingTree(res, postingRoot); GinSetPostingTree(res, postingRoot);
gdi = prepareScanPostingTree(index, postingRoot, FALSE); gdi = ginPrepareScanPostingTree(index, postingRoot, FALSE);
gdi->btree.isBuild = (buildStats != NULL); gdi->btree.isBuild = (buildStats != NULL);
ginInsertItemPointer(gdi, items, nitem, buildStats); ginInsertItemPointer(gdi, items, nitem, buildStats);
...@@ -166,7 +167,7 @@ ginEntryInsert(Relation index, GinState *ginstate, ...@@ -166,7 +167,7 @@ ginEntryInsert(Relation index, GinState *ginstate,
if (buildStats) if (buildStats)
buildStats->nEntries++; buildStats->nEntries++;
prepareEntryScan(&btree, index, attnum, value, ginstate); ginPrepareEntryScan(&btree, index, attnum, value, ginstate);
stack = ginFindLeafPage(&btree, NULL); stack = ginFindLeafPage(&btree, NULL);
page = BufferGetPage(stack->buffer); page = BufferGetPage(stack->buffer);
...@@ -187,7 +188,7 @@ ginEntryInsert(Relation index, GinState *ginstate, ...@@ -187,7 +188,7 @@ ginEntryInsert(Relation index, GinState *ginstate,
freeGinBtreeStack(stack); freeGinBtreeStack(stack);
/* insert into posting tree */ /* insert into posting tree */
gdi = prepareScanPostingTree(index, rootPostingTree, FALSE); gdi = ginPrepareScanPostingTree(index, rootPostingTree, FALSE);
gdi->btree.isBuild = (buildStats != NULL); gdi->btree.isBuild = (buildStats != NULL);
ginInsertItemPointer(gdi, items, nitem, buildStats); ginInsertItemPointer(gdi, items, nitem, buildStats);
pfree(gdi); pfree(gdi);
...@@ -233,7 +234,7 @@ ginHeapTupleBulkInsert(GinBuildState *buildstate, OffsetNumber attnum, Datum val ...@@ -233,7 +234,7 @@ ginHeapTupleBulkInsert(GinBuildState *buildstate, OffsetNumber attnum, Datum val
MemoryContext oldCtx; MemoryContext oldCtx;
oldCtx = MemoryContextSwitchTo(buildstate->funcCtx); oldCtx = MemoryContextSwitchTo(buildstate->funcCtx);
entries = extractEntriesSU(buildstate->accum.ginstate, attnum, value, &nentries); entries = ginExtractEntriesSU(buildstate->accum.ginstate, attnum, value, &nentries);
MemoryContextSwitchTo(oldCtx); MemoryContextSwitchTo(oldCtx);
if (nentries == 0) if (nentries == 0)
...@@ -420,7 +421,7 @@ ginHeapTupleInsert(Relation index, GinState *ginstate, OffsetNumber attnum, Datu ...@@ -420,7 +421,7 @@ ginHeapTupleInsert(Relation index, GinState *ginstate, OffsetNumber attnum, Datu
int32 i, int32 i,
nentries; nentries;
entries = extractEntriesSU(ginstate, attnum, value, &nentries); entries = ginExtractEntriesSU(ginstate, attnum, value, &nentries);
if (nentries == 0) if (nentries == 0)
/* nothing to insert */ /* nothing to insert */
......
...@@ -75,7 +75,8 @@ fillScanKey(GinState *ginstate, GinScanKey key, OffsetNumber attnum, Datum query ...@@ -75,7 +75,8 @@ fillScanKey(GinState *ginstate, GinScanKey key, OffsetNumber attnum, Datum query
/* link to the equals entry in current scan key */ /* link to the equals entry in current scan key */
key->scanEntry[i].master = NULL; key->scanEntry[i].master = NULL;
for (j = 0; j < i; j++) for (j = 0; j < i; j++)
if (compareEntries(ginstate, attnum, entryValues[i], entryValues[j]) == 0 && if (ginCompareEntries(ginstate, attnum,
entryValues[i], entryValues[j]) == 0 &&
key->scanEntry[i].isPartialMatch == key->scanEntry[j].isPartialMatch && key->scanEntry[i].isPartialMatch == key->scanEntry[j].isPartialMatch &&
key->scanEntry[i].strategy == key->scanEntry[j].strategy) key->scanEntry[i].strategy == key->scanEntry[j].strategy)
{ {
...@@ -155,7 +156,7 @@ freeScanKeys(GinScanKey keys, uint32 nkeys) ...@@ -155,7 +156,7 @@ freeScanKeys(GinScanKey keys, uint32 nkeys)
} }
void void
newScanKey(IndexScanDesc scan) ginNewScanKey(IndexScanDesc scan)
{ {
ScanKey scankey = scan->keyData; ScanKey scankey = scan->keyData;
GinScanOpaque so = (GinScanOpaque) scan->opaque; GinScanOpaque so = (GinScanOpaque) scan->opaque;
......
...@@ -236,22 +236,18 @@ GinInitMetabuffer(Buffer b) ...@@ -236,22 +236,18 @@ GinInitMetabuffer(Buffer b)
} }
int int
compareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, Datum b) ginCompareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, Datum b)
{ {
return DatumGetInt32( return DatumGetInt32(FunctionCall2(&ginstate->compareFn[attnum - 1],
FunctionCall2( a, b));
&ginstate->compareFn[attnum - 1],
a, b
)
);
} }
int int
compareAttEntries(GinState *ginstate, OffsetNumber attnum_a, Datum a, ginCompareAttEntries(GinState *ginstate, OffsetNumber attnum_a, Datum a,
OffsetNumber attnum_b, Datum b) OffsetNumber attnum_b, Datum b)
{ {
if (attnum_a == attnum_b) if (attnum_a == attnum_b)
return compareEntries(ginstate, attnum_a, a, b); return ginCompareEntries(ginstate, attnum_a, a, b);
return (attnum_a < attnum_b) ? -1 : 1; return (attnum_a < attnum_b) ? -1 : 1;
} }
...@@ -275,7 +271,7 @@ cmpEntries(const Datum *a, const Datum *b, cmpEntriesData *arg) ...@@ -275,7 +271,7 @@ cmpEntries(const Datum *a, const Datum *b, cmpEntriesData *arg)
} }
Datum * Datum *
extractEntriesS(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nentries, ginExtractEntriesS(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nentries,
bool *needUnique) bool *needUnique)
{ {
Datum *entries; Datum *entries;
...@@ -305,11 +301,11 @@ extractEntriesS(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nen ...@@ -305,11 +301,11 @@ extractEntriesS(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nen
Datum * Datum *
extractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nentries) ginExtractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nentries)
{ {
bool needUnique; bool needUnique;
Datum *entries = extractEntriesS(ginstate, attnum, value, nentries, Datum *entries = ginExtractEntriesS(ginstate, attnum, value, nentries,
&needUnique); &needUnique);
if (needUnique) if (needUnique)
{ {
...@@ -320,7 +316,7 @@ extractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *ne ...@@ -320,7 +316,7 @@ extractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *ne
while (ptr - entries < *nentries) while (ptr - entries < *nentries)
{ {
if (compareEntries(ginstate, attnum, *ptr, *res) != 0) if (ginCompareEntries(ginstate, attnum, *ptr, *res) != 0)
*(++res) = *ptr++; *(++res) = *ptr++;
else else
ptr++; ptr++;
......
...@@ -293,7 +293,7 @@ ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkn ...@@ -293,7 +293,7 @@ ginDeletePage(GinVacuumState *gvs, BlockNumber deleteBlkno, BlockNumber leftBlkn
Assert(PostingItemGetBlockNumber(tod) == deleteBlkno); Assert(PostingItemGetBlockNumber(tod) == deleteBlkno);
} while (0); } while (0);
#endif #endif
PageDeletePostingItem(parentPage, myoff); GinPageDeletePostingItem(parentPage, myoff);
page = BufferGetPage(dBuffer); page = BufferGetPage(dBuffer);
......
...@@ -339,12 +339,12 @@ ginRedoSplit(XLogRecPtr lsn, XLogRecord *record) ...@@ -339,12 +339,12 @@ ginRedoSplit(XLogRecPtr lsn, XLogRecord *record)
if (data->isData) if (data->isData)
{ {
Assert(data->rootBlkno != GIN_ROOT_BLKNO); Assert(data->rootBlkno != GIN_ROOT_BLKNO);
dataFillRoot(NULL, rootBuf, lbuffer, rbuffer); ginDataFillRoot(NULL, rootBuf, lbuffer, rbuffer);
} }
else else
{ {
Assert(data->rootBlkno == GIN_ROOT_BLKNO); Assert(data->rootBlkno == GIN_ROOT_BLKNO);
entryFillRoot(NULL, rootBuf, lbuffer, rbuffer); ginEntryFillRoot(NULL, rootBuf, lbuffer, rbuffer);
} }
PageSetLSN(rootPage, lsn); PageSetLSN(rootPage, lsn);
...@@ -448,7 +448,7 @@ ginRedoDeletePage(XLogRecPtr lsn, XLogRecord *record) ...@@ -448,7 +448,7 @@ ginRedoDeletePage(XLogRecPtr lsn, XLogRecord *record)
{ {
Assert(GinPageIsData(page)); Assert(GinPageIsData(page));
Assert(!GinPageIsLeaf(page)); Assert(!GinPageIsLeaf(page));
PageDeletePostingItem(page, data->parentOffset); GinPageDeletePostingItem(page, data->parentOffset);
PageSetLSN(page, lsn); PageSetLSN(page, lsn);
PageSetTLI(page, ThisTimeLineID); PageSetTLI(page, ThisTimeLineID);
MarkBufferDirty(buffer); MarkBufferDirty(buffer);
...@@ -813,14 +813,14 @@ ginContinueSplit(ginIncompleteSplit *split) ...@@ -813,14 +813,14 @@ ginContinueSplit(ginIncompleteSplit *split)
if (split->rootBlkno == GIN_ROOT_BLKNO) if (split->rootBlkno == GIN_ROOT_BLKNO)
{ {
prepareEntryScan(&btree, reln, InvalidOffsetNumber, (Datum) 0, NULL); ginPrepareEntryScan(&btree, reln, InvalidOffsetNumber, (Datum) 0, NULL);
btree.entry = ginPageGetLinkItup(buffer); btree.entry = ginPageGetLinkItup(buffer);
} }
else else
{ {
Page page = BufferGetPage(buffer); Page page = BufferGetPage(buffer);
prepareDataScan(&btree, reln); ginPrepareDataScan(&btree, reln);
PostingItemSetBlockNumber(&(btree.pitem), split->leftBlkno); PostingItemSetBlockNumber(&(btree.pitem), split->leftBlkno);
if (GinPageIsLeaf(page)) if (GinPageIsLeaf(page))
...@@ -838,7 +838,7 @@ ginContinueSplit(ginIncompleteSplit *split) ...@@ -838,7 +838,7 @@ ginContinueSplit(ginIncompleteSplit *split)
stack.off = InvalidOffsetNumber; stack.off = InvalidOffsetNumber;
stack.parent = NULL; stack.parent = NULL;
findParents(&btree, &stack, split->rootBlkno); ginFindParents(&btree, &stack, split->rootBlkno);
ginInsertValue(&btree, stack.parent, NULL); ginInsertValue(&btree, stack.parent, NULL);
FreeFakeRelcacheEntry(reln); FreeFakeRelcacheEntry(reln);
......
...@@ -362,12 +362,12 @@ extern Buffer GinNewBuffer(Relation index); ...@@ -362,12 +362,12 @@ extern Buffer GinNewBuffer(Relation index);
extern void GinInitBuffer(Buffer b, uint32 f); extern void GinInitBuffer(Buffer b, uint32 f);
extern void GinInitPage(Page page, uint32 f, Size pageSize); extern void GinInitPage(Page page, uint32 f, Size pageSize);
extern void GinInitMetabuffer(Buffer b); extern void GinInitMetabuffer(Buffer b);
extern int compareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, Datum b); extern int ginCompareEntries(GinState *ginstate, OffsetNumber attnum, Datum a, Datum b);
extern int compareAttEntries(GinState *ginstate, OffsetNumber attnum_a, Datum a, extern int ginCompareAttEntries(GinState *ginstate, OffsetNumber attnum_a, Datum a,
OffsetNumber attnum_b, Datum b); OffsetNumber attnum_b, Datum b);
extern Datum *extractEntriesS(GinState *ginstate, OffsetNumber attnum, Datum value, extern Datum *ginExtractEntriesS(GinState *ginstate, OffsetNumber attnum, Datum value,
int32 *nentries, bool *needUnique); int32 *nentries, bool *needUnique);
extern Datum *extractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nentries); extern Datum *ginExtractEntriesSU(GinState *ginstate, OffsetNumber attnum, Datum value, int32 *nentries);
extern Datum gin_index_getattr(GinState *ginstate, IndexTuple tuple); extern Datum gin_index_getattr(GinState *ginstate, IndexTuple tuple);
extern OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple); extern OffsetNumber gintuple_get_attrnum(GinState *ginstate, IndexTuple tuple);
...@@ -460,26 +460,26 @@ extern GinBtreeStack *ginFindLeafPage(GinBtree btree, GinBtreeStack *stack); ...@@ -460,26 +460,26 @@ extern GinBtreeStack *ginFindLeafPage(GinBtree btree, GinBtreeStack *stack);
extern void freeGinBtreeStack(GinBtreeStack *stack); extern void freeGinBtreeStack(GinBtreeStack *stack);
extern void ginInsertValue(GinBtree btree, GinBtreeStack *stack, extern void ginInsertValue(GinBtree btree, GinBtreeStack *stack,
GinStatsData *buildStats); GinStatsData *buildStats);
extern void findParents(GinBtree btree, GinBtreeStack *stack, BlockNumber rootBlkno); extern void ginFindParents(GinBtree btree, GinBtreeStack *stack, BlockNumber rootBlkno);
/* ginentrypage.c */ /* ginentrypage.c */
extern IndexTuple GinFormTuple(Relation index, GinState *ginstate, extern IndexTuple GinFormTuple(Relation index, GinState *ginstate,
OffsetNumber attnum, Datum key, OffsetNumber attnum, Datum key,
ItemPointerData *ipd, uint32 nipd, bool errorTooBig); ItemPointerData *ipd, uint32 nipd, bool errorTooBig);
extern void GinShortenTuple(IndexTuple itup, uint32 nipd); extern void GinShortenTuple(IndexTuple itup, uint32 nipd);
extern void prepareEntryScan(GinBtree btree, Relation index, OffsetNumber attnum, extern void ginPrepareEntryScan(GinBtree btree, Relation index, OffsetNumber attnum,
Datum value, GinState *ginstate); Datum value, GinState *ginstate);
extern void entryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf); extern void ginEntryFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf);
extern IndexTuple ginPageGetLinkItup(Buffer buf); extern IndexTuple ginPageGetLinkItup(Buffer buf);
/* gindatapage.c */ /* gindatapage.c */
extern int compareItemPointers(ItemPointer a, ItemPointer b); extern int ginCompareItemPointers(ItemPointer a, ItemPointer b);
extern uint32 MergeItemPointers(ItemPointerData *dst, extern uint32 ginMergeItemPointers(ItemPointerData *dst,
ItemPointerData *a, uint32 na, ItemPointerData *a, uint32 na,
ItemPointerData *b, uint32 nb); ItemPointerData *b, uint32 nb);
extern void GinDataPageAddItem(Page page, void *data, OffsetNumber offset); extern void GinDataPageAddItem(Page page, void *data, OffsetNumber offset);
extern void PageDeletePostingItem(Page page, OffsetNumber offset); extern void GinPageDeletePostingItem(Page page, OffsetNumber offset);
typedef struct typedef struct
{ {
...@@ -487,14 +487,14 @@ typedef struct ...@@ -487,14 +487,14 @@ typedef struct
GinBtreeStack *stack; GinBtreeStack *stack;
} GinPostingTreeScan; } GinPostingTreeScan;
extern GinPostingTreeScan *prepareScanPostingTree(Relation index, extern GinPostingTreeScan *ginPrepareScanPostingTree(Relation index,
BlockNumber rootBlkno, bool searchMode); BlockNumber rootBlkno, bool searchMode);
extern void ginInsertItemPointer(GinPostingTreeScan *gdi, extern void ginInsertItemPointer(GinPostingTreeScan *gdi,
ItemPointerData *items, uint32 nitem, ItemPointerData *items, uint32 nitem,
GinStatsData *buildStats); GinStatsData *buildStats);
extern Buffer scanBeginPostingTree(GinPostingTreeScan *gdi); extern Buffer ginScanBeginPostingTree(GinPostingTreeScan *gdi);
extern void dataFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf); extern void ginDataFillRoot(GinBtree btree, Buffer root, Buffer lbuf, Buffer rbuf);
extern void prepareDataScan(GinBtree btree, Relation index); extern void ginPrepareDataScan(GinBtree btree, Relation index);
/* ginscan.c */ /* ginscan.c */
...@@ -583,7 +583,7 @@ extern Datum ginendscan(PG_FUNCTION_ARGS); ...@@ -583,7 +583,7 @@ extern Datum ginendscan(PG_FUNCTION_ARGS);
extern Datum ginrescan(PG_FUNCTION_ARGS); extern Datum ginrescan(PG_FUNCTION_ARGS);
extern Datum ginmarkpos(PG_FUNCTION_ARGS); extern Datum ginmarkpos(PG_FUNCTION_ARGS);
extern Datum ginrestrpos(PG_FUNCTION_ARGS); extern Datum ginrestrpos(PG_FUNCTION_ARGS);
extern void newScanKey(IndexScanDesc scan); extern void ginNewScanKey(IndexScanDesc scan);
/* ginget.c */ /* ginget.c */
extern PGDLLIMPORT int GinFuzzySearchLimit; extern PGDLLIMPORT int GinFuzzySearchLimit;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment