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

Function MarkIndexesAsValid

pg_documentdb/src/metadata/index.c:566–603  ·  view source on GitHub ↗

* MarkIndexesAsValid takes a list of index ids and marks the index metadata * entries associated with them as valid (if inserted already). * * Returns number of index metadata entries processed. */

Source from the content-addressed store, hash-verified

564 * Returns number of index metadata entries processed.
565 */
566int
567MarkIndexesAsValid(uint64 collectionId, const List *indexIdList)
568{
569 const char *cmdStr =
570 FormatSqlQuery("WITH cte AS ( UPDATE %s.collection_indexes"
571 " SET index_is_valid = true WHERE collection_id = $1"
572 " AND index_id = ANY($2) RETURNING 1) SELECT COUNT(*) FROM cte",
573 ApiCatalogSchemaName);
574
575 int argCount = 2;
576 Oid argTypes[2];
577 Datum argValues[2];
578 char argNulls[2] = { ' ', ' ' };
579
580 argTypes[0] = INT8OID;
581 argValues[0] = UInt64GetDatum(collectionId);
582
583 argTypes[1] = INT4ARRAYOID;
584 argValues[1] = PointerGetDatum(IntListGetPgIntArray(indexIdList));
585
586 bool isNull = true;
587 Datum resultDatum = RunQueryWithCommutativeWrites(cmdStr, argCount, argTypes,
588 argValues, argNulls,
589 SPI_OK_SELECT, &isNull);
590
591 if (isNull)
592 {
593 ereport(ERROR, (errmsg("unexpected error when updating index metadata "
594 "records")));
595 }
596
597 if (DatumGetInt64(resultDatum) > INT_MAX)
598 {
599 ereport(ERROR, (errmsg("found too many indexes in index metadata")));
600 }
601
602 return DatumGetInt64(resultDatum);
603}
604
605
606/*

Callers 2

ShardCollectionCoreFunction · 0.85

Calls 3

FormatSqlQueryFunction · 0.85
IntListGetPgIntArrayFunction · 0.85

Tested by

no test coverage detected