MySQL  8.0.20
Source Code Documentation
filesort.h File Reference
#include <stddef.h>
#include <sys/types.h>
#include "my_base.h"
#include "my_dbug.h"
#include "my_inttypes.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 *fsort, RowIterator *source_iterator, 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...
 
longlong get_int_sort_key_for_item (Item *item)
 Declared here for Item_func_weight_string. 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...
 
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,
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.
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 by position (like if sort_positions is 1) 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 
)

◆ get_int_sort_key_for_item()

longlong get_int_sort_key_for_item ( Item item)

Declared here for Item_func_weight_string.

◆ 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