Fix contrib/bloom to not fail under CLOBBER_CACHE_ALWAYS.
The code was supposing that rd_amcache wouldn't disappear from under it during a scan; which is wrong. Copy the data out of the relcache rather than trying to reference it there.
This commit is contained in:
parent
a9284849b4
commit
8f75fd1f40
|
@ -110,12 +110,11 @@ typedef struct BloomMetaPageData
|
||||||
typedef struct BloomState
|
typedef struct BloomState
|
||||||
{
|
{
|
||||||
FmgrInfo hashFn[INDEX_MAX_KEYS];
|
FmgrInfo hashFn[INDEX_MAX_KEYS];
|
||||||
BloomOptions *opts; /* stored in rd_amcache and defined at
|
BloomOptions opts; /* copy of options on index's metapage */
|
||||||
* creation time */
|
|
||||||
int32 nColumns;
|
int32 nColumns;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* sizeOfBloomTuple is index's specific, and it depends on reloptions, so
|
* sizeOfBloomTuple is index-specific, and it depends on reloptions, so
|
||||||
* precompute it
|
* precompute it
|
||||||
*/
|
*/
|
||||||
Size sizeOfBloomTuple;
|
Size sizeOfBloomTuple;
|
||||||
|
|
|
@ -99,7 +99,7 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
|
||||||
/* New search: have to calculate search signature */
|
/* New search: have to calculate search signature */
|
||||||
ScanKey skey = scan->keyData;
|
ScanKey skey = scan->keyData;
|
||||||
|
|
||||||
so->sign = palloc0(sizeof(SignType) * so->state.opts->bloomLength);
|
so->sign = palloc0(sizeof(SignType) * so->state.opts.bloomLength);
|
||||||
|
|
||||||
for (i = 0; i < scan->numberOfKeys; i++)
|
for (i = 0; i < scan->numberOfKeys; i++)
|
||||||
{
|
{
|
||||||
|
@ -151,7 +151,7 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
|
||||||
bool res = true;
|
bool res = true;
|
||||||
|
|
||||||
/* Check index signature with scan signature */
|
/* Check index signature with scan signature */
|
||||||
for (i = 0; i < so->state.opts->bloomLength; i++)
|
for (i = 0; i < so->state.opts.bloomLength; i++)
|
||||||
{
|
{
|
||||||
if ((itup->sign[i] & so->sign[i]) != so->sign[i])
|
if ((itup->sign[i] & so->sign[i]) != so->sign[i])
|
||||||
{
|
{
|
||||||
|
|
|
@ -155,9 +155,9 @@ initBloomState(BloomState *state, Relation index)
|
||||||
index->rd_amcache = (void *) opts;
|
index->rd_amcache = (void *) opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
state->opts = (BloomOptions *) index->rd_amcache;
|
memcpy(&state->opts, index->rd_amcache, sizeof(state->opts));
|
||||||
state->sizeOfBloomTuple = BLOOMTUPLEHDRSZ +
|
state->sizeOfBloomTuple = BLOOMTUPLEHDRSZ +
|
||||||
sizeof(SignType) * state->opts->bloomLength;
|
sizeof(SignType) * state->opts.bloomLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -228,10 +228,10 @@ signValue(BloomState *state, SignType *sign, Datum value, int attno)
|
||||||
hashVal = DatumGetInt32(FunctionCall1(&state->hashFn[attno], value));
|
hashVal = DatumGetInt32(FunctionCall1(&state->hashFn[attno], value));
|
||||||
mySrand(hashVal ^ myRand());
|
mySrand(hashVal ^ myRand());
|
||||||
|
|
||||||
for (j = 0; j < state->opts->bitSize[attno]; j++)
|
for (j = 0; j < state->opts.bitSize[attno]; j++)
|
||||||
{
|
{
|
||||||
/* prevent mutiple evaluation */
|
/* prevent mutiple evaluation */
|
||||||
nBit = myRand() % (state->opts->bloomLength * BITSIGNTYPE);
|
nBit = myRand() % (state->opts.bloomLength * BITSIGNTYPE);
|
||||||
SETBIT(sign, nBit);
|
SETBIT(sign, nBit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue