Skip to content

Commit cd29aee

Browse files
committed
misc cleanup
1 parent 1823ce7 commit cd29aee

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

sql/filesort.cc

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ static bool save_index(Sort_param *param, uint count,
6060
static uint suffix_length(ulong string_length);
6161
static uint sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
6262
bool *multi_byte_charset);
63-
static SORT_ADDON_FIELD *get_addon_fields(ulong max_length_for_sort_data,
64-
Field **ptabfield,
65-
uint sortlength,
63+
static SORT_ADDON_FIELD *get_addon_fields(TABLE *table, uint sortlength,
6664
LEX_STRING *addon_buf);
6765
static void unpack_addon_fields(struct st_sort_addon_field *addon_field,
6866
uchar *buff, uchar *buff_end);
@@ -71,7 +69,6 @@ static bool check_if_pq_applicable(Sort_param *param, SORT_INFO *info,
7169
ha_rows records, size_t memory_available);
7270

7371
void Sort_param::init_for_filesort(uint sortlen, TABLE *table,
74-
ulong max_length_for_sort_data,
7572
ha_rows maxrows, bool sort_positions)
7673
{
7774
DBUG_ASSERT(addon_field == 0 && addon_buf.length == 0);
@@ -85,8 +82,7 @@ void Sort_param::init_for_filesort(uint sortlen, TABLE *table,
8582
Get the descriptors of all fields whose values are appended
8683
to sorted fields and get its total length in addon_buf.length
8784
*/
88-
addon_field= get_addon_fields(max_length_for_sort_data,
89-
table->field, sort_length, &addon_buf);
85+
addon_field= get_addon_fields(table, sort_length, &addon_buf);
9086
}
9187
if (addon_field)
9288
{
@@ -190,9 +186,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
190186

191187
param.init_for_filesort(sortlength(thd, filesort->sortorder, s_length,
192188
&multi_byte_charset),
193-
table,
194-
thd->variables.max_length_for_sort_data,
195-
max_rows, filesort->sort_positions);
189+
table, max_rows, filesort->sort_positions);
196190

197191
sort->addon_buf= param.addon_buf;
198192
sort->addon_field= param.addon_field;
@@ -1970,7 +1964,7 @@ sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
19701964
19711965
The function first finds out what fields are used in the result set.
19721966
Then it calculates the length of the buffer to store the values of
1973-
these fields together with the value of sort values.
1967+
these fields together with the value of sort values.
19741968
If the calculated length is not greater than max_length_for_sort_data
19751969
the function allocates memory for an array of descriptors containing
19761970
layouts for the values of the non-sorted fields in the buffer and
@@ -1992,16 +1986,16 @@ sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
19921986
*/
19931987

19941988
static SORT_ADDON_FIELD *
1995-
get_addon_fields(ulong max_length_for_sort_data,
1996-
Field **ptabfield, uint sortlength, LEX_STRING *addon_buf)
1989+
get_addon_fields(TABLE *table, uint sortlength, LEX_STRING *addon_buf)
19971990
{
19981991
Field **pfield;
19991992
Field *field;
20001993
SORT_ADDON_FIELD *addonf;
20011994
uint length= 0;
20021995
uint fields= 0;
20031996
uint null_fields= 0;
2004-
MY_BITMAP *read_set= (*ptabfield)->table->read_set;
1997+
MY_BITMAP *read_set= table->read_set;
1998+
ulong max_sort_len= table->in_use->variables.max_length_for_sort_data;
20051999
DBUG_ENTER("get_addon_fields");
20062000

20072001
/*
@@ -2010,14 +2004,14 @@ get_addon_fields(ulong max_length_for_sort_data,
20102004
Note for future refinement:
20112005
This this a too strong condition.
20122006
Actually we need only the fields referred in the
2013-
result set. And for some of them it makes sense to use
2007+
result set. And for some of them it makes sense to use
20142008
the values directly from sorted fields.
20152009
But beware the case when item->cmp_type() != item->result_type()
20162010
*/
20172011
addon_buf->str= 0;
20182012
addon_buf->length= 0;
20192013

2020-
for (pfield= ptabfield; (field= *pfield) ; pfield++)
2014+
for (pfield= table->field; (field= *pfield) ; pfield++)
20212015
{
20222016
if (!bitmap_is_set(read_set, field->field_index))
20232017
continue;
@@ -2027,12 +2021,12 @@ get_addon_fields(ulong max_length_for_sort_data,
20272021
if (field->maybe_null())
20282022
null_fields++;
20292023
fields++;
2030-
}
2024+
}
20312025
if (!fields)
20322026
DBUG_RETURN(0);
20332027
length+= (null_fields+7)/8;
20342028

2035-
if (length+sortlength > max_length_for_sort_data ||
2029+
if (length+sortlength > max_sort_len ||
20362030
!my_multi_malloc(MYF(MY_WME | MY_THREAD_SPECIFIC),
20372031
&addonf, sizeof(SORT_ADDON_FIELD) * (fields+1),
20382032
&addon_buf->str, length,
@@ -2043,7 +2037,7 @@ get_addon_fields(ulong max_length_for_sort_data,
20432037
addon_buf->length= length;
20442038
length= (null_fields+7)/8;
20452039
null_fields= 0;
2046-
for (pfield= ptabfield; (field= *pfield) ; pfield++)
2040+
for (pfield= table->field; (field= *pfield) ; pfield++)
20472041
{
20482042
if (!bitmap_is_set(read_set, field->field_index))
20492043
continue;
@@ -2065,7 +2059,7 @@ get_addon_fields(ulong max_length_for_sort_data,
20652059
addonf++;
20662060
}
20672061
addonf->field= 0; // Put end marker
2068-
2062+
20692063
DBUG_PRINT("info",("addon_length: %d",length));
20702064
DBUG_RETURN(addonf-fields);
20712065
}

sql/item_subselect.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5795,7 +5795,7 @@ int
57955795
Ordered_key::cmp_keys_by_row_data(ha_rows a, ha_rows b)
57965796
{
57975797
uchar *rowid_a, *rowid_b;
5798-
int __attribute__((unused)) error;
5798+
int error;
57995799
int cmp_res;
58005800
/* The length in bytes of the rowids (positions) of tmp_table. */
58015801
uint rowid_length= tbl->file->ref_length;
@@ -5892,7 +5892,7 @@ int Ordered_key::cmp_key_with_search_key(rownum_t row_num)
58925892
/* The length in bytes of the rowids (positions) of tmp_table. */
58935893
uint rowid_length= tbl->file->ref_length;
58945894
uchar *cur_rowid= row_num_to_rowid + row_num * rowid_length;
5895-
int __attribute__((unused)) error;
5895+
int error;
58965896
int cmp_res;
58975897

58985898
if (unlikely((error= tbl->file->ha_rnd_pos(tbl->record[0], cur_rowid))))

sql/sql_select.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,7 @@ int JOIN::optimize_stage2()
25012501
{
25022502
JOIN_TAB *tab= &join_tab[const_tables];
25032503

2504-
if (order)
2504+
if (order && !need_tmp)
25052505
{
25062506
/*
25072507
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()
32063206
or end_write_group()) if JOIN::group is set to false.
32073207
*/
32083208
// the temporary table was explicitly requested
3209-
DBUG_ASSERT(MY_TEST(select_options & OPTION_BUFFER_RESULT));
3209+
DBUG_ASSERT(select_options & OPTION_BUFFER_RESULT);
32103210
// the temporary table does not have a grouping expression
32113211
DBUG_ASSERT(!curr_tab->table->group);
32123212
}
@@ -13191,7 +13191,8 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
1319113191
tab++)
1319213192
tab->cached_eq_ref_table= FALSE;
1319313193

13194-
*simple_order= *join->join_tab[join->const_tables].on_expr_ref ? 0 : 1;
13194+
JOIN_TAB *head= join->join_tab + join->const_tables;
13195+
*simple_order= head->on_expr_ref[0] == NULL;
1319513196
}
1319613197
else
1319713198
{

sql/sql_sort.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ class Sort_param {
9292
memset(this, 0, sizeof(*this));
9393
}
9494
void init_for_filesort(uint sortlen, TABLE *table,
95-
ulong max_length_for_sort_data,
9695
ha_rows maxrows, bool sort_positions);
9796
};
9897

0 commit comments

Comments
 (0)