2016-04-01 21:42:24 +08:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* blutils.c
|
|
|
|
* Bloom index utilities.
|
|
|
|
*
|
|
|
|
* Portions Copyright (c) 2016, PostgreSQL Global Development Group
|
|
|
|
* Portions Copyright (c) 1990-1993, Regents of the University of California
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
|
|
|
* contrib/bloom/blutils.c
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/amapi.h"
|
|
|
|
#include "access/generic_xlog.h"
|
|
|
|
#include "catalog/index.h"
|
|
|
|
#include "storage/lmgr.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "storage/bufmgr.h"
|
|
|
|
#include "storage/indexfsm.h"
|
|
|
|
#include "utils/memutils.h"
|
|
|
|
#include "access/reloptions.h"
|
|
|
|
#include "storage/freespace.h"
|
|
|
|
#include "storage/indexfsm.h"
|
|
|
|
|
|
|
|
#include "bloom.h"
|
|
|
|
|
2016-06-03 22:52:36 +08:00
|
|
|
/* Signature dealing macros - note i is assumed to be of type int */
|
|
|
|
#define GETWORD(x,i) ( *( (BloomSignatureWord *)(x) + ( (i) / SIGNWORDBITS ) ) )
|
|
|
|
#define CLRBIT(x,i) GETWORD(x,i) &= ~( 0x01 << ( (i) % SIGNWORDBITS ) )
|
|
|
|
#define SETBIT(x,i) GETWORD(x,i) |= ( 0x01 << ( (i) % SIGNWORDBITS ) )
|
|
|
|
#define GETBIT(x,i) ( (GETWORD(x,i) >> ( (i) % SIGNWORDBITS )) & 0x01 )
|
2016-04-01 21:42:24 +08:00
|
|
|
|
|
|
|
PG_FUNCTION_INFO_V1(blhandler);
|
|
|
|
|
2016-06-03 22:52:36 +08:00
|
|
|
/* Kind of relation options for bloom index */
|
2016-04-01 21:42:24 +08:00
|
|
|
static relopt_kind bl_relopt_kind;
|
2016-06-03 22:52:36 +08:00
|
|
|
/* parse table for fillRelOptions */
|
|
|
|
static relopt_parse_elt bl_relopt_tab[INDEX_MAX_KEYS + 1];
|
2016-04-01 21:42:24 +08:00
|
|
|
|
2016-04-12 23:42:06 +08:00
|
|
|
static int32 myRand(void);
|
2016-04-01 21:42:24 +08:00
|
|
|
static void mySrand(uint32 seed);
|
|
|
|
|
|
|
|
/*
|
2016-06-03 22:52:36 +08:00
|
|
|
* Module initialize function: initialize info about Bloom relation options.
|
|
|
|
*
|
|
|
|
* Note: keep this in sync with makeDefaultBloomOptions().
|
2016-04-01 21:42:24 +08:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
_PG_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char buf[16];
|
|
|
|
|
|
|
|
bl_relopt_kind = add_reloption_kind();
|
|
|
|
|
2016-06-03 22:52:36 +08:00
|
|
|
/* Option for length of signature */
|
2016-04-01 21:42:24 +08:00
|
|
|
add_int_reloption(bl_relopt_kind, "length",
|
2016-06-03 22:52:36 +08:00
|
|
|
"Length of signature in bits",
|
|
|
|
DEFAULT_BLOOM_LENGTH, 1, MAX_BLOOM_LENGTH);
|
|
|
|
bl_relopt_tab[0].optname = "length";
|
|
|
|
bl_relopt_tab[0].opttype = RELOPT_TYPE_INT;
|
|
|
|
bl_relopt_tab[0].offset = offsetof(BloomOptions, bloomLength);
|
2016-04-01 21:42:24 +08:00
|
|
|
|
2016-06-03 22:52:36 +08:00
|
|
|
/* Number of bits for each possible index column: col1, col2, ... */
|
2016-04-01 21:42:24 +08:00
|
|
|
for (i = 0; i < INDEX_MAX_KEYS; i++)
|
|
|
|
{
|
2016-06-03 22:52:36 +08:00
|
|
|
snprintf(buf, sizeof(buf), "col%d", i + 1);
|
2016-04-01 21:42:24 +08:00
|
|
|
add_int_reloption(bl_relopt_kind, buf,
|
2016-06-03 22:52:36 +08:00
|
|
|
"Number of bits generated for each index column",
|
|
|
|
DEFAULT_BLOOM_BITS, 1, MAX_BLOOM_BITS);
|
|
|
|
bl_relopt_tab[i + 1].optname = MemoryContextStrdup(TopMemoryContext,
|
|
|
|
buf);
|
|
|
|
bl_relopt_tab[i + 1].opttype = RELOPT_TYPE_INT;
|
|
|
|
bl_relopt_tab[i + 1].offset = offsetof(BloomOptions, bitSize[i]);
|
2016-04-01 21:42:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-03 22:52:36 +08:00
|
|
|
/*
|
|
|
|
* Construct a default set of Bloom options.
|
|
|
|
*/
|
|
|
|
static BloomOptions *
|
|
|
|
makeDefaultBloomOptions(void)
|
|
|
|
{
|
|
|
|
BloomOptions *opts;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
opts = (BloomOptions *) palloc0(sizeof(BloomOptions));
|
|
|
|
/* Convert DEFAULT_BLOOM_LENGTH from # of bits to # of words */
|
|
|
|
opts->bloomLength = (DEFAULT_BLOOM_LENGTH + SIGNWORDBITS - 1) / SIGNWORDBITS;
|
|
|
|
for (i = 0; i < INDEX_MAX_KEYS; i++)
|
|
|
|
opts->bitSize[i] = DEFAULT_BLOOM_BITS;
|
|
|
|
SET_VARSIZE(opts, sizeof(BloomOptions));
|
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
2016-04-01 21:42:24 +08:00
|
|
|
/*
|
|
|
|
* Bloom handler function: return IndexAmRoutine with access method parameters
|
|
|
|
* and callbacks.
|
|
|
|
*/
|
|
|
|
Datum
|
|
|
|
blhandler(PG_FUNCTION_ARGS)
|
|
|
|
{
|
|
|
|
IndexAmRoutine *amroutine = makeNode(IndexAmRoutine);
|
|
|
|
|
2016-04-28 21:39:25 +08:00
|
|
|
amroutine->amstrategies = BLOOM_NSTRATEGIES;
|
|
|
|
amroutine->amsupport = BLOOM_NPROC;
|
2016-04-01 21:42:24 +08:00
|
|
|
amroutine->amcanorder = false;
|
|
|
|
amroutine->amcanorderbyop = false;
|
|
|
|
amroutine->amcanbackward = false;
|
|
|
|
amroutine->amcanunique = false;
|
|
|
|
amroutine->amcanmulticol = true;
|
|
|
|
amroutine->amoptionalkey = true;
|
|
|
|
amroutine->amsearcharray = false;
|
|
|
|
amroutine->amsearchnulls = false;
|
|
|
|
amroutine->amstorage = false;
|
|
|
|
amroutine->amclusterable = false;
|
|
|
|
amroutine->ampredlocks = false;
|
|
|
|
amroutine->amkeytype = 0;
|
|
|
|
|
|
|
|
amroutine->aminsert = blinsert;
|
|
|
|
amroutine->ambeginscan = blbeginscan;
|
|
|
|
amroutine->amgettuple = NULL;
|
|
|
|
amroutine->amgetbitmap = blgetbitmap;
|
|
|
|
amroutine->amrescan = blrescan;
|
|
|
|
amroutine->amendscan = blendscan;
|
|
|
|
amroutine->ammarkpos = NULL;
|
|
|
|
amroutine->amrestrpos = NULL;
|
|
|
|
amroutine->ambuild = blbuild;
|
|
|
|
amroutine->ambuildempty = blbuildempty;
|
|
|
|
amroutine->ambulkdelete = blbulkdelete;
|
|
|
|
amroutine->amvacuumcleanup = blvacuumcleanup;
|
|
|
|
amroutine->amcanreturn = NULL;
|
|
|
|
amroutine->amcostestimate = blcostestimate;
|
|
|
|
amroutine->amoptions = bloptions;
|
|
|
|
amroutine->amvalidate = blvalidate;
|
|
|
|
|
|
|
|
PG_RETURN_POINTER(amroutine);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fill BloomState structure for particular index.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
initBloomState(BloomState *state, Relation index)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
state->nColumns = index->rd_att->natts;
|
|
|
|
|
|
|
|
/* Initialize hash function for each attribute */
|
|
|
|
for (i = 0; i < index->rd_att->natts; i++)
|
|
|
|
{
|
|
|
|
fmgr_info_copy(&(state->hashFn[i]),
|
|
|
|
index_getprocinfo(index, i + 1, BLOOM_HASH_PROC),
|
|
|
|
CurrentMemoryContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize amcache if needed with options from metapage */
|
|
|
|
if (!index->rd_amcache)
|
|
|
|
{
|
|
|
|
Buffer buffer;
|
|
|
|
Page page;
|
|
|
|
BloomMetaPageData *meta;
|
|
|
|
BloomOptions *opts;
|
|
|
|
|
|
|
|
opts = MemoryContextAlloc(index->rd_indexcxt, sizeof(BloomOptions));
|
|
|
|
|
|
|
|
buffer = ReadBuffer(index, BLOOM_METAPAGE_BLKNO);
|
|
|
|
LockBuffer(buffer, BUFFER_LOCK_SHARE);
|
|
|
|
|
2016-04-20 21:31:19 +08:00
|
|
|
page = BufferGetPage(buffer);
|
2016-04-01 21:42:24 +08:00
|
|
|
|
|
|
|
if (!BloomPageIsMeta(page))
|
|
|
|
elog(ERROR, "Relation is not a bloom index");
|
2016-04-20 21:31:19 +08:00
|
|
|
meta = BloomPageGetMeta(BufferGetPage(buffer));
|
2016-04-01 21:42:24 +08:00
|
|
|
|
|
|
|
if (meta->magickNumber != BLOOM_MAGICK_NUMBER)
|
|
|
|
elog(ERROR, "Relation is not a bloom index");
|
|
|
|
|
|
|
|
*opts = meta->opts;
|
|
|
|
|
|
|
|
UnlockReleaseBuffer(buffer);
|
|
|
|
|
|
|
|
index->rd_amcache = (void *) opts;
|
|
|
|
}
|
|
|
|
|
2016-04-04 03:16:07 +08:00
|
|
|
memcpy(&state->opts, index->rd_amcache, sizeof(state->opts));
|
2016-04-01 21:42:24 +08:00
|
|
|
state->sizeOfBloomTuple = BLOOMTUPLEHDRSZ +
|
2016-06-03 22:52:36 +08:00
|
|
|
sizeof(BloomSignatureWord) * state->opts.bloomLength;
|
2016-04-01 21:42:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Random generator copied from FreeBSD. Using own random generator here for
|
|
|
|
* two reasons:
|
|
|
|
*
|
|
|
|
* 1) In this case random numbers are used for on-disk storage. Usage of
|
|
|
|
* PostgreSQL number generator would obstruct it from all possible changes.
|
|
|
|
* 2) Changing seed of PostgreSQL random generator would be undesirable side
|
|
|
|
* effect.
|
|
|
|
*/
|
|
|
|
static int32 next;
|
|
|
|
|
|
|
|
static int32
|
2016-04-12 23:42:06 +08:00
|
|
|
myRand(void)
|
2016-04-01 21:42:24 +08:00
|
|
|
{
|
2016-04-12 23:42:06 +08:00
|
|
|
/*----------
|
2016-04-01 21:42:24 +08:00
|
|
|
* Compute x = (7^5 * x) mod (2^31 - 1)
|
|
|
|
* without overflowing 31 bits:
|
2016-04-02 18:47:04 +08:00
|
|
|
* (2^31 - 1) = 127773 * (7^5) + 2836
|
2016-04-01 21:42:24 +08:00
|
|
|
* From "Random number generators: good ones are hard to find",
|
|
|
|
* Park and Miller, Communications of the ACM, vol. 31, no. 10,
|
|
|
|
* October 1988, p. 1195.
|
2016-04-12 23:42:06 +08:00
|
|
|
*----------
|
2016-04-01 21:42:24 +08:00
|
|
|
*/
|
|
|
|
int32 hi, lo, x;
|
|
|
|
|
|
|
|
/* Must be in [1, 0x7ffffffe] range at this point. */
|
|
|
|
hi = next / 127773;
|
|
|
|
lo = next % 127773;
|
|
|
|
x = 16807 * lo - 2836 * hi;
|
|
|
|
if (x < 0)
|
|
|
|
x += 0x7fffffff;
|
|
|
|
next = x;
|
|
|
|
/* Transform to [0, 0x7ffffffd] range. */
|
|
|
|
return (x - 1);
|
|
|
|
}
|
|
|
|
|
2016-04-03 01:59:11 +08:00
|
|
|
static void
|
2016-04-01 21:42:24 +08:00
|
|
|
mySrand(uint32 seed)
|
|
|
|
{
|
|
|
|
next = seed;
|
|
|
|
/* Transform to [1, 0x7ffffffe] range. */
|
|
|
|
next = (next % 0x7ffffffe) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add bits of given value to the signature.
|
|
|
|
*/
|
|
|
|
void
|
2016-06-03 22:52:36 +08:00
|
|
|
signValue(BloomState *state, BloomSignatureWord *sign, Datum value, int attno)
|
2016-04-01 21:42:24 +08:00
|
|
|
{
|
|
|
|
uint32 hashVal;
|
|
|
|
int nBit,
|
|
|
|
j;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* init generator with "column's" number to get "hashed" seed for new
|
|
|
|
* value. We don't want to map the same numbers from different columns
|
|
|
|
* into the same bits!
|
|
|
|
*/
|
|
|
|
mySrand(attno);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Init hash sequence to map our value into bits. the same values in
|
|
|
|
* different columns will be mapped into different bits because of step
|
|
|
|
* above
|
|
|
|
*/
|
|
|
|
hashVal = DatumGetInt32(FunctionCall1(&state->hashFn[attno], value));
|
|
|
|
mySrand(hashVal ^ myRand());
|
|
|
|
|
2016-04-04 03:16:07 +08:00
|
|
|
for (j = 0; j < state->opts.bitSize[attno]; j++)
|
2016-04-01 21:42:24 +08:00
|
|
|
{
|
2016-06-03 22:52:36 +08:00
|
|
|
/* prevent multiple evaluation in SETBIT macro */
|
|
|
|
nBit = myRand() % (state->opts.bloomLength * SIGNWORDBITS);
|
2016-04-01 21:42:24 +08:00
|
|
|
SETBIT(sign, nBit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make bloom tuple from values.
|
|
|
|
*/
|
|
|
|
BloomTuple *
|
|
|
|
BloomFormTuple(BloomState *state, ItemPointer iptr, Datum *values, bool *isnull)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
BloomTuple *res = (BloomTuple *) palloc0(state->sizeOfBloomTuple);
|
|
|
|
|
|
|
|
res->heapPtr = *iptr;
|
|
|
|
|
|
|
|
/* Blooming each column */
|
|
|
|
for (i = 0; i < state->nColumns; i++)
|
|
|
|
{
|
|
|
|
/* skip nulls */
|
|
|
|
if (isnull[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
signValue(state, res->sign, values[i], i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add new bloom tuple to the page. Returns true if new tuple was successfully
|
2016-04-04 19:55:29 +08:00
|
|
|
* added to the page. Returns false if it doesn't fit the page.
|
2016-04-01 21:42:24 +08:00
|
|
|
*/
|
|
|
|
bool
|
|
|
|
BloomPageAddItem(BloomState *state, Page page, BloomTuple *tuple)
|
|
|
|
{
|
|
|
|
BloomTuple *itup;
|
|
|
|
BloomPageOpaque opaque;
|
|
|
|
Pointer ptr;
|
|
|
|
|
|
|
|
/* Does new tuple fit the page */
|
|
|
|
if (BloomPageGetFreeSpace(state, page) < state->sizeOfBloomTuple)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Copy new tuple to the end of page */
|
|
|
|
opaque = BloomPageGetOpaque(page);
|
|
|
|
itup = BloomPageGetTuple(state, page, opaque->maxoff + 1);
|
|
|
|
memcpy((Pointer) itup, (Pointer) tuple, state->sizeOfBloomTuple);
|
|
|
|
|
|
|
|
/* Adjust maxoff and pd_lower */
|
|
|
|
opaque->maxoff++;
|
|
|
|
ptr = (Pointer) BloomPageGetTuple(state, page, opaque->maxoff + 1);
|
|
|
|
((PageHeader) page)->pd_lower = ptr - page;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new page (either by recycling, or by extending the index file)
|
|
|
|
* The returned buffer is already pinned and exclusive-locked
|
|
|
|
* Caller is responsible for initializing the page by calling BloomInitBuffer
|
|
|
|
*/
|
|
|
|
Buffer
|
|
|
|
BloomNewBuffer(Relation index)
|
|
|
|
{
|
|
|
|
Buffer buffer;
|
|
|
|
bool needLock;
|
|
|
|
|
|
|
|
/* First, try to get a page from FSM */
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
BlockNumber blkno = GetFreeIndexPage(index);
|
|
|
|
|
|
|
|
if (blkno == InvalidBlockNumber)
|
|
|
|
break;
|
|
|
|
|
|
|
|
buffer = ReadBuffer(index, blkno);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to guard against the possibility that someone else already
|
|
|
|
* recycled this page; the buffer may be locked if so.
|
|
|
|
*/
|
|
|
|
if (ConditionalLockBuffer(buffer))
|
|
|
|
{
|
2016-04-20 21:31:19 +08:00
|
|
|
Page page = BufferGetPage(buffer);
|
2016-04-01 21:42:24 +08:00
|
|
|
|
|
|
|
if (PageIsNew(page))
|
|
|
|
return buffer; /* OK to use, if never initialized */
|
|
|
|
|
|
|
|
if (BloomPageIsDeleted(page))
|
|
|
|
return buffer; /* OK to use */
|
|
|
|
|
|
|
|
LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Can't use it, so release buffer and try again */
|
|
|
|
ReleaseBuffer(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must extend the file */
|
|
|
|
needLock = !RELATION_IS_LOCAL(index);
|
|
|
|
if (needLock)
|
|
|
|
LockRelationForExtension(index, ExclusiveLock);
|
|
|
|
|
|
|
|
buffer = ReadBuffer(index, P_NEW);
|
|
|
|
LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE);
|
|
|
|
|
|
|
|
if (needLock)
|
|
|
|
UnlockRelationForExtension(index, ExclusiveLock);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-05-25 09:04:23 +08:00
|
|
|
* Initialize any page of a bloom index.
|
2016-04-01 21:42:24 +08:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
BloomInitPage(Page page, uint16 flags)
|
|
|
|
{
|
|
|
|
BloomPageOpaque opaque;
|
|
|
|
|
|
|
|
PageInit(page, BLCKSZ, sizeof(BloomPageOpaqueData));
|
|
|
|
|
|
|
|
opaque = BloomPageGetOpaque(page);
|
|
|
|
memset(opaque, 0, sizeof(BloomPageOpaqueData));
|
|
|
|
opaque->flags = flags;
|
2016-04-12 23:03:01 +08:00
|
|
|
opaque->bloom_page_id = BLOOM_PAGE_ID;
|
2016-04-01 21:42:24 +08:00
|
|
|
}
|
|
|
|
|
2016-05-25 09:04:23 +08:00
|
|
|
/*
|
|
|
|
* Fill in metapage for bloom index.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
BloomFillMetapage(Relation index, Page metaPage)
|
|
|
|
{
|
|
|
|
BloomOptions *opts;
|
|
|
|
BloomMetaPageData *metadata;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Choose the index's options. If reloptions have been assigned, use
|
2016-06-03 22:52:36 +08:00
|
|
|
* those, otherwise create default options.
|
2016-05-25 09:04:23 +08:00
|
|
|
*/
|
|
|
|
opts = (BloomOptions *) index->rd_options;
|
|
|
|
if (!opts)
|
2016-06-03 22:52:36 +08:00
|
|
|
opts = makeDefaultBloomOptions();
|
2016-05-25 09:04:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize contents of meta page, including a copy of the options,
|
|
|
|
* which are now frozen for the life of the index.
|
|
|
|
*/
|
|
|
|
BloomInitPage(metaPage, BLOOM_META);
|
|
|
|
metadata = BloomPageGetMeta(metaPage);
|
|
|
|
memset(metadata, 0, sizeof(BloomMetaPageData));
|
|
|
|
metadata->magickNumber = BLOOM_MAGICK_NUMBER;
|
|
|
|
metadata->opts = *opts;
|
|
|
|
((PageHeader) metaPage)->pd_lower += sizeof(BloomMetaPageData);
|
|
|
|
}
|
|
|
|
|
2016-04-01 21:42:24 +08:00
|
|
|
/*
|
|
|
|
* Initialize metapage for bloom index.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
BloomInitMetapage(Relation index)
|
|
|
|
{
|
|
|
|
Buffer metaBuffer;
|
2016-05-25 09:04:23 +08:00
|
|
|
Page metaPage;
|
2016-04-01 21:42:24 +08:00
|
|
|
GenericXLogState *state;
|
|
|
|
|
|
|
|
/*
|
2016-05-25 09:04:23 +08:00
|
|
|
* Make a new page; since it is first page it should be associated with
|
2016-04-01 21:42:24 +08:00
|
|
|
* block number 0 (BLOOM_METAPAGE_BLKNO).
|
|
|
|
*/
|
|
|
|
metaBuffer = BloomNewBuffer(index);
|
|
|
|
Assert(BufferGetBlockNumber(metaBuffer) == BLOOM_METAPAGE_BLKNO);
|
|
|
|
|
|
|
|
/* Initialize contents of meta page */
|
|
|
|
state = GenericXLogStart(index);
|
2016-05-25 09:04:23 +08:00
|
|
|
metaPage = GenericXLogRegisterBuffer(state, metaBuffer,
|
|
|
|
GENERIC_XLOG_FULL_IMAGE);
|
|
|
|
BloomFillMetapage(index, metaPage);
|
2016-04-01 21:42:24 +08:00
|
|
|
GenericXLogFinish(state);
|
2016-05-25 09:04:23 +08:00
|
|
|
|
2016-04-01 21:42:24 +08:00
|
|
|
UnlockReleaseBuffer(metaBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2016-05-25 09:04:23 +08:00
|
|
|
* Parse reloptions for bloom index, producing a BloomOptions struct.
|
2016-04-01 21:42:24 +08:00
|
|
|
*/
|
|
|
|
bytea *
|
|
|
|
bloptions(Datum reloptions, bool validate)
|
|
|
|
{
|
|
|
|
relopt_value *options;
|
|
|
|
int numoptions;
|
|
|
|
BloomOptions *rdopts;
|
|
|
|
|
2016-06-03 22:52:36 +08:00
|
|
|
/* Parse the user-given reloptions */
|
2016-04-01 21:42:24 +08:00
|
|
|
options = parseRelOptions(reloptions, validate, bl_relopt_kind, &numoptions);
|
|
|
|
rdopts = allocateReloptStruct(sizeof(BloomOptions), options, numoptions);
|
|
|
|
fillRelOptions((void *) rdopts, sizeof(BloomOptions), options, numoptions,
|
2016-06-03 22:52:36 +08:00
|
|
|
validate, bl_relopt_tab, lengthof(bl_relopt_tab));
|
2016-04-01 21:42:24 +08:00
|
|
|
|
2016-06-03 22:52:36 +08:00
|
|
|
/* Convert signature length from # of bits to # to words, rounding up */
|
|
|
|
rdopts->bloomLength = (rdopts->bloomLength + SIGNWORDBITS - 1) / SIGNWORDBITS;
|
2016-04-01 21:42:24 +08:00
|
|
|
|
|
|
|
return (bytea *) rdopts;
|
|
|
|
}
|