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

Function RecordCollectionIndex

pg_documentdb/src/metadata/index.c:520–557  ·  view source on GitHub ↗

* RecordCollectionIndex inserts a record into ApiCatalogSchemaName.collection_indexes * for given index using SPI and returns the index_id assigned to that index. */

Source from the content-addressed store, hash-verified

518 * for given index using SPI and returns the index_id assigned to that index.
519 */
520int
521RecordCollectionIndex(uint64 collectionId, const IndexSpec *indexSpec,
522 bool isKnownValid)
523{
524 const char *cmdStr = FormatSqlQuery("INSERT INTO %s.collection_indexes "
525 "(collection_id, index_spec, index_is_valid) "
526 "VALUES ($1, $2, $3) RETURNING index_id",
527 ApiCatalogSchemaName);
528
529 int argCount = 3;
530 Oid argTypes[3];
531 Datum argValues[3];
532 char argNulls[3] = { ' ', ' ', ' ' };
533
534 argTypes[0] = INT8OID;
535 argValues[0] = UInt64GetDatum(collectionId);
536
537 argTypes[1] = IndexSpecTypeId();
538 argValues[1] = IndexSpecGetDatum(CopyIndexSpec(indexSpec));
539
540 argTypes[2] = BOOLOID;
541 argValues[2] = BoolGetDatum(isKnownValid);
542
543 bool isNull = true;
544 Datum resultDatum = RunQueryWithCommutativeWrites(cmdStr, argCount, argTypes,
545 argValues, argNulls,
546 SPI_OK_INSERT_RETURNING,
547 &isNull);
548
549 if (isNull)
550 {
551 /* not expecting this to happen but .. */
552 ereport(ERROR, (errmsg("unexpected error when inserting record into "
553 "index metadata")));
554 }
555
556 return DatumGetInt32(resultDatum);
557}
558
559
560/*

Callers 4

command_record_id_indexFunction · 0.85

Calls 5

FormatSqlQueryFunction · 0.85
IndexSpecTypeIdFunction · 0.85
IndexSpecGetDatumFunction · 0.85
CopyIndexSpecFunction · 0.85

Tested by

no test coverage detected