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

Function command_delete_worker

pg_documentdb/src/commands/delete.c:1146–1216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1144
1145
1146Datum
1147command_delete_worker(PG_FUNCTION_ARGS)
1148{
1149 uint64 collectionId = PG_GETARG_INT64(0);
1150 int64 shardKeyHash = PG_GETARG_INT64(1);
1151 Oid shardOid = PG_GETARG_OID(2);
1152
1153 pgbson *deleteInternalSpec = PG_GETARG_PGBSON_PACKED(3);
1154
1155 if (shardOid == InvalidOid)
1156 {
1157 /* The planner is expected to replace this */
1158 ereport(ERROR, (errcode(ERRCODE_DOCUMENTDB_INTERNALERROR),
1159 errmsg("Explicit shardOid must be set - this is a server bug"),
1160 errdetail_log(
1161 "Explicit shardOid must be set - this is a server bug")));
1162 }
1163
1164 pgbsonsequence *specDocuments = PG_GETARG_MAYBE_NULL_PGBSON_SEQUENCE(4);
1165 text *transactionId = PG_ARGISNULL(5) ? NULL : PG_GETARG_TEXT_PP(5);
1166
1167 ThrowIfServerOrTransactionReadOnly();
1168 AllowNestedDistributionInCurrentTransaction();
1169 pgbsonelement commandElement;
1170 PgbsonToSinglePgbsonElement(deleteInternalSpec, &commandElement);
1171
1172 pgbson *serializedResult;
1173 if (strcmp(commandElement.path, "deleteOne") == 0)
1174 {
1175 DeleteOneParams deleteOneParams = { 0 };
1176 DeserializeDeleteWorkerSpecForDeleteOne(&commandElement.bsonValue,
1177 &deleteOneParams);
1178
1179 DeleteOneResult result;
1180 memset(&result, 0, sizeof(result));
1181
1182 MongoCollection mongoCollection = { 0 };
1183 UpdateMongoCollectionUsingIds(&mongoCollection, collectionId, shardOid);
1184
1185 DeleteOneInternalCore(&mongoCollection, shardKeyHash, &deleteOneParams,
1186 transactionId,
1187 &result);
1188
1189 serializedResult = SerializeDeleteOneResult(&result);
1190 }
1191 else if (strcmp(commandElement.path, "deleteUnsharded") == 0)
1192 {
1193 BatchDeletionSpec batchDeletionSpec = { 0 };
1194 BatchDeletionResult result = { 0 };
1195
1196 DeserializeDeleteWorkerSpecForUnsharded(&commandElement.bsonValue,
1197 &batchDeletionSpec);
1198 batchDeletionSpec.deletionSequence = specDocuments;
1199
1200 MongoCollection mongoCollection = { 0 };
1201 UpdateMongoCollectionUsingIds(&mongoCollection, collectionId, InvalidOid);
1202
1203 bool forceInline = true;

Callers

nothing calls this directly

Tested by

no test coverage detected