MySQL 8.4.3
Source Code Documentation
uniques.cc File Reference
#include "sql/uniques.h"
#include <string.h>
#include <algorithm>
#include <atomic>
#include <cmath>
#include <vector>
#include "my_base.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_io.h"
#include "my_tree.h"
#include "mysql/components/services/bits/psi_bits.h"
#include "mysql/psi/mysql_file.h"
#include "mysql/service_mysql_alloc.h"
#include "priority_queue.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/malloc_allocator.h"
#include "sql/merge_many_buff.h"
#include "sql/mysqld.h"
#include "sql/opt_costmodel.h"
#include "sql/psi_memory_key.h"
#include "sql/sql_base.h"
#include "sql/sql_class.h"
#include "sql/sql_const.h"
#include "sql/sql_executor.h"
#include "sql/sql_sort.h"
#include "sql/sql_tmp_table.h"
#include "sql/table.h"

Classes

struct  anonymous_namespace{uniques.cc}::Merge_chunk_compare_context
 
class  anonymous_namespace{uniques.cc}::Uniq_param
 
struct  anonymous_namespace{uniques.cc}::Merge_chunk_less
 

Namespaces

namespace  anonymous_namespace{uniques.cc}
 

Functions

static uint uniq_read_to_buffer (IO_CACHE *fromfile, Merge_chunk *merge_chunk, Uniq_param *param)
 Read data to buffer. More...
 
static int merge_buffers (THD *thd, Uniq_param *param, IO_CACHE *from_file, IO_CACHE *to_file, Sort_buffer sort_buffer, Merge_chunk *last_chunk, Merge_chunk_array chunk_array, int flag)
 Merge buffers to one buffer. More...
 
int unique_write_to_file (void *v_key, element_count, void *v_unique)
 
int unique_write_to_ptrs (void *v_key, element_count, void *v_unique)
 
static double log2_n_fact (ulong n)
 Calculate log2(n!) More...
 
static double get_merge_buffers_cost (size_t total_buf_elems, size_t n_buffers, uint elem_size, const Cost_model_table *cost_model)
 
static double get_merge_many_buffs_cost (uint num_full_buffers, uint elems_per_buffer, uint additional_num_elems, int elem_size, const Cost_model_table *cost_model)
 
static int merge_chunk_compare (Merge_chunk_compare_context *ctx, uchar *key_ptr1, uchar *key_ptr2)
 
static bool merge_walk (uchar *merge_buffer, size_t merge_buffer_size, size_t key_length, Merge_chunk *begin, Merge_chunk *end, tree_walk_action walk_action, void *walk_action_arg, qsort2_cmp compare, const void *compare_arg, IO_CACHE *file)
 

Function Documentation

◆ get_merge_buffers_cost()

static double get_merge_buffers_cost ( size_t  total_buf_elems,
size_t  n_buffers,
uint  elem_size,
const Cost_model_table cost_model 
)
static

◆ get_merge_many_buffs_cost()

static double get_merge_many_buffs_cost ( uint  num_full_buffers,
uint  elems_per_buffer,
uint  additional_num_elems,
int  elem_size,
const Cost_model_table cost_model 
)
static

◆ log2_n_fact()

static double log2_n_fact ( ulong  n)
inlinestatic

Calculate log2(n!)

Stirling's approximate formula is used:

n! ~= sqrt(2*M_PI*n) * (n/M_E)^n

Derivation of formula used for calculations is as follows:

log2(n!) = log2(sqrt(2*M_PI*n)*(n/M_E)^n)

= log2(2*M_PI*n)/2 + n*log2(n/M_E)

= log2(2*M_PI)/2 + log2(n)/2 + n * (log2(n) - M_LOG2E);

Parameters
nthe number to calculate log2(n!) for
Returns
log2(n!) for the function argument

◆ merge_buffers()

static int merge_buffers ( THD thd,
Uniq_param *  param,
IO_CACHE from_file,
IO_CACHE to_file,
Sort_buffer  sort_buffer,
Merge_chunk last_chunk,
Merge_chunk_array  chunk_array,
int  flag 
)
static

Merge buffers to one buffer.

Parameters
thdthread context
paramSort parameter
from_fileFile with source data (Merge_chunks point to this file)
to_fileFile to write the sorted result data.
sort_bufferBuffer for data to store up to MERGEBUFF2 sort keys.
[out]last_chunkStore here Merge_chunk describing data written to to_file.
chunk_arrayArray of chunks to merge.
flag0 - write full record, 1 - write addon/ref
Return values
0OK
othererror

◆ merge_chunk_compare()

static int merge_chunk_compare ( Merge_chunk_compare_context *  ctx,
uchar key_ptr1,
uchar key_ptr2 
)
static

◆ merge_walk()

static bool merge_walk ( uchar merge_buffer,
size_t  merge_buffer_size,
size_t  key_length,
Merge_chunk begin,
Merge_chunk end,
tree_walk_action  walk_action,
void *  walk_action_arg,
qsort2_cmp  compare,
const void *  compare_arg,
IO_CACHE file 
)
static

◆ uniq_read_to_buffer()

static uint uniq_read_to_buffer ( IO_CACHE fromfile,
Merge_chunk merge_chunk,
Uniq_param *  param 
)
static

Read data to buffer.

Returns
(uint)-1 if something goes wrong

◆ unique_write_to_file()

int unique_write_to_file ( void *  v_key,
element_count  count,
void *  v_unique 
)

◆ unique_write_to_ptrs()

int unique_write_to_ptrs ( void *  v_key,
element_count  count,
void *  v_unique 
)