summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2022-01-11 16:58:56 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-11 17:49:13 +0000
commitf18bb1e1c2d7bedeb3c08964e6a65bcc794e2a2a (patch)
tree4b8da16edf2a5eec5adc8596386572ca47a28756 /src
parent4f0b5118a61593927dc5398b8eacf37884c84c88 (diff)
downloadmongo-f18bb1e1c2d7bedeb3c08964e6a65bcc794e2a2a.tar.gz
SERVER-61185 Use WT prefix_key search for unique index lookups
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
index d3da10b5d3c..78ef755ffb7 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp
@@ -1407,13 +1407,13 @@ bool WiredTigerIndexUnique::_keyExists(OperationContext* opCtx,
int cmp;
int ret = wiredTigerPrepareConflictRetry(opCtx, [&] { return c->search_near(c, &cmp); });
+ auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx);
+ metricsCollector.incrementOneCursorSeek();
+
if (ret == WT_NOTFOUND)
return false;
invariantWTOK(ret);
- auto& metricsCollector = ResourceConsumption::MetricsCollector::get(opCtx);
- metricsCollector.incrementOneCursorSeek();
-
if (cmp == 0)
return true;
@@ -1574,7 +1574,12 @@ StatusWith<bool> WiredTigerIndexUnique::_insert(OperationContext* opCtx,
fmt::format("WiredTigerIndexUnique::_insert: remove: {}; uri: {}", _indexName, _uri));
// 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());
auto entry = _desc->getEntry();