mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
misc cleanup
This commit is contained in:
@ -60,9 +60,7 @@ static bool save_index(Sort_param *param, uint count,
|
|||||||
static uint suffix_length(ulong string_length);
|
static uint suffix_length(ulong string_length);
|
||||||
static uint sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
|
static uint sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
|
||||||
bool *multi_byte_charset);
|
bool *multi_byte_charset);
|
||||||
static SORT_ADDON_FIELD *get_addon_fields(ulong max_length_for_sort_data,
|
static SORT_ADDON_FIELD *get_addon_fields(TABLE *table, uint sortlength,
|
||||||
Field **ptabfield,
|
|
||||||
uint sortlength,
|
|
||||||
LEX_STRING *addon_buf);
|
LEX_STRING *addon_buf);
|
||||||
static void unpack_addon_fields(struct st_sort_addon_field *addon_field,
|
static void unpack_addon_fields(struct st_sort_addon_field *addon_field,
|
||||||
uchar *buff, uchar *buff_end);
|
uchar *buff, uchar *buff_end);
|
||||||
@ -71,7 +69,6 @@ static bool check_if_pq_applicable(Sort_param *param, SORT_INFO *info,
|
|||||||
ha_rows records, size_t memory_available);
|
ha_rows records, size_t memory_available);
|
||||||
|
|
||||||
void Sort_param::init_for_filesort(uint sortlen, TABLE *table,
|
void Sort_param::init_for_filesort(uint sortlen, TABLE *table,
|
||||||
ulong max_length_for_sort_data,
|
|
||||||
ha_rows maxrows, bool sort_positions)
|
ha_rows maxrows, bool sort_positions)
|
||||||
{
|
{
|
||||||
DBUG_ASSERT(addon_field == 0 && addon_buf.length == 0);
|
DBUG_ASSERT(addon_field == 0 && addon_buf.length == 0);
|
||||||
@ -85,8 +82,7 @@ void Sort_param::init_for_filesort(uint sortlen, TABLE *table,
|
|||||||
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_field= get_addon_fields(max_length_for_sort_data,
|
addon_field= get_addon_fields(table, sort_length, &addon_buf);
|
||||||
table->field, sort_length, &addon_buf);
|
|
||||||
}
|
}
|
||||||
if (addon_field)
|
if (addon_field)
|
||||||
{
|
{
|
||||||
@ -190,9 +186,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
|
|||||||
|
|
||||||
param.init_for_filesort(sortlength(thd, filesort->sortorder, s_length,
|
param.init_for_filesort(sortlength(thd, filesort->sortorder, s_length,
|
||||||
&multi_byte_charset),
|
&multi_byte_charset),
|
||||||
table,
|
table, max_rows, filesort->sort_positions);
|
||||||
thd->variables.max_length_for_sort_data,
|
|
||||||
max_rows, filesort->sort_positions);
|
|
||||||
|
|
||||||
sort->addon_buf= param.addon_buf;
|
sort->addon_buf= param.addon_buf;
|
||||||
sort->addon_field= param.addon_field;
|
sort->addon_field= param.addon_field;
|
||||||
@ -1970,7 +1964,7 @@ sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
|
|||||||
|
|
||||||
The function first finds out what fields are used in the result set.
|
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
|
Then it calculates the length of the buffer to store the values of
|
||||||
these fields together with the value of sort values.
|
these fields together with the value of sort values.
|
||||||
If the calculated length is not greater than max_length_for_sort_data
|
If the calculated length is not greater than max_length_for_sort_data
|
||||||
the function allocates memory for an array of descriptors containing
|
the function allocates memory for an array of descriptors containing
|
||||||
layouts for the values of the non-sorted fields in the buffer and
|
layouts for the values of the non-sorted fields in the buffer and
|
||||||
@ -1992,8 +1986,7 @@ sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static SORT_ADDON_FIELD *
|
static SORT_ADDON_FIELD *
|
||||||
get_addon_fields(ulong max_length_for_sort_data,
|
get_addon_fields(TABLE *table, uint sortlength, LEX_STRING *addon_buf)
|
||||||
Field **ptabfield, uint sortlength, LEX_STRING *addon_buf)
|
|
||||||
{
|
{
|
||||||
Field **pfield;
|
Field **pfield;
|
||||||
Field *field;
|
Field *field;
|
||||||
@ -2001,7 +1994,8 @@ get_addon_fields(ulong max_length_for_sort_data,
|
|||||||
uint length= 0;
|
uint length= 0;
|
||||||
uint fields= 0;
|
uint fields= 0;
|
||||||
uint null_fields= 0;
|
uint null_fields= 0;
|
||||||
MY_BITMAP *read_set= (*ptabfield)->table->read_set;
|
MY_BITMAP *read_set= table->read_set;
|
||||||
|
ulong max_sort_len= table->in_use->variables.max_length_for_sort_data;
|
||||||
DBUG_ENTER("get_addon_fields");
|
DBUG_ENTER("get_addon_fields");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2010,14 +2004,14 @@ get_addon_fields(ulong max_length_for_sort_data,
|
|||||||
Note for future refinement:
|
Note for future refinement:
|
||||||
This this a too strong condition.
|
This this a too strong condition.
|
||||||
Actually we need only the fields referred in the
|
Actually we need only the fields referred in the
|
||||||
result set. And for some of them it makes sense to use
|
result set. And for some of them it makes sense to use
|
||||||
the values directly from sorted fields.
|
the values directly from sorted fields.
|
||||||
But beware the case when item->cmp_type() != item->result_type()
|
But beware the case when item->cmp_type() != item->result_type()
|
||||||
*/
|
*/
|
||||||
addon_buf->str= 0;
|
addon_buf->str= 0;
|
||||||
addon_buf->length= 0;
|
addon_buf->length= 0;
|
||||||
|
|
||||||
for (pfield= ptabfield; (field= *pfield) ; pfield++)
|
for (pfield= table->field; (field= *pfield) ; pfield++)
|
||||||
{
|
{
|
||||||
if (!bitmap_is_set(read_set, field->field_index))
|
if (!bitmap_is_set(read_set, field->field_index))
|
||||||
continue;
|
continue;
|
||||||
@ -2027,12 +2021,12 @@ get_addon_fields(ulong max_length_for_sort_data,
|
|||||||
if (field->maybe_null())
|
if (field->maybe_null())
|
||||||
null_fields++;
|
null_fields++;
|
||||||
fields++;
|
fields++;
|
||||||
}
|
}
|
||||||
if (!fields)
|
if (!fields)
|
||||||
DBUG_RETURN(0);
|
DBUG_RETURN(0);
|
||||||
length+= (null_fields+7)/8;
|
length+= (null_fields+7)/8;
|
||||||
|
|
||||||
if (length+sortlength > max_length_for_sort_data ||
|
if (length+sortlength > max_sort_len ||
|
||||||
!my_multi_malloc(MYF(MY_WME | MY_THREAD_SPECIFIC),
|
!my_multi_malloc(MYF(MY_WME | MY_THREAD_SPECIFIC),
|
||||||
&addonf, sizeof(SORT_ADDON_FIELD) * (fields+1),
|
&addonf, sizeof(SORT_ADDON_FIELD) * (fields+1),
|
||||||
&addon_buf->str, length,
|
&addon_buf->str, length,
|
||||||
@ -2043,7 +2037,7 @@ get_addon_fields(ulong max_length_for_sort_data,
|
|||||||
addon_buf->length= length;
|
addon_buf->length= length;
|
||||||
length= (null_fields+7)/8;
|
length= (null_fields+7)/8;
|
||||||
null_fields= 0;
|
null_fields= 0;
|
||||||
for (pfield= ptabfield; (field= *pfield) ; pfield++)
|
for (pfield= table->field; (field= *pfield) ; pfield++)
|
||||||
{
|
{
|
||||||
if (!bitmap_is_set(read_set, field->field_index))
|
if (!bitmap_is_set(read_set, field->field_index))
|
||||||
continue;
|
continue;
|
||||||
@ -2065,7 +2059,7 @@ get_addon_fields(ulong max_length_for_sort_data,
|
|||||||
addonf++;
|
addonf++;
|
||||||
}
|
}
|
||||||
addonf->field= 0; // Put end marker
|
addonf->field= 0; // Put end marker
|
||||||
|
|
||||||
DBUG_PRINT("info",("addon_length: %d",length));
|
DBUG_PRINT("info",("addon_length: %d",length));
|
||||||
DBUG_RETURN(addonf-fields);
|
DBUG_RETURN(addonf-fields);
|
||||||
}
|
}
|
||||||
|
@ -5795,7 +5795,7 @@ int
|
|||||||
Ordered_key::cmp_keys_by_row_data(ha_rows a, ha_rows b)
|
Ordered_key::cmp_keys_by_row_data(ha_rows a, ha_rows b)
|
||||||
{
|
{
|
||||||
uchar *rowid_a, *rowid_b;
|
uchar *rowid_a, *rowid_b;
|
||||||
int __attribute__((unused)) error;
|
int error;
|
||||||
int cmp_res;
|
int cmp_res;
|
||||||
/* The length in bytes of the rowids (positions) of tmp_table. */
|
/* The length in bytes of the rowids (positions) of tmp_table. */
|
||||||
uint rowid_length= tbl->file->ref_length;
|
uint rowid_length= tbl->file->ref_length;
|
||||||
@ -5892,7 +5892,7 @@ int Ordered_key::cmp_key_with_search_key(rownum_t row_num)
|
|||||||
/* The length in bytes of the rowids (positions) of tmp_table. */
|
/* The length in bytes of the rowids (positions) of tmp_table. */
|
||||||
uint rowid_length= tbl->file->ref_length;
|
uint rowid_length= tbl->file->ref_length;
|
||||||
uchar *cur_rowid= row_num_to_rowid + row_num * rowid_length;
|
uchar *cur_rowid= row_num_to_rowid + row_num * rowid_length;
|
||||||
int __attribute__((unused)) error;
|
int error;
|
||||||
int cmp_res;
|
int cmp_res;
|
||||||
|
|
||||||
if (unlikely((error= tbl->file->ha_rnd_pos(tbl->record[0], cur_rowid))))
|
if (unlikely((error= tbl->file->ha_rnd_pos(tbl->record[0], cur_rowid))))
|
||||||
|
@ -2501,7 +2501,7 @@ int JOIN::optimize_stage2()
|
|||||||
{
|
{
|
||||||
JOIN_TAB *tab= &join_tab[const_tables];
|
JOIN_TAB *tab= &join_tab[const_tables];
|
||||||
|
|
||||||
if (order)
|
if (order && !need_tmp)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
Force using of tmp table if sorting by a SP or UDF function due to
|
Force using of tmp table if sorting by a SP or UDF function due to
|
||||||
@ -3206,7 +3206,7 @@ bool JOIN::make_aggr_tables_info()
|
|||||||
or end_write_group()) if JOIN::group is set to false.
|
or end_write_group()) if JOIN::group is set to false.
|
||||||
*/
|
*/
|
||||||
// the temporary table was explicitly requested
|
// the temporary table was explicitly requested
|
||||||
DBUG_ASSERT(MY_TEST(select_options & OPTION_BUFFER_RESULT));
|
DBUG_ASSERT(select_options & OPTION_BUFFER_RESULT);
|
||||||
// the temporary table does not have a grouping expression
|
// the temporary table does not have a grouping expression
|
||||||
DBUG_ASSERT(!curr_tab->table->group);
|
DBUG_ASSERT(!curr_tab->table->group);
|
||||||
}
|
}
|
||||||
@ -13191,7 +13191,8 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
|
|||||||
tab++)
|
tab++)
|
||||||
tab->cached_eq_ref_table= FALSE;
|
tab->cached_eq_ref_table= FALSE;
|
||||||
|
|
||||||
*simple_order= *join->join_tab[join->const_tables].on_expr_ref ? 0 : 1;
|
JOIN_TAB *head= join->join_tab + join->const_tables;
|
||||||
|
*simple_order= head->on_expr_ref[0] == NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -92,7 +92,6 @@ public:
|
|||||||
memset(this, 0, sizeof(*this));
|
memset(this, 0, sizeof(*this));
|
||||||
}
|
}
|
||||||
void init_for_filesort(uint sortlen, TABLE *table,
|
void init_for_filesort(uint sortlen, TABLE *table,
|
||||||
ulong max_length_for_sort_data,
|
|
||||||
ha_rows maxrows, bool sort_positions);
|
ha_rows maxrows, bool sort_positions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user