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

Function MakeIndexSpecForBuiltinIdIndex

pg_documentdb/src/metadata/index.c:1228–1257  ·  view source on GitHub ↗

* MakeIndexSpecForBuiltinIdIndex returns an IndexSpec for a built-in _id index. */

Source from the content-addressed store, hash-verified

1226 * MakeIndexSpecForBuiltinIdIndex returns an IndexSpec for a built-in _id index.
1227 */
1228IndexSpec
1229MakeIndexSpecForBuiltinIdIndex(void)
1230{
1231 pgbson_writer indexKeyDocumentWriter;
1232 PgbsonWriterInit(&indexKeyDocumentWriter);
1233 int idIndexOrdering = 1;
1234 PgbsonWriterAppendInt32(&indexKeyDocumentWriter, ID_FIELD_KEY,
1235 strlen(ID_FIELD_KEY), idIndexOrdering);
1236
1237 IndexSpec idIndexSpec = {
1238 .indexName = ID_INDEX_NAME,
1239 .indexVersion = 2,
1240 .indexKeyDocument = PgbsonWriterGetPgbson(&indexKeyDocumentWriter),
1241 .indexPFEDocument = NULL,
1242 .indexWPDocument = NULL,
1243 .indexSparse = BoolIndexOption_Undefined,
1244
1245 /*
1246 * Even though the _id index is unique, Mongo (and we) report it as
1247 * "non unique". This is especially true in Sharded collections where
1248 * it's only unique by shard key.
1249 */
1250 .indexUnique = BoolIndexOption_Undefined,
1251 .indexExpireAfterSeconds = NULL,
1252 .cosmosSearchOptions = NULL,
1253 .indexOptions = NULL
1254 };
1255
1256 return idIndexSpec;
1257}
1258
1259
1260/*

Calls 3

PgbsonWriterInitFunction · 0.85
PgbsonWriterAppendInt32Function · 0.85
PgbsonWriterGetPgbsonFunction · 0.85

Tested by

no test coverage detected