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

Function insertsetbit

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

* insertsetbit() -- insert a given set bit into a bitmap * specified by lovBlock and lovOffset. */

Source from the content-addressed store, hash-verified

2124 * specified by lovBlock and lovOffset.
2125 */
2126static void
2127insertsetbit(Relation rel, BlockNumber lovBlock, OffsetNumber lovOffset,
2128 uint64 tidnum, BMTIDBuffer *buf, bool use_wal)
2129{
2130 Buffer lovBuffer;
2131 Page lovPage;
2132 BMLOVItem lovItem;
2133
2134 lovBuffer = _bitmap_getbuf(rel, lovBlock, BM_WRITE);
2135 lovPage = BufferGetPage(lovBuffer);
2136 lovItem = (BMLOVItem) PageGetItem(lovPage,
2137 PageGetItemId(lovPage, lovOffset));
2138
2139 buf->last_compword = lovItem->bm_last_compword;
2140 buf->last_word = lovItem->bm_last_word;
2141 buf->is_last_compword_fill = (lovItem->lov_words_header >= 2);
2142 buf->last_tid = lovItem->bm_last_setbit;
2143 MemSet(buf->hwords, 0, BM_NUM_OF_HEADER_WORDS * sizeof(BM_HRL_WORD));
2144 if (buf->cwords)
2145 {
2146 MemSet(buf->cwords, 0,
2147 buf->num_cwords * sizeof(BM_HRL_WORD));
2148 }
2149 if (buf->last_tids)
2150 MemSet(buf->last_tids, 0,
2151 buf->num_cwords * sizeof(uint64));
2152 buf->curword = 0;
2153
2154 /*
2155 * Usually, tidnum is greater than lovItem->bm_last_setbit.
2156 * However, if this is not the case, this should be called while
2157 * doing 'vacuum full' or doing insertion after 'vacuum'. In this
2158 * case, we try to update this bit in the corresponding bitmap
2159 * vector.
2160 */
2161 if (tidnum <= lovItem->bm_last_setbit)
2162 {
2163 /*
2164 * Scan through the bitmap vector, and update the bit in
2165 * tidnum.
2166 */
2167 updatesetbit(rel, lovBuffer, lovOffset, tidnum, use_wal);
2168
2169 _bitmap_relbuf(lovBuffer);
2170 return;
2171 }
2172
2173 /*
2174 * To insert this new set bit, we also need to add all zeros between
2175 * this set bit and last set bit. We construct all new words here.
2176 */
2177 buf_add_tid_with_fill(rel, buf, lovBuffer, lovOffset, tidnum, use_wal);
2178
2179 /*
2180 * If there are only updates to the last bitmap complete word and
2181 * last bitmp word, we simply needs to update the lov buffer.
2182 */
2183 if (buf->num_cwords == 0)

Callers 1

inserttupleFunction · 0.85

Calls 7

_bitmap_getbufFunction · 0.85
updatesetbitFunction · 0.85
_bitmap_relbufFunction · 0.85
buf_add_tid_with_fillFunction · 0.85
MarkBufferDirtyFunction · 0.85

Tested by

no test coverage detected