* Insert new tuple to the bloom index. */
| 196 | * Insert new tuple to the bloom index. |
| 197 | */ |
| 198 | bool |
| 199 | blinsert(Relation index, Datum *values, bool *isnull, |
| 200 | ItemPointer ht_ctid, Relation heapRel, |
| 201 | IndexUniqueCheck checkUnique, |
| 202 | bool indexUnchanged, |
| 203 | IndexInfo *indexInfo) |
| 204 | { |
| 205 | BloomState blstate; |
| 206 | BloomTuple *itup; |
| 207 | MemoryContext oldCtx; |
| 208 | MemoryContext insertCtx; |
| 209 | BloomMetaPageData *metaData; |
| 210 | Buffer buffer, |
| 211 | metaBuffer; |
| 212 | Page page, |
| 213 | metaPage; |
| 214 | BlockNumber blkno = InvalidBlockNumber; |
| 215 | OffsetNumber nStart; |
| 216 | GenericXLogState *state; |
| 217 | |
| 218 | insertCtx = AllocSetContextCreate(CurrentMemoryContext, |
| 219 | "Bloom insert temporary context", |
| 220 | ALLOCSET_DEFAULT_SIZES); |
| 221 | |
| 222 | oldCtx = MemoryContextSwitchTo(insertCtx); |
| 223 | |
| 224 | initBloomState(&blstate, index); |
| 225 | itup = BloomFormTuple(&blstate, ht_ctid, values, isnull); |
| 226 | |
| 227 | /* |
| 228 | * At first, try to insert new tuple to the first page in notFullPage |
| 229 | * array. If successful, we don't need to modify the meta page. |
| 230 | */ |
| 231 | metaBuffer = ReadBuffer(index, BLOOM_METAPAGE_BLKNO); |
| 232 | LockBuffer(metaBuffer, BUFFER_LOCK_SHARE); |
| 233 | metaData = BloomPageGetMeta(BufferGetPage(metaBuffer)); |
| 234 | |
| 235 | if (metaData->nEnd > metaData->nStart) |
| 236 | { |
| 237 | Page page; |
| 238 | |
| 239 | blkno = metaData->notFullPage[metaData->nStart]; |
| 240 | Assert(blkno != InvalidBlockNumber); |
| 241 | |
| 242 | /* Don't hold metabuffer lock while doing insert */ |
| 243 | LockBuffer(metaBuffer, BUFFER_LOCK_UNLOCK); |
| 244 | |
| 245 | buffer = ReadBuffer(index, blkno); |
| 246 | LockBuffer(buffer, BUFFER_LOCK_EXCLUSIVE); |
| 247 | |
| 248 | state = GenericXLogStart(index); |
| 249 | page = GenericXLogRegisterBuffer(state, buffer, 0); |
| 250 | |
| 251 | /* |
| 252 | * We might have found a page that was recently deleted by VACUUM. If |
| 253 | * so, we can reuse it, but we must reinitialize it. |
| 254 | */ |
| 255 | if (PageIsNew(page) || BloomPageIsDeleted(page)) |
nothing calls this directly
no test coverage detected