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

Function mergewords

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

* mergewords() -- merge last two bitmap words based on the HRL compression * scheme. If these two words can not be merged, the last complete * word will be appended into the word array in the buffer. * * If the buffer is extended, this function returns the number * of bytes used. */

Source from the content-addressed store, hash-verified

1123 * of bytes used.
1124 */
1125static int16
1126mergewords(BMTIDBuffer *buf, bool lastWordFill)
1127{
1128 int16 bytes_used = 0;
1129
1130 /* the last_tid in the complete word */
1131 uint64 last_tid = buf->last_tid - buf->last_tid%BM_HRL_WORD_SIZE;
1132
1133 /*
1134 * If last_compword is LITERAL_ALL_ONE, it is not set yet.
1135 * We move last_word to it.
1136 */
1137 if (buf->last_compword == LITERAL_ALL_ONE)
1138 {
1139 buf->last_compword = buf->last_word;
1140 buf->is_last_compword_fill = lastWordFill;
1141 if (lastWordFill)
1142 last_tid = FILL_LENGTH(buf->last_word) * BM_HRL_WORD_SIZE;
1143 else
1144 last_tid = BM_HRL_WORD_SIZE;
1145
1146 buf->last_word = 0;
1147 buf->last_tid = last_tid;
1148
1149 return bytes_used;
1150 }
1151 /*
1152 * If both words are fill words, and have the same fill bit,
1153 * we increment the fill length of the last complete word by
1154 * the fill length stored in the last word.
1155 */
1156 if (buf->is_last_compword_fill && lastWordFill &&
1157 (GET_FILL_BIT(buf->last_compword) ==
1158 GET_FILL_BIT(buf->last_word)))
1159 {
1160 BM_HRL_WORD lengthMerged;
1161
1162 if (FILL_LENGTH(buf->last_compword) + FILL_LENGTH(buf->last_word) <=
1163 MAX_FILL_LENGTH)
1164 {
1165 last_tid += FILL_LENGTH(buf->last_word)*BM_HRL_WORD_SIZE;
1166 buf->last_compword += FILL_LENGTH(buf->last_word);
1167 buf->last_word = LITERAL_ALL_ZERO;
1168 buf->last_tid = last_tid;
1169
1170 return bytes_used;
1171 }
1172
1173 lengthMerged =
1174 MAX_FILL_LENGTH - FILL_LENGTH(buf->last_compword);
1175 buf->last_word -= lengthMerged;
1176 last_tid += lengthMerged * BM_HRL_WORD_SIZE;
1177 buf->last_compword += lengthMerged;
1178 }
1179
1180 /*
1181 * Here, these two words can not be merged together. We
1182 * move the last complete word to the array, and set it to be the

Callers 1

buf_add_tid_with_fillFunction · 0.85

Calls 1

buf_extendFunction · 0.85

Tested by

no test coverage detected