* Fill BloomState structure for particular index. */
| 158 | * Fill BloomState structure for particular index. |
| 159 | */ |
| 160 | void |
| 161 | initBloomState(BloomState *state, Relation index) |
| 162 | { |
| 163 | int i; |
| 164 | |
| 165 | state->nColumns = index->rd_att->natts; |
| 166 | |
| 167 | /* Initialize hash function for each attribute */ |
| 168 | for (i = 0; i < index->rd_att->natts; i++) |
| 169 | { |
| 170 | fmgr_info_copy(&(state->hashFn[i]), |
| 171 | index_getprocinfo(index, i + 1, BLOOM_HASH_PROC), |
| 172 | CurrentMemoryContext); |
| 173 | state->collations[i] = index->rd_indcollation[i]; |
| 174 | } |
| 175 | |
| 176 | /* Initialize amcache if needed with options from metapage */ |
| 177 | if (!index->rd_amcache) |
| 178 | { |
| 179 | Buffer buffer; |
| 180 | Page page; |
| 181 | BloomMetaPageData *meta; |
| 182 | BloomOptions *opts; |
| 183 | |
| 184 | opts = MemoryContextAlloc(index->rd_indexcxt, sizeof(BloomOptions)); |
| 185 | |
| 186 | buffer = ReadBuffer(index, BLOOM_METAPAGE_BLKNO); |
| 187 | LockBuffer(buffer, BUFFER_LOCK_SHARE); |
| 188 | |
| 189 | page = BufferGetPage(buffer); |
| 190 | |
| 191 | if (!BloomPageIsMeta(page)) |
| 192 | elog(ERROR, "Relation is not a bloom index"); |
| 193 | meta = BloomPageGetMeta(BufferGetPage(buffer)); |
| 194 | |
| 195 | if (meta->magickNumber != BLOOM_MAGICK_NUMBER) |
| 196 | elog(ERROR, "Relation is not a bloom index"); |
| 197 | |
| 198 | *opts = meta->opts; |
| 199 | |
| 200 | UnlockReleaseBuffer(buffer); |
| 201 | |
| 202 | index->rd_amcache = (void *) opts; |
| 203 | } |
| 204 | |
| 205 | memcpy(&state->opts, index->rd_amcache, sizeof(state->opts)); |
| 206 | state->sizeOfBloomTuple = BLOOMTUPLEHDRSZ + |
| 207 | sizeof(BloomSignatureWord) * state->opts.bloomLength; |
| 208 | } |
| 209 | |
| 210 | /* |
| 211 | * Random generator copied from FreeBSD. Using own random generator here for |
no test coverage detected