Public Member Functions | |
FileSort (Session &arg) | |
Session & | getSession () |
ha_rows | run (Table *table, SortField *sortorder, uint32_t s_length, optimizer::SqlSelect *select, ha_rows max_rows, bool sort_positions, ha_rows &examined_rows) |
Private Member Functions | |
uint32_t | sortlength (SortField *sortorder, uint32_t s_length, bool *multi_byte_charset) |
sort_addon_field * | get_addon_fields (Field **ptabfield, uint32_t sortlength, uint32_t *plength) |
ha_rows | find_all_keys (SortParam *param, optimizer::SqlSelect *select, unsigned char **sort_keys, internal::io_cache_st *buffpek_pointers, internal::io_cache_st *tempfile, internal::io_cache_st *indexfile) |
int | merge_buffers (SortParam *param, internal::io_cache_st *from_file, internal::io_cache_st *to_file, unsigned char *sort_buffer, buffpek *lastbuff, buffpek *Fb, buffpek *Tb, int flag) |
int | merge_index (SortParam *param, unsigned char *sort_buffer, buffpek *buffpek, uint32_t maxbuffer, internal::io_cache_st *tempfile, internal::io_cache_st *outfile) |
int | merge_many_buff (SortParam *param, unsigned char *sort_buffer, buffpek *buffpek, uint32_t *maxbuffer, internal::io_cache_st *t_file) |
uint32_t | read_to_buffer (internal::io_cache_st *fromfile, buffpek *buffpek, uint32_t sort_length) |
Private Attributes | |
Session & | _session |
Definition at line 36 of file filesort.h.
|
private |
Search after sort_keys and write them into tempfile. All produced sequences are guaranteed to be non-empty.
param | Sorting parameter |
select | Use this to get source data |
sort_keys | Array of pointers to sort key + addon buffers. |
buffpek_pointers | File to write buffpeks describing sorted segments in tempfile. |
tempfile | File to write sorted sequences of sortkeys to. |
indexfile | If !NULL, use it for source data (contains rowids) |
while (get_next_sortkey()) { if (no free space in sort_keys buffers) { sort sort_keys buffer; dump sorted sequence to 'tempfile'; dump buffpek describing sequence location into 'buffpek_pointers'; } put sort key into 'sort_keys'; } if (sort_keys has some elements && dumped at least once) sort-dump-dump as above; else don't sort, leave sort_keys array to be sorted by caller.
Number | of records written on success. |
HA_POS_ERROR | on error. |
Definition at line 522 of file filesort.cc.
References drizzled::optimizer::SqlSelect::cond, drizzled::Table::cursor, drizzled::SortParam::make_sortkey(), drizzled::optimizer::SqlSelect::quick, drizzled::optimizer::QuickSelectInterface::reset(), and drizzled::SortParam::write_keys().
Referenced by run().
|
private |
Get descriptors of fields appended to sorted fields and calculate its total length.
The function first finds out what fields are used in the result set. Then it calculates the length of the buffer to store the values of these fields together with the value of sort values. If the calculated length is not greater than max_length_for_sort_data the function allocates memory for an array of descriptors containing layouts for the values of the non-sorted fields in the buffer and fills them.
ptabfield | Array of references to the table fields | |
sortlength | Total length of sorted fields | |
[out] | plength | Total length of appended fields |
NULL | if we do not store field values with sort data. |
Definition at line 1541 of file filesort.cc.
References drizzled::Field::pack_length(), and drizzled::Session::variables.
Referenced by run().
|
private |
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 1184 of file filesort.cc.
References read_to_buffer().
Referenced by merge_many_buff().
|
private |
Merge buffers to make < MERGEBUFF2 buffers.
Definition at line 1067 of file filesort.cc.
References merge_buffers(), drizzled::internal::io_cache_st::reinit_io_cache(), and drizzled::internal::io_cache_st::setup_io_cache().
Referenced by run().
|
private |
Read data to buffer.
(uint32_t)-1 | if something goes wrong |
Definition at line 1127 of file filesort.cc.
Referenced by merge_buffers().
ha_rows drizzled::FileSort::run | ( | Table * | table, |
SortField * | sortorder, | ||
uint32_t | s_length, | ||
optimizer::SqlSelect * | select, | ||
ha_rows | max_rows, | ||
bool | sort_positions, | ||
ha_rows & | examined_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.
table | Table to sort |
sortorder | How to sort the table |
s_length | Number of elements in sortorder |
select | condition to apply to the rows |
max_rows | Return only this many rows |
sort_positions | Set to 1 if we want to force sorting by position (Needed by UPDATE/INSERT or ALTER Table) |
examined_rows | Store number of examined rows here |
HA_POS_ERROR | Error |
Definition at line 187 of file filesort.cc.
References drizzled::TableList::containing_subselect(), drizzled::Table::cursor, drizzled::Cursor::estimate_rows_upper_bound(), find_all_keys(), get_addon_fields(), drizzled::make_char_array(), merge_many_buff(), drizzled::optimizer::SqlSelect::quick, drizzled::read_buffpek_from_file(), drizzled::optimizer::QuickSelectInterface::records, drizzled::Cursor::ref_length, drizzled::internal::io_cache_st::reinit_io_cache(), drizzled::plugin::TransactionalStorageEngine::releaseTemporaryLatches(), sortlength(), drizzled::unpack_addon_fields(), and drizzled::Session::variables.
Referenced by drizzled::delete_query(), and drizzled::update_query().
|
private |
Calculate length of sort key.
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 1438 of file filesort.cc.
References drizzled::SortField::field, drizzled::SortField::item, drizzled::SortField::length, drizzled::Item::maybe_null, drizzled::SortField::need_strxnfrm, drizzled::Item::result_as_int64_t(), drizzled::SortField::result_type, and drizzled::SortField::suffix_length.
Referenced by run().