Skip to content

Commit 8f75fd1

Browse files
committed
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.
1 parent a928484 commit 8f75fd1

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

contrib/bloom/bloom.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,11 @@ typedef struct BloomMetaPageData
110110
typedef struct BloomState
111111
{
112112
FmgrInfo hashFn[INDEX_MAX_KEYS];
113-
BloomOptions *opts; /* stored in rd_amcache and defined at
114-
* creation time */
113+
BloomOptions opts; /* copy of options on index's metapage */
115114
int32 nColumns;
116115

117116
/*
118-
* sizeOfBloomTuple is index's specific, and it depends on reloptions, so
117+
* sizeOfBloomTuple is index-specific, and it depends on reloptions, so
119118
* precompute it
120119
*/
121120
Size sizeOfBloomTuple;

contrib/bloom/blscan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
9999
/* New search: have to calculate search signature */
100100
ScanKey skey = scan->keyData;
101101

102-
so->sign = palloc0(sizeof(SignType) * so->state.opts->bloomLength);
102+
so->sign = palloc0(sizeof(SignType) * so->state.opts.bloomLength);
103103

104104
for (i = 0; i < scan->numberOfKeys; i++)
105105
{
@@ -151,7 +151,7 @@ blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
151151
bool res = true;
152152

153153
/* Check index signature with scan signature */
154-
for (i = 0; i < so->state.opts->bloomLength; i++)
154+
for (i = 0; i < so->state.opts.bloomLength; i++)
155155
{
156156
if ((itup->sign[i] & so->sign[i]) != so->sign[i])
157157
{

contrib/bloom/blutils.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ initBloomState(BloomState *state, Relation index)
155155
index->rd_amcache = (void *) opts;
156156
}
157157

158-
state->opts = (BloomOptions *) index->rd_amcache;
158+
memcpy(&state->opts, index->rd_amcache, sizeof(state->opts));
159159
state->sizeOfBloomTuple = BLOOMTUPLEHDRSZ +
160-
sizeof(SignType) * state->opts->bloomLength;
160+
sizeof(SignType) * state->opts.bloomLength;
161161
}
162162

163163
/*
@@ -228,10 +228,10 @@ signValue(BloomState *state, SignType *sign, Datum value, int attno)
228228
hashVal = DatumGetInt32(FunctionCall1(&state->hashFn[attno], value));
229229
mySrand(hashVal ^ myRand());
230230

231-
for (j = 0; j < state->opts->bitSize[attno]; j++)
231+
for (j = 0; j < state->opts.bitSize[attno]; j++)
232232
{
233233
/* prevent mutiple evaluation */
234-
nBit = myRand() % (state->opts->bloomLength * BITSIGNTYPE);
234+
nBit = myRand() % (state->opts.bloomLength * BITSIGNTYPE);
235235
SETBIT(sign, nBit);
236236
}
237237
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy