MySQL 8.3.0
Source Code Documentation
filesort.h File Reference
#include <stddef.h>
#include <sys/types.h>
#include "mem_root_array.h"
#include "my_base.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_table_map.h"
#include "sql/sort_param.h"

Go to the source code of this file.

Classes

class  Filesort
 Sorting related info. More...
 

Functions

bool filesort (THD *thd, Filesort *filesort, RowIterator *source_iterator, table_map tables_to_get_rowid_for, ha_rows num_rows_estimate, Filesort_info *fs_info, Sort_result *sort_result, ha_rows *found_rows)
 Sort a table. More...
 
void filesort_free_buffers (TABLE *table, bool full)
 
void change_double_for_sort (double nr, uchar *to)
 
uint sortlength (THD *thd, st_sort_field *sortorder, uint s_length)
 Declared here so we can unit test it. More...
 
template<bool Is_big_endian>
void copy_integer (uchar *to, size_t to_length, const uchar *from, size_t from_length, bool is_unsigned)
 Copies an integer value to a format comparable with memcmp(). More...
 
bool SortWillBeOnRowId (const TABLE *table)
 
static void copy_native_longlong (uchar *to, size_t to_length, longlong val, bool is_unsigned)
 

Function Documentation

◆ change_double_for_sort()

void change_double_for_sort ( double  nr,
uchar to 
)

◆ copy_integer()

template<bool Is_big_endian>
void copy_integer ( uchar to,
size_t  to_length,
const uchar from,
size_t  from_length,
bool  is_unsigned 
)

Copies an integer value to a format comparable with memcmp().

The format is characterized by the following:

  • The sign bit goes first and is unset for negative values.
  • The representation is big endian.

The function template can be instantiated to copy from little or big endian values.

Template Parameters
Is_big_endianTrue if the source integer is big endian.
Parameters
toWhere to write the integer.
to_lengthSize in bytes of the destination buffer.
fromWhere to read the integer.
from_lengthSize in bytes of the source integer
is_unsignedTrue if the source integer is an unsigned value.

◆ copy_native_longlong()

static void copy_native_longlong ( uchar to,
size_t  to_length,
longlong  val,
bool  is_unsigned 
)
inlinestatic

◆ filesort()

bool filesort ( THD thd,
Filesort filesort,
RowIterator source_iterator,
table_map  tables_to_get_rowid_for,
ha_rows  num_rows_estimate,
Filesort_info fs_info,
Sort_result sort_result,
ha_rows found_rows 
)

Sort a table.

Creates a set of pointers that can be used to read the rows in sorted order. This should be done with the functions in records.cc.

The result set is stored in fs_info->io_cache or fs_info->sorted_result, or left in the main filesort buffer.

Parameters
thdCurrent thread
filesortHow to sort the table
source_iteratorWhere to read the rows to be sorted from.
tables_to_get_rowid_forWhich tables we are responsible for getting row IDs for. Tables in this set that are not also in "tables" are ignored.
num_rows_estimateHow many rows source_iterator is expected to produce. Only used for whether we intend to use the priority queue optimization or not; if we estimate fewer rows than we can fit into RAM, we never use the priority queue.
fs_infoOwns the buffers for sort_result.
sort_resultWhere to store the sort result.
[out]found_rowsStore the number of found rows here. This is the number of found rows after applying WHERE condition.
Note
If we sort row IDs (as opposed to addon fields), filesort() will call table->prepare_for_position().
Returns
False if success, true if error

◆ filesort_free_buffers()

void filesort_free_buffers ( TABLE table,
bool  full 
)

◆ sortlength()

uint sortlength ( THD thd,
st_sort_field sortorder,
uint  s_length 
)

Declared here so we can unit test it.

Declared here so we can unit test it.

Parameters
thdThread handler
sortorderOrder of items to sort
s_lengthNumber of items to sort
Note
sortorder->length is updated for each sort item.
Returns
Total length of sort buffer in bytes

◆ SortWillBeOnRowId()

bool SortWillBeOnRowId ( const TABLE table)