MySQL 5.6.14 Source Code Document
|
Sorts a database. More...
#include "sql_priv.h"
#include "filesort.h"
#include "unireg.h"
#include <m_ctype.h>
#include "sql_sort.h"
#include "probes_mysql.h"
#include "opt_range.h"
#include "bounded_queue.h"
#include "filesort_utils.h"
#include "sql_select.h"
#include "debug_sync.h"
#include "opt_trace.h"
#include "sql_optimizer.h"
#include <algorithm>
#include <utility>
Go to the source code of this file.
Macros | |
#define | DBL_EXP_DIG (sizeof(double)*8-DBL_MANT_DIG) |
Functions | |
ha_rows | filesort (THD *thd, TABLE *table, Filesort *filesort, bool sort_positions, ha_rows *examined_rows, ha_rows *found_rows) |
void | filesort_free_buffers (TABLE *table, bool full) |
void | copy_native_longlong (uchar *to, int to_length, longlong val, bool is_unsigned) |
void | make_sortkey (Sort_param *param, uchar *to, uchar *ref_pos) |
Declared here so we can unit test it. | |
int | merge_many_buff (Sort_param *param, uchar *sort_buffer, BUFFPEK *buffpek, uint *maxbuffer, IO_CACHE *t_file) |
uint | read_to_buffer (IO_CACHE *fromfile, BUFFPEK *buffpek, uint rec_length) |
void | reuse_freed_buff (QUEUE *queue, BUFFPEK *reuse, uint key_length) |
int | merge_buffers (Sort_param *param, IO_CACHE *from_file, IO_CACHE *to_file, uchar *sort_buffer, BUFFPEK *lastbuff, BUFFPEK *Fb, BUFFPEK *Tb, int flag) |
uint | sortlength (THD *thd, SORT_FIELD *sortorder, uint s_length, bool *multi_byte_charset) |
Declared here so we can unit test it. | |
void | change_double_for_sort (double nr, uchar *to) |
Variables | |
const bool | Is_big_endian = false |
Sorts a database.
Definition in file filesort.cc.
ha_rows filesort | ( | THD * | thd, |
TABLE * | table, | ||
Filesort * | filesort, | ||
bool | sort_positions, | ||
ha_rows * | examined_rows, | ||
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.
Before calling filesort, one must have done table->file->info(HA_STATUS_VARIABLE)
The result set is stored in table->io_cache or table->record_pointers.
thd | Current thread | |
table | Table to sort | |
filesort | How to sort the table | |
sort_positions | Set to TRUE if we want to force sorting by position (Needed by UPDATE/INSERT or ALTER TABLE or when rowids are required by executor) | |
[out] | examined_rows | Store number of examined rows here This is the number of found rows before applying WHERE condition. |
[out] | found_rows | Store the number of found rows here. This is the number of found rows after applying WHERE condition. |
HA_POS_ERROR | Error |
\:: | Number of rows in the result, could be less than found_rows if LIMIT were provided. |
Definition at line 173 of file filesort.cc.
void make_sortkey | ( | Sort_param * | param, |
uchar * | to, | ||
uchar * | ref_pos | ||
) |
Declared here so we can unit test it.
Make a sort-key from record.
Definition at line 950 of file filesort.cc.
int merge_buffers | ( | Sort_param * | param, |
IO_CACHE * | from_file, | ||
IO_CACHE * | to_file, | ||
uchar * | sort_buffer, | ||
BUFFPEK * | lastbuff, | ||
BUFFPEK * | Fb, | ||
BUFFPEK * | Tb, | ||
int | flag | ||
) |
Merge buffers to one buffer.
param | Sort parameter |
from_file | File with source data (BUFFPEKs point to this file) |
to_file | File to write the sorted result data. |
sort_buffer | Buffer for data to store up to MERGEBUFF2 sort keys. |
lastbuff | OUT Store here BUFFPEK describing data written to to_file |
Fb | First element in source BUFFPEKs array |
Tb | Last element in source BUFFPEKs array |
flag |
0 | OK |
other | error |
Definition at line 1555 of file filesort.cc.
int merge_many_buff | ( | Sort_param * | param, |
uchar * | sort_buffer, | ||
BUFFPEK * | buffpek, | ||
uint * | maxbuffer, | ||
IO_CACHE * | t_file | ||
) |
Merge buffers to make < MERGEBUFF2 buffers.
Definition at line 1425 of file filesort.cc.
Read data to buffer.
(uint)-1 | if something goes wrong |
Definition at line 1483 of file filesort.cc.
Put all room used by freed buffer to use in adjacent buffer.
Note, that we can't simply distribute memory evenly between all buffers, because new areas must not overlap with old ones.
[in] | queue | list of non-empty buffers, without freed buffer |
[in] | reuse | empty buffer |
[in] | key_length | key length |
Definition at line 1515 of file filesort.cc.
uint sortlength | ( | THD * | thd, |
SORT_FIELD * | sortorder, | ||
uint | s_length, | ||
bool * | multi_byte_charset | ||
) |
Declared here so we can unit test it.
Calculate length of sort key.
thd | Thread handler | |
sortorder | Order of items to sort | |
s_length | Number of items to sort | |
[out] | multi_byte_charset | Set to 1 if we are using multi-byte charset (In which case we have to use strxnfrm()) |
Definition at line 1807 of file filesort.cc.