MySQL 8.0.39
Source Code Documentation
|
This file contains the HashJoinRowBuffer class and related functions/classes. More...
#include <assert.h>
#include <stddef.h>
#include <memory>
#include <optional>
#include <string_view>
#include <vector>
#include "my_alloc.h"
#include "sql/immutable_string.h"
#include "sql/pack_rows.h"
#include "sql_string.h"
Go to the source code of this file.
Classes | |
class | hash_join_buffer::HashJoinRowBuffer |
Namespaces | |
namespace | hash_join_buffer |
Typedefs | |
using | hash_join_buffer::Key = std::string_view |
The key type for the hash structure in HashJoinRowBuffer. More... | |
using | hash_join_buffer::BufferRow = Key |
Enumerations | |
enum class | hash_join_buffer::StoreRowResult { hash_join_buffer::ROW_STORED , hash_join_buffer::BUFFER_FULL , hash_join_buffer::FATAL_ERROR } |
Functions | |
void | hash_join_buffer::LoadBufferRowIntoTableBuffers (const TableCollection &tables, BufferRow row) |
void | hash_join_buffer::LoadImmutableStringIntoTableBuffers (const TableCollection &tables, LinkedImmutableString row) |
This file contains the HashJoinRowBuffer class and related functions/classes.
A HashJoinBuffer is a row buffer that can hold a certain amount of rows. The rows are stored in a hash table, which allows for constant-time lookup. The HashJoinBuffer maintains its own internal MEM_ROOT, where all of the data is allocated.
The HashJoinBuffer contains an operand with rows from one or more tables, keyed on the value we join on. Consider the following trivial example:
SELECT t1.data FROM t1 JOIN t2 ON (t1.key = t2.key);
Let us say that the table "t2" is stored in a HashJoinBuffer. In this case, the hash table key will be the value found in "t2.key", since that is the join condition that belongs to t2. If we have multiple equalities, they will be concatenated together in order to form the hash table key. The hash table key is a std::string_view.
In order to store a row, we use the function StoreFromTableBuffers. See the comments attached to the function for more details.
The amount of memory a HashJoinBuffer instance can use is limited by the system variable "join_buffer_size". However, note that we check whether we have exceeded the memory limit after we have inserted data into the row buffer. As such, we will probably use a little bit more memory than specified by join_buffer_size.
The primary use case for these classes is, as the name implies, for implementing hash join.