* ProcessDeletion processes a single deletion operation defined in * deletionSpec on the given collection. */
| 705 | * deletionSpec on the given collection. |
| 706 | */ |
| 707 | static uint64 |
| 708 | ProcessDeletion(MongoCollection *collection, DeletionSpec *deletionSpec, |
| 709 | bool forceInlineWrites, text *transactionId) |
| 710 | { |
| 711 | if (deletionSpec->deleteOneParams.returnDeletedDocument) |
| 712 | { |
| 713 | ereport(ERROR, (errmsg("cannot return deleted document via " |
| 714 | "regular delete"))); |
| 715 | } |
| 716 | |
| 717 | pgbson *query = PgbsonInitFromDocumentBsonValue(deletionSpec->deleteOneParams.query); |
| 718 | |
| 719 | /* determine whether query filters by a single shard key value */ |
| 720 | int64 shardKeyHash = 0; |
| 721 | |
| 722 | /* if the collection is sharded, check whether we can use a single hash value */ |
| 723 | bool isShardKeyValueCollationAware = false; |
| 724 | bool hasShardKeyValueFilter = |
| 725 | ComputeShardKeyHashForQuery(collection->shardKey, collection->collectionId, query, |
| 726 | &shardKeyHash, &isShardKeyValueCollationAware); |
| 727 | |
| 728 | /* determine whether query filters by a single object ID */ |
| 729 | bson_iter_t queryDocIter; |
| 730 | PgbsonInitIterator(query, &queryDocIter); |
| 731 | |
| 732 | uint64_t result = 0; |
| 733 | const char *collationString = deletionSpec->deleteOneParams.collationString; |
| 734 | bool applyCollationToShardKeyValue = IsCollationApplicable(collationString) && |
| 735 | isShardKeyValueCollationAware; |
| 736 | if (deletionSpec->limit == 0) |
| 737 | { |
| 738 | if (applyCollationToShardKeyValue) |
| 739 | { |
| 740 | /* if shard key value is collation sensitive, we distribute the query */ |
| 741 | /* by omitting the shard key value filter */ |
| 742 | hasShardKeyValueFilter = false; |
| 743 | } |
| 744 | |
| 745 | /* |
| 746 | * Delete as many document as match the query. This is not a retryable |
| 747 | * operation, so we ignore transactionId. |
| 748 | */ |
| 749 | result = DeleteAllMatchingDocuments(collection, query, |
| 750 | deletionSpec->deleteOneParams.variableSpec, |
| 751 | collationString, hasShardKeyValueFilter, |
| 752 | shardKeyHash); |
| 753 | pfree(query); |
| 754 | return result; |
| 755 | } |
| 756 | |
| 757 | bson_value_t idFromQueryDocument = { 0 }; |
| 758 | bool errorOnConflict = false; |
| 759 | bool queryHasNonIdFilters = false; |
| 760 | bool isIdFilterCollationAware = false; |
| 761 | bool hasObjectIdFilter = |
| 762 | TraverseQueryDocumentAndGetId(&queryDocIter, &idFromQueryDocument, |
| 763 | errorOnConflict, &queryHasNonIdFilters, |
| 764 | &isIdFilterCollationAware); |
no test coverage detected