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

Function command_delete

pg_documentdb/src/commands/delete.c:161–269  ·  view source on GitHub ↗

* command_delete handles a single delete on a collection. */

Source from the content-addressed store, hash-verified

159 * command_delete handles a single delete on a collection.
160 */
161Datum
162command_delete(PG_FUNCTION_ARGS)
163{
164 if (PG_ARGISNULL(1))
165 {
166 ereport(ERROR, (errmsg("delete document cannot be NULL")));
167 }
168
169 Datum databaseNameDatum = PG_ARGISNULL(0) ? (Datum) 0 : PG_GETARG_DATUM(0);
170 pgbson *deleteSpec = PG_GETARG_PGBSON(1);
171
172 pgbsonsequence *deleteDocs = PG_GETARG_MAYBE_NULL_PGBSON_SEQUENCE(2);
173
174 text *transactionId = NULL;
175 if (!PG_ARGISNULL(3))
176 {
177 transactionId = PG_GETARG_TEXT_P(3);
178 }
179
180 ReportFeatureUsage(FEATURE_COMMAND_DELETE);
181
182 /* fetch TupleDesc for return value, not interested in resultTypeId */
183 Oid *resultTypeId = NULL;
184 TupleDesc resultTupDesc;
185 TypeFuncClass resultTypeClass =
186 get_call_result_type(fcinfo, resultTypeId, &resultTupDesc);
187
188 if (resultTypeClass != TYPEFUNC_COMPOSITE)
189 {
190 ereport(ERROR, (errmsg("return type must be a row type")));
191 }
192
193 ThrowIfServerOrTransactionReadOnly();
194
195 bson_iter_t deleteCommandIter;
196 PgbsonInitIterator(deleteSpec, &deleteCommandIter);
197
198 /*
199 * We first validate delete command BSON and build a specification.
200 */
201 BatchDeletionSpec *batchSpec = BuildBatchDeletionSpec(&deleteCommandIter, deleteDocs,
202 &databaseNameDatum);
203
204 pgbson *batchResponse;
205
206 Datum collectionNameDatum = CStringGetTextDatum(batchSpec->collectionName);
207 MongoCollection *collection =
208 GetMongoCollectionByNameDatum(databaseNameDatum, collectionNameDatum,
209 RowExclusiveLock);
210 if (collection != NULL)
211 {
212 Oid shardOid = TryGetCollectionShardTable(collection, NoLock);
213 if (shardOid == InvalidOid)
214 {
215 /* Shard not valid on this node anymore (due to shard moves etc) */
216 collection->shardTableName[0] = '\0';
217 }
218

Callers

nothing calls this directly

Tested by

no test coverage detected