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

Function command_insert_worker

pg_documentdb/src/commands/insert.c:1243–1287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1241
1242
1243Datum
1244command_insert_worker(PG_FUNCTION_ARGS)
1245{
1246 uint64 collectionId = PG_GETARG_INT64(0);
1247 int64 shardKeyValue = PG_GETARG_INT64(1);
1248 Oid shardOid = PG_GETARG_OID(2);
1249
1250 pgbson *insertInternalSpec = PG_GETARG_PGBSON_PACKED(3);
1251 text *transactionId = PG_GETARG_TEXT_P(5);
1252
1253 if (shardOid == InvalidOid)
1254 {
1255 /* The planner is expected to replace this */
1256 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1257 errmsg("Explicit shardOid must be set - this is a server bug"),
1258 errdetail_log(
1259 "Explicit shardOid must be set - this is a server bug")));
1260 }
1261
1262 ThrowIfServerOrTransactionReadOnly();
1263 AllowNestedDistributionInCurrentTransaction();
1264 pgbsonelement element = { 0 };
1265 PgbsonToSinglePgbsonElement(insertInternalSpec, &element);
1266
1267 if (strcmp(element.path, "insertOne") != 0 ||
1268 element.bsonValue.value_type != BSON_TYPE_DOCUMENT)
1269 {
1270 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1271 errmsg(
1272 "Only insertOne with a single document on the worker is supported currently")));
1273 }
1274
1275 const char *localShardTable = NULL;
1276 if (UseLocalExecutionShardQueries)
1277 {
1278 localShardTable = get_rel_name(shardOid);
1279 }
1280
1281 pgbson *document = PgbsonInitFromDocumentBsonValue(&element.bsonValue);
1282 pgbson *objectId = PgbsonGetDocumentId(document);
1283 InsertOneWithTransactionCore(collectionId, localShardTable, shardKeyValue,
1284 transactionId, objectId,
1285 document);
1286 PG_RETURN_POINTER(PgbsonInitEmpty());
1287}
1288
1289
1290/*

Callers

nothing calls this directly

Tested by

no test coverage detected