summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/key_string.h
diff options
context:
space:
mode:
authorLouis Williams <louis.williams@mongodb.com>2021-11-05 15:08:40 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-11-05 16:09:45 +0000
commit7bcb659c013aaf44e1edab7b8a102a738c0bfb8c (patch)
tree89d69d8c8bc4eb13bc6523ef89cba8f64b5b6e94 /src/mongo/db/storage/key_string.h
parent43cba1cc995ffc6436493246b10146365d593b8e (diff)
downloadmongo-7bcb659c013aaf44e1edab7b8a102a738c0bfb8c.tar.gz
SERVER-54360 Support secondary unique indexes on clustered collections
Diffstat (limited to 'src/mongo/db/storage/key_string.h')
-rw-r--r--src/mongo/db/storage/key_string.h38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/mongo/db/storage/key_string.h b/src/mongo/db/storage/key_string.h
index d8db757213e..f0e1441004c 100644
--- a/src/mongo/db/storage/key_string.h
+++ b/src/mongo/db/storage/key_string.h
@@ -335,13 +335,21 @@ public:
return *this;
}
+ /**
+ * Compare with another KeyString::Value or Builder.
+ */
template <class T>
int compare(const T& other) const;
int compareWithTypeBits(const Value& other) const;
+ /**
+ * Compare with another KeyString::Value or Builder, ignoring the RecordId part of both.
+ */
template <class T>
int compareWithoutRecordIdLong(const T& other) const;
+ template <class T>
+ int compareWithoutRecordIdStr(const T& other) const;
// Returns the size of the stored KeyString.
size_t getSize() const {
@@ -383,11 +391,12 @@ public:
}
/**
- * Serializes this Value, excluing the RecordId, into a storable format with TypeBits
+ * Serializes this Value, excluding the RecordId, into a storable format with TypeBits
* information. The serialized format takes the following form:
* [keystring size][keystring encoding][typebits encoding]
*/
void serializeWithoutRecordIdLong(BufBuilder& buf) const;
+ void serializeWithoutRecordIdStr(BufBuilder& buf) const;
// Deserialize the Value from a serialized format.
static Value deserialize(BufReader& buf, KeyString::Version version) {
@@ -616,11 +625,19 @@ public:
return _typeBits;
}
+ /**
+ * Compare with another KeyString::Value or Builder.
+ */
template <class T>
int compare(const T& other) const;
+ /**
+ * Compare with another KeyString::Value or Builder, ignoring the RecordId part of both.
+ */
template <class T>
int compareWithoutRecordIdLong(const T& other) const;
+ template <class T>
+ int compareWithoutRecordIdStr(const T& other) const;
/**
* @return a hex encoding of this key
@@ -1030,6 +1047,16 @@ int BuilderBase<BufferT>::compareWithoutRecordIdLong(const T& other) const {
!other.isEmpty() ? sizeWithoutRecordIdLongAtEnd(other.getBuffer(), other.getSize()) : 0);
}
+template <class BufferT>
+template <class T>
+int BuilderBase<BufferT>::compareWithoutRecordIdStr(const T& other) const {
+ return KeyString::compare(
+ getBuffer(),
+ other.getBuffer(),
+ !isEmpty() ? sizeWithoutRecordIdStrAtEnd(getBuffer(), getSize()) : 0,
+ !other.isEmpty() ? sizeWithoutRecordIdStrAtEnd(other.getBuffer(), other.getSize()) : 0);
+}
+
template <class T>
int Value::compare(const T& other) const {
return KeyString::compare(getBuffer(), other.getBuffer(), getSize(), other.getSize());
@@ -1044,6 +1071,15 @@ int Value::compareWithoutRecordIdLong(const T& other) const {
!other.isEmpty() ? sizeWithoutRecordIdLongAtEnd(other.getBuffer(), other.getSize()) : 0);
}
+template <class T>
+int Value::compareWithoutRecordIdStr(const T& other) const {
+ return KeyString::compare(
+ getBuffer(),
+ other.getBuffer(),
+ !isEmpty() ? sizeWithoutRecordIdStrAtEnd(getBuffer(), getSize()) : 0,
+ !other.isEmpty() ? sizeWithoutRecordIdStrAtEnd(other.getBuffer(), other.getSize()) : 0);
+}
+
/**
* Takes key string and key pattern information and uses it to present human-readable information
* about an index or collection entry.