MySQL 8.0.39
Source Code Documentation
LinkedImmutableString Class Reference

LinkedImmutableString is designed for storing rows (values) in hash join. More...

#include <immutable_string.h>

Classes

struct  Decoded
 

Public Member Functions

 LinkedImmutableString (const char *encoded)
 NOTE: nullptr is a legal value for encoded, and signals the same thing as nullptr would on a const char *. More...
 
Decoded Decode () const
 
bool operator== (std::nullptr_t) const
 
bool operator!= (std::nullptr_t) const
 

Static Public Member Functions

static LinkedImmutableString EncodeHeader (LinkedImmutableString next, char **dst)
 Encode the given string and “next” pointer as a header for LinkedImmutableString, and returns a new object pointing to it. More...
 
static size_t RequiredBytesForEncode (size_t length)
 Calculates an upper bound on the space required for encoding a string of the given length. More...
 

Private Attributes

const char * m_ptr
 

Detailed Description

LinkedImmutableString is designed for storing rows (values) in hash join.

It does not need a length, since it is implicit from the contents; however, since there might be multiple values with the same key, we simulate a multimap by having a “next” pointer. (Normally, linked lists are a bad idea due to pointer chasing, but here, we're doing so much work for each value that the overhead disappears into the noise.)

As the next pointer is usually be very close in memory to ourselves (nearly all rows are stored in the same MEM_ROOT), we don't need to store the entire pointer; instead, we store the difference between the start of this string and the next pointer, as a zigzag-encoded Varint128. As with the length in ImmutableStringWithLength, this typically saves 6–7 bytes for each value. The special value of 0 means that there is no next pointer (ie., it is nullptr), as that would otherwise be an infinite loop.

Constructor & Destructor Documentation

◆ LinkedImmutableString()

LinkedImmutableString::LinkedImmutableString ( const char *  encoded)
inlineexplicit

NOTE: nullptr is a legal value for encoded, and signals the same thing as nullptr would on a const char *.

Member Function Documentation

◆ Decode()

LinkedImmutableString::Decoded LinkedImmutableString::Decode ( ) const
inline

◆ EncodeHeader()

LinkedImmutableString LinkedImmutableString::EncodeHeader ( LinkedImmutableString  next,
char **  dst 
)
inlinestatic

Encode the given string and “next” pointer as a header for LinkedImmutableString, and returns a new object pointing to it.

Note that unlike ImmutableStringWithLength::Encode(), this only encodes the header; since there is no explicitly stored length, you must write the contents of the string yourself.

*dst must contain at least the number of bytes returned by RequiredBytesForEncode. It is moved to one byte past the end of the written stream (which is the right place to store the string itself).

◆ operator!=()

bool LinkedImmutableString::operator!= ( std::nullptr_t  ) const
inline

◆ operator==()

bool LinkedImmutableString::operator== ( std::nullptr_t  ) const
inline

◆ RequiredBytesForEncode()

static size_t LinkedImmutableString::RequiredBytesForEncode ( size_t  length)
inlinestatic

Calculates an upper bound on the space required for encoding a string of the given length.

Member Data Documentation

◆ m_ptr

const char* LinkedImmutableString::m_ptr
private

The documentation for this class was generated from the following file: