Refactor Sort_param::init_for_filesort
No logic changes. Extract some of init_for_filesort logic into a separate function: * Sort_param::setup_lengths_and_limit can be used to fill in the various xxx_length members of Sort_param, without having to allocate any of the other buffers. Reviewer: Monty
This commit is contained in:
parent
50e9f7aee5
commit
b70290869e
@ -87,43 +87,62 @@ static uint32 read_keypart_length(const uchar *from, uint bytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @param sortlen [Maximum] length of the sort key
|
/*
|
||||||
void Sort_param::init_for_filesort(uint sortlen, TABLE *table,
|
Initialize Sort_param for doing a filesort
|
||||||
ha_rows maxrows, Filesort *filesort)
|
|
||||||
|
@param table Table to sort
|
||||||
|
@param Filesort Filesort parameter to filesort()
|
||||||
|
@param sortlen [Maximum] length of the sort key
|
||||||
|
@param limit_rows Number of rows to return (may be less than rows to sort)
|
||||||
|
*/
|
||||||
|
|
||||||
|
void Sort_param::init_for_filesort(TABLE *table, Filesort *filesort,
|
||||||
|
uint sortlen, ha_rows limit_rows_arg)
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(addon_fields == NULL);
|
DBUG_ASSERT(addon_fields == NULL);
|
||||||
|
|
||||||
sort_length= sortlen;
|
|
||||||
ref_length= table->file->ref_length;
|
|
||||||
accepted_rows= filesort->accepted_rows;
|
|
||||||
|
|
||||||
if (!(table->file->ha_table_flags() & HA_FAST_KEY_READ) &&
|
if (!(table->file->ha_table_flags() & HA_FAST_KEY_READ) &&
|
||||||
!table->fulltext_searched && !filesort->sort_positions)
|
!table->fulltext_searched && !filesort->sort_positions)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Get the descriptors of all fields whose values are appended
|
Get the descriptors of all fields whose values are appended
|
||||||
to sorted fields and get its total length in addon_buf.length
|
to sorted fields and get its total length in addon_buf.length
|
||||||
*/
|
*/
|
||||||
addon_fields= get_addon_fields(table, sort_length, &addon_length,
|
addon_fields= get_addon_fields(table, sortlen, &addon_length,
|
||||||
&m_packable_length);
|
&m_packable_length);
|
||||||
}
|
}
|
||||||
if (using_addon_fields())
|
DBUG_ASSERT((using_addon_fields() == 0 || addon_length != 0));
|
||||||
|
|
||||||
|
setup_lengths_and_limit(table, sortlen, addon_length, limit_rows_arg);
|
||||||
|
accepted_rows= filesort->accepted_rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Sort_param::setup_lengths_and_limit(TABLE *table,
|
||||||
|
uint sort_len_arg,
|
||||||
|
uint addon_length_arg,
|
||||||
|
ha_rows limit_rows_arg)
|
||||||
|
{
|
||||||
|
sort_form= table;
|
||||||
|
sort_length= sort_len_arg;
|
||||||
|
limit_rows= limit_rows_arg;
|
||||||
|
ref_length= table->file->ref_length;
|
||||||
|
|
||||||
|
if (addon_length_arg)
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(addon_length < UINT_MAX32);
|
DBUG_ASSERT(addon_length_arg < UINT_MAX32);
|
||||||
res_length= addon_length;
|
res_length= addon_length_arg;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
res_length= ref_length;
|
res_length= ref_length;
|
||||||
/*
|
/*
|
||||||
The reference to the record is considered
|
The reference (rowid) to the record is considered as an additional
|
||||||
as an additional sorted field
|
sorted field as we want to access rows in rowid order if possible.
|
||||||
*/
|
*/
|
||||||
sort_length+= ref_length;
|
sort_length+= ref_length;
|
||||||
}
|
}
|
||||||
rec_length= sort_length + addon_length;
|
rec_length= sort_length + addon_length_arg;
|
||||||
limit_rows= maxrows;
|
|
||||||
sort_form= table;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -590,10 +590,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
tmp_buffer.set_charset(&my_charset_bin);
|
tmp_buffer.set_charset(&my_charset_bin);
|
||||||
}
|
}
|
||||||
void init_for_filesort(uint sortlen, TABLE *table,
|
|
||||||
ha_rows maxrows, Filesort *filesort);
|
|
||||||
|
|
||||||
void (*unpack)(TABLE *);
|
void init_for_filesort(TABLE *table, Filesort *filesort,
|
||||||
|
uint sortlen, ha_rows limit_rows_arg);
|
||||||
|
void setup_lengths_and_limit(TABLE *table,
|
||||||
|
uint sortlen,
|
||||||
|
uint addon_length,
|
||||||
|
ha_rows limit_rows_arg);
|
||||||
|
void (*unpack)(TABLE *);
|
||||||
/// Enables the packing of addons if possible.
|
/// Enables the packing of addons if possible.
|
||||||
void try_to_pack_addons(ulong max_length_for_sort_data);
|
void try_to_pack_addons(ulong max_length_for_sort_data);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user