* insertsetbit() -- insert a given set bit into a bitmap * specified by lovBlock and lovOffset. */
| 2124 | * specified by lovBlock and lovOffset. |
| 2125 | */ |
| 2126 | static void |
| 2127 | insertsetbit(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) |
no test coverage detected