MCPcopy Create free account
hub / github.com/documentdb/documentdb / GetExtendedIndexCreationCmds

Function GetExtendedIndexCreationCmds

pg_documentdb/src/sharding/sharding.c:1255–1339  ·  view source on GitHub ↗

* GetExtendedIndexCreationCmds retrieves SQL creation commands for all extended indexes * (both existing and in-progress) on a collection. * * Returns a List of char* strings, each containing a SQL CREATE INDEX command. */

Source from the content-addressed store, hash-verified

1253 * Returns a List of char* strings, each containing a SQL CREATE INDEX command.
1254 */
1255static List *
1256GetExtendedIndexCreationCmds(MongoCollection *collection)
1257{
1258 List *existingExtendedIndexesCmds = NIL;
1259
1260 /* Fetch existing extended indexes on the collection to be recreated later */
1261 Relation collectionRelation = RelationIdGetRelation(collection->relationId);
1262 List *indexIdList = RelationGetIndexList(collectionRelation);
1263 RelationClose(collectionRelation);
1264
1265 ListCell *indexId;
1266 foreach(indexId, indexIdList)
1267 {
1268 Oid indexOid = lfirst_oid(indexId);
1269 Relation indexRelation = RelationIdGetRelation(indexOid);
1270
1271 /* skip regular indexes */
1272 if (!IsExtendedIndexAm(indexRelation->rd_rel->relam))
1273 {
1274 /* skip non-extended indexes */
1275 RelationClose(indexRelation);
1276 continue;
1277 }
1278
1279 char *indexName = get_rel_name(indexOid);
1280 char *indexDefString = pg_get_indexdef_string(indexOid);
1281
1282 /* Skip the collection_pk_<id> index, we will create it separately */
1283 if (strncmp(indexName, "collection_pk_", strlen("collection_pk_")) == 0)
1284 {
1285 ereport(DEBUG1, (errmsg(
1286 "Skipping primary key index: %s, Oid: %u \ndefinition: %s",
1287 indexName, indexOid, indexDefString)));
1288 RelationClose(indexRelation);
1289 continue;
1290 }
1291
1292 ereport(DEBUG1, (errmsg(
1293 "Found existing extended index: %s, Oid: %u \ndefinition: %s",
1294 indexName, indexOid, indexDefString)));
1295 existingExtendedIndexesCmds = lappend(existingExtendedIndexesCmds,
1296 indexDefString);
1297 RelationClose(indexRelation);
1298 }
1299
1300 /* Fetch in-progress extended indexes from the index_queue. */
1301 List *inProgressIndexRequests = GetInProgressRequestFromIndexQueue(
1302 collection->collectionId, CurrentMemoryContext);
1303
1304 ListCell *requestCell;
1305 foreach(requestCell, inProgressIndexRequests)
1306 {
1307 IndexCmdRequest *request = (IndexCmdRequest *) lfirst(requestCell);
1308
1309 /* Extract the AM name from the CREATE INDEX command */
1310 char *amName = ExtractAmNameFromCreateIndexCmd(request->cmd);
1311 if (amName == NULL)
1312 {

Callers 1

ShardCollectionCoreFunction · 0.85

Calls 5

IsExtendedIndexAmFunction · 0.85
IsExtendedIndexAmByNameFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected