MCPcopy Create free account
hub / github.com/apache/cloudberry / _bitmap_init

Function _bitmap_init

src/backend/access/bitmap/bitmappages.c:364–453  ·  view source on GitHub ↗

* _bitmap_init() -- initialize the bitmap index. * * Create the meta page, a new heap which stores the distinct values for * the attributes to be indexed, a btree index on this new heap for searching * those distinct values, and the first LOV page. * * for_empty: true means build for '_init' file. * Create bitmap index for a 'unlogged' table will call bmbuildempty(), which * initialize the

Source from the content-addressed store, hash-verified

362 * new heap and its index from meta page through GetBitmapIndexAuxOids().
363 */
364void
365_bitmap_init(Relation indexrel, bool use_wal, bool for_empty)
366{
367 BMMetaPage metapage;
368 Buffer metabuf;
369 Page page;
370 Buffer buf;
371 BMLOVItem lovItem;
372 OffsetNumber newOffset;
373 Page currLovPage;
374 OffsetNumber o;
375 Oid lovHeapOid;
376 Oid lovIndexOid;
377 ForkNumber fork;
378
379 fork = for_empty ? INIT_FORKNUM : MAIN_FORKNUM;
380
381 /* sanity check */
382 if (RelationGetNumberOfBlocksInFork(indexrel, fork) != 0)
383 ereport(ERROR,
384 (errcode(ERRCODE_INDEX_CORRUPTED),
385 errmsg("cannot initialize non-empty bitmap index \"%s\"",
386 RelationGetRelationName(indexrel))));
387
388 /* create the metapage */
389 metabuf = ReadBufferExtended(indexrel, fork, P_NEW, RBM_NORMAL, NULL);
390 LockBuffer(metabuf, BUFFER_LOCK_EXCLUSIVE);
391 page = BufferGetPage(metabuf);
392 Assert(PageIsNew(page));
393
394 /* initialize the LOV metadata */
395 if (for_empty)
396 GetBitmapIndexAuxOids(indexrel, &lovHeapOid, &lovIndexOid);
397 else
398 _bitmap_create_lov_heapandindex(indexrel, &lovHeapOid, &lovIndexOid);
399
400 START_CRIT_SECTION();
401
402 MarkBufferDirty(metabuf);
403
404 /* initialize the metapage */
405 PageInit(page, BufferGetPageSize(metabuf), 0);
406 metapage = (BMMetaPage) PageGetContents(page);
407
408 metapage->bm_magic = BITMAP_MAGIC;
409 metapage->bm_version = BITMAP_VERSION;
410 metapage->bm_lov_heapId = lovHeapOid;
411 metapage->bm_lov_indexId = lovIndexOid;
412
413 if (use_wal)
414 _bitmap_log_metapage(indexrel, fork, page);
415
416 /* allocate the first LOV page. */
417 buf = ReadBufferExtended(indexrel, fork, P_NEW, RBM_NORMAL, NULL);
418 LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
419 _bitmap_init_lovpage(indexrel, buf);
420
421 MarkBufferDirty(buf);

Callers 2

bmbuildFunction · 0.85
bmbuildemptyFunction · 0.85

Calls 15

ReadBufferExtendedFunction · 0.85
LockBufferFunction · 0.85
GetBitmapIndexAuxOidsFunction · 0.85
MarkBufferDirtyFunction · 0.85
PageInitFunction · 0.85
_bitmap_log_metapageFunction · 0.85
_bitmap_init_lovpageFunction · 0.85
_bitmap_formitemFunction · 0.85
BufferGetBlockNumberFunction · 0.85
_bitmap_log_lovitemFunction · 0.85

Tested by

no test coverage detected