mirror of
https://github.com/postgres/postgres.git
synced 2025-08-31 17:02:12 +03:00
Misc GIN refactoring.
Merge the isEnoughSpace and placeToPage functions in the b-tree interface into one function that tries to put a tuple on page, and returns false if it doesn't fit. Move createPostingTree function to gindatapage.c, and change its contract so that it can be passed more items than fit on the root page. It's in a better position than the callers to know how many items fit. Move ginMergeItemPointers out of gindatapage.c, into a separate file. These changes make no difference now, but reduce the footprint of Alexander Korotkov's upcoming patch to pack item pointers more tightly.
This commit is contained in:
56
src/backend/access/gin/ginpostinglist.c
Normal file
56
src/backend/access/gin/ginpostinglist.c
Normal file
@@ -0,0 +1,56 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* ginpostinglist.c
|
||||
* routines for dealing with posting lists.
|
||||
*
|
||||
*
|
||||
* Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* src/backend/access/gin/ginpostinglist.c
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "access/gin_private.h"
|
||||
|
||||
/*
|
||||
* Merge two ordered arrays of itempointers, eliminating any duplicates.
|
||||
* Returns the number of items in the result.
|
||||
* Caller is responsible that there is enough space at *dst.
|
||||
*/
|
||||
uint32
|
||||
ginMergeItemPointers(ItemPointerData *dst,
|
||||
ItemPointerData *a, uint32 na,
|
||||
ItemPointerData *b, uint32 nb)
|
||||
{
|
||||
ItemPointerData *dptr = dst;
|
||||
ItemPointerData *aptr = a,
|
||||
*bptr = b;
|
||||
|
||||
while (aptr - a < na && bptr - b < nb)
|
||||
{
|
||||
int cmp = ginCompareItemPointers(aptr, bptr);
|
||||
|
||||
if (cmp > 0)
|
||||
*dptr++ = *bptr++;
|
||||
else if (cmp == 0)
|
||||
{
|
||||
/* we want only one copy of the identical items */
|
||||
*dptr++ = *bptr++;
|
||||
aptr++;
|
||||
}
|
||||
else
|
||||
*dptr++ = *aptr++;
|
||||
}
|
||||
|
||||
while (aptr - a < na)
|
||||
*dptr++ = *aptr++;
|
||||
|
||||
while (bptr - b < nb)
|
||||
*dptr++ = *bptr++;
|
||||
|
||||
return dptr - dst;
|
||||
}
|
Reference in New Issue
Block a user