diff options
author | Louis Williams <louis.williams@mongodb.com> | 2021-06-01 13:37:26 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-23 14:30:53 +0000 |
commit | ae2da27652e552f101559466d165b82a3c122d71 (patch) | |
tree | c65f28342818682eb3d5cb7a24fcc52d1b54c6e1 | |
parent | fbdfaa2530248b18b4327527f08d83eb283f67a2 (diff) | |
download | mongo-ae2da27652e552f101559466d165b82a3c122d71.tar.gz |
SERVER-56509 Wrap unique index insertion _keyExists call in a WT cursor reconfigure
This improves, but does not entirely fix a performance regression with
inserts and updates on unique indexes
(cherry picked from commit c5ac2eb1ea145693e1c6b974e88a2cfc18780134)
(cherry picked from commit 297e2977ef3e394e02d61aedc954c9aaadc37e73)
-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( |