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

Function CollectionIdGetIndexCount

pg_documentdb/src/metadata/index.c:816–839  ·  view source on GitHub ↗

* CollectionIdGetIndexCount returns number of indexes that collection with * collectionId has. */

Source from the content-addressed store, hash-verified

814 * collectionId has.
815 */
816int
817CollectionIdGetIndexCount(uint64 collectionId)
818{
819 StringInfo cmdStr = makeStringInfo();
820 appendStringInfo(cmdStr,
821 "SELECT COUNT(*) "
822 "FROM %s.collection_indexes "
823 "WHERE collection_id = " UINT64_FORMAT
824 " AND (index_is_valid OR %s.index_build_is_in_progress(index_id))",
825 ApiCatalogSchemaName, collectionId, ApiInternalSchemaName);
826
827 bool isNull = true;
828 bool readOnly = true;
829 Datum resultDatum = ExtensionExecuteQueryViaSPI(cmdStr->data, readOnly,
830 SPI_OK_SELECT, &isNull);
831 Assert(!isNull);
832
833 if (DatumGetInt64(resultDatum) > INT_MAX)
834 {
835 ereport(ERROR, (errmsg("found too many indexes in index metadata")));
836 }
837
838 return DatumGetInt64(resultDatum);
839}
840
841
842/*

Callers 5

reindex_concurrentlyFunction · 0.85

Calls 1

Tested by

no test coverage detected