MySQL  8.0.27
Source Code Documentation
hash_join_buffer.h File Reference

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

#include <stddef.h>
#include <stdint.h>
#include <memory>
#include <vector>
#include "extra/robin-hood-hashing/robin_hood.h"
#include "field_types.h"
#include "map_helpers.h"
#include "my_alloc.h"
#include "my_inttypes.h"
#include "my_table_map.h"
#include "prealloced_array.h"
#include "sql/immutable_string.h"
#include "sql/item_cmpfunc.h"
#include "sql/pack_rows.h"
#include "sql/table.h"
#include "sql_string.h"

Go to the source code of this file.

Classes

class  hash_join_buffer::KeyEquals
 
class  hash_join_buffer::KeyHasher
 
class  hash_join_buffer::HashJoinRowBuffer
 

Namespaces

 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)
 

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