* updatesetbit() -- update a set bit in a bitmap. * * This function finds the bit in a given bitmap vector whose bit location is * equal to tidnum, and changes this bit to 1. * * If this bit is already 1, then we are done. Otherwise, there are * two possibilities: * (1) This bit appears in a literal word. In this case, we simply change * it to 1. * (2) This bit appears in a fill word
| 141 | * these extra words. |
| 142 | */ |
| 143 | static void |
| 144 | updatesetbit(Relation rel, Buffer lovBuffer, OffsetNumber lovOffset, |
| 145 | uint64 tidnum, bool use_wal) |
| 146 | { |
| 147 | Page lovPage; |
| 148 | BMLOVItem lovItem; |
| 149 | |
| 150 | uint64 tidLocation; |
| 151 | uint16 insertingPos; |
| 152 | |
| 153 | uint64 firstTidNumber = 1; |
| 154 | Buffer bitmapBuffer = InvalidBuffer; |
| 155 | |
| 156 | lovPage = BufferGetPage(lovBuffer); |
| 157 | lovItem = (BMLOVItem) PageGetItem(lovPage, |
| 158 | PageGetItemId(lovPage, lovOffset)); |
| 159 | |
| 160 | /* Calculate the tid location in the last bitmap page. */ |
| 161 | tidLocation = lovItem->bm_last_tid_location; |
| 162 | if (BM_LAST_COMPWORD_IS_FILL(lovItem)) |
| 163 | tidLocation -= (FILL_LENGTH(lovItem->bm_last_compword) * |
| 164 | BM_HRL_WORD_SIZE); |
| 165 | else |
| 166 | tidLocation -= BM_HRL_WORD_SIZE; |
| 167 | |
| 168 | /* |
| 169 | * If tidnum is in either bm_last_compword or bm_last_word, |
| 170 | * and this does not generate any new words, we simply |
| 171 | * need to update the lov item. |
| 172 | */ |
| 173 | if ((tidnum > lovItem->bm_last_tid_location) || |
| 174 | ((tidnum > tidLocation) && |
| 175 | ((lovItem->lov_words_header == 0) || |
| 176 | (FILL_LENGTH(lovItem->bm_last_compword) == 1)))) |
| 177 | { |
| 178 | START_CRIT_SECTION(); |
| 179 | |
| 180 | MarkBufferDirty(lovBuffer); |
| 181 | |
| 182 | if (tidnum > lovItem->bm_last_tid_location) /* bm_last_word */ |
| 183 | { |
| 184 | insertingPos = (tidnum-1)%BM_HRL_WORD_SIZE; |
| 185 | lovItem->bm_last_word |= (((BM_HRL_WORD)1)<<insertingPos); |
| 186 | |
| 187 | if (Debug_bitmap_print_insert) |
| 188 | elog(LOG, "Bitmap Insert: updated a set bit in lovItem->bm_last_word" |
| 189 | " pos %d" |
| 190 | ", lovBlock=%d, lovOffset=%d" |
| 191 | ", tidnum=" INT64_FORMAT, |
| 192 | insertingPos, |
| 193 | BufferGetBlockNumber(lovBuffer), |
| 194 | lovOffset, |
| 195 | tidnum); |
| 196 | } |
| 197 | else /* bm_last_compword */ |
| 198 | { |
| 199 | if (BM_LAST_COMPWORD_IS_FILL(lovItem)) |
| 200 | { |
no test coverage detected