@@ -60,9 +60,7 @@ static bool save_index(Sort_param *param, uint count,
60
60
static uint suffix_length (ulong string_length);
61
61
static uint sortlength (THD *thd, SORT_FIELD *sortorder, uint s_length,
62
62
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,
66
64
LEX_STRING *addon_buf);
67
65
static void unpack_addon_fields (struct st_sort_addon_field *addon_field,
68
66
uchar *buff, uchar *buff_end);
@@ -71,7 +69,6 @@ static bool check_if_pq_applicable(Sort_param *param, SORT_INFO *info,
71
69
ha_rows records, size_t memory_available);
72
70
73
71
void Sort_param::init_for_filesort (uint sortlen, TABLE *table,
74
- ulong max_length_for_sort_data,
75
72
ha_rows maxrows, bool sort_positions)
76
73
{
77
74
DBUG_ASSERT (addon_field == 0 && addon_buf.length == 0 );
@@ -85,8 +82,7 @@ void Sort_param::init_for_filesort(uint sortlen, TABLE *table,
85
82
Get the descriptors of all fields whose values are appended
86
83
to sorted fields and get its total length in addon_buf.length
87
84
*/
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);
90
86
}
91
87
if (addon_field)
92
88
{
@@ -190,9 +186,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
190
186
191
187
param.init_for_filesort (sortlength (thd, filesort->sortorder , s_length,
192
188
&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 );
196
190
197
191
sort->addon_buf = param.addon_buf ;
198
192
sort->addon_field = param.addon_field ;
@@ -1970,7 +1964,7 @@ sortlength(THD *thd, SORT_FIELD *sortorder, uint s_length,
1970
1964
1971
1965
The function first finds out what fields are used in the result set.
1972
1966
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.
1974
1968
If the calculated length is not greater than max_length_for_sort_data
1975
1969
the function allocates memory for an array of descriptors containing
1976
1970
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,
1992
1986
*/
1993
1987
1994
1988
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)
1997
1990
{
1998
1991
Field **pfield;
1999
1992
Field *field;
2000
1993
SORT_ADDON_FIELD *addonf;
2001
1994
uint length= 0 ;
2002
1995
uint fields= 0 ;
2003
1996
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 ;
2005
1999
DBUG_ENTER (" get_addon_fields" );
2006
2000
2007
2001
/*
@@ -2010,14 +2004,14 @@ get_addon_fields(ulong max_length_for_sort_data,
2010
2004
Note for future refinement:
2011
2005
This this a too strong condition.
2012
2006
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
2014
2008
the values directly from sorted fields.
2015
2009
But beware the case when item->cmp_type() != item->result_type()
2016
2010
*/
2017
2011
addon_buf->str = 0 ;
2018
2012
addon_buf->length = 0 ;
2019
2013
2020
- for (pfield= ptabfield ; (field= *pfield) ; pfield++)
2014
+ for (pfield= table-> field ; (field= *pfield) ; pfield++)
2021
2015
{
2022
2016
if (!bitmap_is_set (read_set, field->field_index ))
2023
2017
continue ;
@@ -2027,12 +2021,12 @@ get_addon_fields(ulong max_length_for_sort_data,
2027
2021
if (field->maybe_null ())
2028
2022
null_fields++;
2029
2023
fields++;
2030
- }
2024
+ }
2031
2025
if (!fields)
2032
2026
DBUG_RETURN (0 );
2033
2027
length+= (null_fields+7 )/8 ;
2034
2028
2035
- if (length+sortlength > max_length_for_sort_data ||
2029
+ if (length+sortlength > max_sort_len ||
2036
2030
!my_multi_malloc (MYF (MY_WME | MY_THREAD_SPECIFIC),
2037
2031
&addonf, sizeof (SORT_ADDON_FIELD) * (fields+1 ),
2038
2032
&addon_buf->str , length,
@@ -2043,7 +2037,7 @@ get_addon_fields(ulong max_length_for_sort_data,
2043
2037
addon_buf->length = length;
2044
2038
length= (null_fields+7 )/8 ;
2045
2039
null_fields= 0 ;
2046
- for (pfield= ptabfield ; (field= *pfield) ; pfield++)
2040
+ for (pfield= table-> field ; (field= *pfield) ; pfield++)
2047
2041
{
2048
2042
if (!bitmap_is_set (read_set, field->field_index ))
2049
2043
continue ;
@@ -2065,7 +2059,7 @@ get_addon_fields(ulong max_length_for_sort_data,
2065
2059
addonf++;
2066
2060
}
2067
2061
addonf->field = 0 ; // Put end marker
2068
-
2062
+
2069
2063
DBUG_PRINT (" info" ,(" addon_length: %d" ,length));
2070
2064
DBUG_RETURN (addonf-fields);
2071
2065
}
0 commit comments