MySQL 8.4.0
Source Code Documentation
hash_join_buffer.h File Reference

This file contains the HashJoinRowBuffer class and related functions/classes. More...

#include <stddef.h>
#include <cassert>
#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.


class  hash_join_buffer::HashJoinRowBuffer


namespace  hash_join_buffer


using hash_join_buffer::Key = std::string_view
 The key type for the hash structure in HashJoinRowBuffer. More...
using hash_join_buffer::BufferRow = Key


enum class  hash_join_buffer::StoreRowResult { hash_join_buffer::ROW_STORED , hash_join_buffer::BUFFER_FULL , hash_join_buffer::FATAL_ERROR }


void hash_join_buffer::LoadBufferRowIntoTableBuffers (const TableCollection &tables, BufferRow row)
void hash_join_buffer::LoadImmutableStringIntoTableBuffers (const TableCollection &tables, LinkedImmutableString row)
LinkedImmutableString StoreLinkedImmutableStringFromTableBuffers (MEM_ROOT *mem_root, MEM_ROOT *overflow_mem_root, pack_rows::TableCollection tables, LinkedImmutableString next_ptr, size_t row_size_upper_bound, bool *full)
 External interface to the corresponding member in HashJoinRowBuffer. More...

Detailed Description

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 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.

Function Documentation

◆ StoreLinkedImmutableStringFromTableBuffers()

LinkedImmutableString StoreLinkedImmutableStringFromTableBuffers ( MEM_ROOT mem_root,
MEM_ROOT overflow_mem_root,
pack_rows::TableCollection  tables,
LinkedImmutableString  next_ptr,
size_t  row_size_upper_bound,
bool *  full 

External interface to the corresponding member in HashJoinRowBuffer.