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

Function create_lovitem

src/backend/access/bitmap/bitmapinsert.c:1618–1728  ·  view source on GitHub ↗

* create_lovitem() -- create a new LOV item. * * Create a new LOV item and append this item into the last LOV page. * Each LOV item is associated with one distinct value for attributes * to be indexed. This function also inserts this distinct value along * with this new LOV item's block number and offsetnumber into the * auxiliary heap and its b-tree of this bitmap index. * * This function

Source from the content-addressed store, hash-verified

1616 * The caller should have an exclusive lock on metabuf.
1617 */
1618static void
1619create_lovitem(Relation rel, Buffer metabuf, uint64 tidnum,
1620 TupleDesc tupDesc, Datum *attdata, bool *nulls,
1621 Relation lovHeap, Relation lovIndex, BlockNumber *lovBlockP,
1622 OffsetNumber *lovOffsetP, bool use_wal)
1623{
1624 BMMetaPage metapage;
1625 Buffer currLovBuffer;
1626 Page currLovPage;
1627 Datum* lovDatum;
1628 bool* lovNulls;
1629 OffsetNumber itemSize;
1630 BMLOVItem lovitem;
1631 int numOfAttrs;
1632 bool is_new_lov_blkno = false;
1633
1634 numOfAttrs = tupDesc->natts;
1635
1636 /* Get the last LOV page. Meta page should be locked. */
1637 metapage = _bitmap_get_metapage_data(rel, metabuf);
1638 *lovBlockP = metapage->bm_lov_lastpage;
1639
1640 currLovBuffer = _bitmap_getbuf(rel, *lovBlockP, BM_WRITE);
1641 currLovPage = BufferGetPage(currLovBuffer);
1642
1643 lovitem = _bitmap_formitem(tidnum);
1644
1645 *lovOffsetP = OffsetNumberNext(PageGetMaxOffsetNumber(currLovPage));
1646 itemSize = sizeof(BMLOVItemData);
1647
1648 /*
1649 * If there is not enough space in the last LOV page for
1650 * a new item, create a new LOV page, and update the metapage.
1651 */
1652 if (itemSize > PageGetFreeSpace(currLovPage))
1653 {
1654 Buffer newLovBuffer;
1655
1656 /* create a new LOV page */
1657 newLovBuffer = _bitmap_getbuf(rel, P_NEW, BM_WRITE);
1658 _bitmap_init_lovpage(rel, newLovBuffer);
1659
1660 _bitmap_relbuf(currLovBuffer);
1661
1662 currLovBuffer = newLovBuffer;
1663 currLovPage = BufferGetPage(currLovBuffer);
1664
1665 is_new_lov_blkno = true;
1666 }
1667
1668 /* First create the LOV item. */
1669 START_CRIT_SECTION();
1670
1671 if (is_new_lov_blkno)
1672 {
1673 MarkBufferDirty(metabuf);
1674
1675 metapage->bm_lov_lastpage = BufferGetBlockNumber(currLovBuffer);

Callers 2

build_inserttupleFunction · 0.85
inserttupleFunction · 0.85

Calls 15

_bitmap_getbufFunction · 0.85
_bitmap_formitemFunction · 0.85
PageGetFreeSpaceFunction · 0.85
_bitmap_init_lovpageFunction · 0.85
_bitmap_relbufFunction · 0.85
MarkBufferDirtyFunction · 0.85
BufferGetBlockNumberFunction · 0.85
_bitmap_log_lovitemFunction · 0.85
Int32GetDatumFunction · 0.85
Int16GetDatumFunction · 0.85
_bitmap_insert_lovFunction · 0.85

Tested by

no test coverage detected