diff options
-rw-r--r-- | src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp index f39007f4970..5e704c8fe46 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp @@ -1640,7 +1640,12 @@ Status WiredTigerIndexUnique::_insertTimestampSafe(OperationContext* opCtx, invariantWTOK(ret); // Second phase looks up for existence of key to avoid insertion of duplicate key - if (_keyExists(opCtx, c, keyString.getBuffer(), sizeWithoutRecordId)) { + // The usage of 'prefix_key=true' enables an optimization that allows this search to return + // more quickly. See SERVER-56509. + c->reconfigure(c, "prefix_key=true"); + ON_BLOCK_EXIT([c] { c->reconfigure(c, "prefix_key=false"); }); + auto keyExists = _keyExists(opCtx, c, keyString.getBuffer(), sizeWithoutRecordId); + if (keyExists) { auto key = KeyString::toBson( keyString.getBuffer(), sizeWithoutRecordId, _ordering, keyString.getTypeBits()); return buildDupKeyErrorStatus( |