* GPDB: init_sequence_internal() mostly resembles upstream init_sequence(). * However, in Cloudberry we manage dispatcher and executor sequence ranges * separately. */
| 1279 | * separately. |
| 1280 | */ |
| 1281 | static void |
| 1282 | init_sequence_internal(Oid _relid, SeqTable *p_elm, Relation *p_rel, |
| 1283 | bool called_from_dispatcher) |
| 1284 | { |
| 1285 | SeqTable elm; |
| 1286 | Relation seqrel; |
| 1287 | bool found; |
| 1288 | |
| 1289 | SeqTableKey relid; |
| 1290 | relid.relid = _relid; |
| 1291 | relid.called_from_dispatcher = called_from_dispatcher; |
| 1292 | |
| 1293 | /* Find or create a hash table entry for this sequence */ |
| 1294 | if (seqhashtab == NULL) |
| 1295 | create_seq_hashtable(); |
| 1296 | |
| 1297 | elm = (SeqTable) hash_search(seqhashtab, &relid, HASH_ENTER, &found); |
| 1298 | |
| 1299 | /* |
| 1300 | * Initialize the new hash table entry if it did not exist already. |
| 1301 | * |
| 1302 | * NOTE: seqhashtab entries are stored for the life of a backend (unless |
| 1303 | * explicitly discarded with DISCARD). If the sequence itself is deleted |
| 1304 | * then the entry becomes wasted memory, but it's small enough that this |
| 1305 | * should not matter. |
| 1306 | */ |
| 1307 | if (!found) |
| 1308 | { |
| 1309 | /* relid already filled in */ |
| 1310 | elm->filenode = InvalidOid; |
| 1311 | elm->lxid = InvalidLocalTransactionId; |
| 1312 | elm->last_valid = false; |
| 1313 | elm->last = elm->cached = 0; |
| 1314 | } |
| 1315 | |
| 1316 | /* |
| 1317 | * Open the sequence relation. |
| 1318 | */ |
| 1319 | seqrel = lock_and_open_sequence(elm); |
| 1320 | |
| 1321 | if (seqrel->rd_rel->relkind != RELKIND_SEQUENCE) |
| 1322 | ereport(ERROR, |
| 1323 | (errcode(ERRCODE_WRONG_OBJECT_TYPE), |
| 1324 | errmsg("\"%s\" is not a sequence", |
| 1325 | RelationGetRelationName(seqrel)))); |
| 1326 | |
| 1327 | /* |
| 1328 | * If the sequence has been transactionally replaced since we last saw it, |
| 1329 | * discard any cached-but-unissued values. We do not touch the currval() |
| 1330 | * state, however. |
| 1331 | */ |
| 1332 | if (seqrel->rd_rel->relfilenode != elm->filenode && called_from_dispatcher) |
| 1333 | { |
| 1334 | elm->filenode = seqrel->rd_rel->relfilenode; |
| 1335 | elm->cached = elm->last; |
| 1336 | } |
| 1337 | |
| 1338 | /* Return results */ |
no test coverage detected