/* * 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); state->collations[i] = index->rd_indcollation[i]; } /* 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); page = BufferGetPage(buffer); if (!BloomPageIsMeta(page)) elog(ERROR, "Relation is not a bloom index"); meta = BloomPageGetMeta(BufferGetPage(buffer)); if (meta->magickNumber != BLOOM_MAGICK_NUMBER) elog(ERROR, "Relation is not a bloom index"); *opts = meta->opts; UnlockReleaseBuffer(buffer); index->rd_amcache = (void *) opts; } memcpy(&state->opts, index->rd_amcache, sizeof(state->opts)); state->sizeOfBloomTuple = BLOOMTUPLEHDRSZ + sizeof(BloomSignatureWord) * state->opts.bloomLength; }
void initBloomState(BloomState *state, Relation index) { int i; state->nColumns = index->rd_att->natts; for (i = 0; i < index->rd_att->natts; i++) { fmgr_info_copy(&(state->hashFn[i]), index_getprocinfo(index, i + 1, BLOOM_HASH_PROC), CurrentMemoryContext); } if (!index->rd_amcache) { Buffer buffer; BloomMetaPageData *meta; BloomOptions *opts; opts = MemoryContextAlloc(index->rd_indexcxt, sizeof(BloomOptions)); buffer = ReadBuffer(index, BLOOM_METAPAGE_BLKNO); LockBuffer(buffer, BUFFER_LOCK_SHARE); if (!BloomPageIsMeta(BufferGetPage(buffer))) elog(ERROR,"Relation is not a bloom index"); meta = BloomPageGetMeta(BufferGetPage(buffer)); if (meta->magickNumber != BLOOM_MAGICK_NUMBER) elog(ERROR,"Relation is not a bloom index"); *opts = meta->opts; UnlockReleaseBuffer(buffer); index->rd_amcache = (void*)opts; } state->opts = (BloomOptions*)index->rd_amcache; state->sizeOfBloomTuple = BLOOMTUPLEHDRSZ + sizeof(SignType) * state->opts->bloomLength; }