From 7bcb659c013aaf44e1edab7b8a102a738c0bfb8c Mon Sep 17 00:00:00 2001 From: Louis Williams Date: Fri, 5 Nov 2021 15:08:40 +0000 Subject: SERVER-54360 Support secondary unique indexes on clustered collections --- src/mongo/db/storage/key_string.h | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/mongo/db/storage/key_string.h') 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 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 int compareWithoutRecordIdLong(const T& other) const; + template + 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 int compare(const T& other) const; + /** + * Compare with another KeyString::Value or Builder, ignoring the RecordId part of both. + */ template int compareWithoutRecordIdLong(const T& other) const; + template + int compareWithoutRecordIdStr(const T& other) const; /** * @return a hex encoding of this key @@ -1030,6 +1047,16 @@ int BuilderBase::compareWithoutRecordIdLong(const T& other) const { !other.isEmpty() ? sizeWithoutRecordIdLongAtEnd(other.getBuffer(), other.getSize()) : 0); } +template +template +int BuilderBase::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 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 +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. -- cgit v1.2.1