Drizzled Public API Documentation

drizzled::FileSort Class Reference

Public Member Functions

 FileSort (Session &arg)
 
SessiongetSession ()
 
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_fieldget_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
 

Detailed Description

Definition at line 36 of file filesort.h.

Member Function Documentation

ha_rows drizzled::FileSort::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 
)
private

Search after sort_keys and write them into tempfile. All produced sequences are guaranteed to be non-empty.

Parameters
paramSorting parameter
selectUse this to get source data
sort_keysArray of pointers to sort key + addon buffers.
buffpek_pointersFile to write buffpeks describing sorted segments in tempfile.
tempfileFile to write sorted sequences of sortkeys to.
indexfileIf !NULL, use it for source data (contains rowids)
Note
Basic idea:
   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.
Return values
Numberof records written on success.
HA_POS_ERRORon 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().

sort_addon_field * drizzled::FileSort::get_addon_fields ( Field **  ptabfield,
uint32_t  sortlength_arg,
uint32_t *  plength 
)
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.

Parameters
ptabfieldArray of references to the table fields
sortlengthTotal length of sorted fields
[out]plengthTotal length of appended fields
Note
The null bits for the appended values are supposed to be put together and stored the buffer just ahead of the value of the first field.
Returns
Pointer to the layout descriptors for the appended fields, if any
Return values
NULLif 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().

int drizzled::FileSort::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 
)
private

Merge buffers to one buffer.

Parameters
paramSort parameter
from_fileFile with source data (buffpeks point to this file)
to_fileFile to write the sorted result data.
sort_bufferBuffer for data to store up to MERGEBUFF2 sort keys.
lastbuffOUT Store here buffpek describing data written to to_file
FbFirst element in source buffpeks array
TbLast element in source buffpeks array
flag
Return values
0OK
othererror

Definition at line 1184 of file filesort.cc.

References read_to_buffer().

Referenced by merge_many_buff().

int drizzled::FileSort::merge_many_buff ( SortParam param,
unsigned char *  sort_buffer,
buffpek buffpek_inst,
uint32_t *  maxbuffer,
internal::io_cache_st t_file 
)
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().

uint32_t drizzled::FileSort::read_to_buffer ( internal::io_cache_st fromfile,
buffpek buffpek_inst,
uint32_t  rec_length 
)
private

Read data to buffer.

Return values
(uint32_t)-1if 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.

Parameters
tableTable to sort
sortorderHow to sort the table
s_lengthNumber of elements in sortorder
selectcondition to apply to the rows
max_rowsReturn only this many rows
sort_positionsSet to 1 if we want to force sorting by position (Needed by UPDATE/INSERT or ALTER Table)
examined_rowsStore number of examined rows here
Todo:
check why we do this (param.keys–)
Note
If we sort by position (like if sort_positions is 1) filesort() will call table->prepare_for_position().
Return values
HA_POS_ERRORError
# Number of rows
examined_rowswill be set to number of examined rows

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().

uint32_t drizzled::FileSort::sortlength ( SortField sortorder,
uint32_t  s_length,
bool *  multi_byte_charset 
)
private

Calculate length of sort key.

Parameters
sortorderOrder of items to sort
s_lengthNumber of items to sort
[out]multi_byte_charsetSet to 1 if we are using multi-byte charset (In which case we have to use strxnfrm())
Note
sortorder->length is updated for each sort item.
sortorder->need_strxnfrm is set 1 if we have to use strxnfrm
Returns
Total length of sort buffer in bytes

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().


The documentation for this class was generated from the following files: