summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVarun Gupta <varun.gupta@mariadb.com>2020-05-30 16:58:42 +0530
committerVarun Gupta <varun.gupta@mariadb.com>2020-05-30 16:58:42 +0530
commit8c9430a3fd152c0dfa4dcfe144b49a3b61e81eee (patch)
tree82e4b51c646af29358cb292326b8d6694993c39e
parent9983582a6ab55caf9944d78d857cfdbbd64156d8 (diff)
downloadmariadb-git-10.5-mdev22303.tar.gz
Changed Sort_param::tmp_buffer from char* to String10.5-mdev22303
-rw-r--r--sql/filesort.cc40
-rw-r--r--sql/sql_sort.h3
2 files changed, 12 insertions, 31 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 468b57479fb..6fa9b192655 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -58,7 +58,6 @@ static bool save_index(Sort_param *param, uint count,
SORT_INFO *table_sort);
static uint suffix_length(ulong string_length);
static uint sortlength(THD *thd, Sort_keys *sortorder,
- bool *multi_byte_charset,
bool *allow_packing_for_sortkeys);
static Addon_fields *get_addon_fields(TABLE *table, uint sortlength,
uint *addon_length,
@@ -200,7 +199,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
ha_rows num_rows= HA_POS_ERROR;
IO_CACHE tempfile, buffpek_pointers, *outfile;
Sort_param param;
- bool multi_byte_charset, allow_packing_for_sortkeys;
+ bool allow_packing_for_sortkeys;
Bounded_queue<uchar, uchar> pq;
SQL_SELECT *const select= filesort->select;
ha_rows max_rows= filesort->limit;
@@ -248,8 +247,7 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
sort->found_rows= HA_POS_ERROR;
param.sort_keys= sort_keys;
- uint sort_len= sortlength(thd, sort_keys, &multi_byte_charset,
- &allow_packing_for_sortkeys);
+ uint sort_len= sortlength(thd, sort_keys, &allow_packing_for_sortkeys);
param.init_for_filesort(sort_len, table, max_rows, filesort->sort_positions);
@@ -339,11 +337,8 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
tracker->report_addon_fields_format(param.using_packed_addons());
}
- if ((multi_byte_charset || param.using_packed_sortkeys()) &&
- !(param.tmp_buffer= (char*) my_malloc(key_memory_Sort_param_tmp_buffer,
- param.sort_length,
- MYF(MY_WME | MY_THREAD_SPECIFIC))))
- goto err;
+ if (param.tmp_buffer.alloc(param.sort_length))
+ goto err;
if (open_cached_file(&buffpek_pointers,mysql_tmpdir,TEMP_PREFIX,
DISK_BUFFER_SIZE, MYF(MY_WME)))
@@ -438,7 +433,6 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
error= 0;
err:
- my_free(param.tmp_buffer);
if (!subselect || !subselect->is_uncacheable())
{
if (!param.using_addon_fields())
@@ -1101,10 +1095,8 @@ Type_handler_string_result::make_sort_key_part(uchar *to, Item *item,
if (maybe_null)
*to++= 1;
- char *tmp_buffer= param->tmp_buffer ? param->tmp_buffer : (char*) to;
- String tmp(tmp_buffer, param->tmp_buffer ? param->sort_length :
- sort_field->length, cs);
- String *res= item->str_result(&tmp);
+
+ String *res= item->str_result(&param->tmp_buffer);
if (!res)
{
if (maybe_null)
@@ -2181,8 +2173,6 @@ Type_handler_decimal_result::sort_length(THD *thd,
@param thd Thread handler
@param sortorder Order of items to sort
@param s_length Number of items to sort
- @param[out] multi_byte_charset Set to 1 if we are using multi-byte charset
- (In which case we have to use strxnfrm())
@param allow_packing_for_sortkeys [out] set to false if packing sort keys is not
allowed
@@ -2196,11 +2186,9 @@ Type_handler_decimal_result::sort_length(THD *thd,
*/
static uint
-sortlength(THD *thd, Sort_keys *sort_keys, bool *multi_byte_charset,
- bool *allow_packing_for_sortkeys)
+sortlength(THD *thd, Sort_keys *sort_keys, bool *allow_packing_for_sortkeys)
{
uint length;
- *multi_byte_charset= 0;
*allow_packing_for_sortkeys= true;
bool allow_packing_for_keys= true;
@@ -2226,10 +2214,8 @@ sortlength(THD *thd, Sort_keys *sort_keys, bool *multi_byte_charset,
sortorder->cs= cs;
if (use_strnxfrm((cs=sortorder->field->sort_charset())))
- {
- *multi_byte_charset= true;
sortorder->length= (uint) cs->strnxfrmlen(sortorder->length);
- }
+
if (sortorder->is_variable_sized() && allow_packing_for_keys)
{
allow_packing_for_keys= sortorder->check_if_packing_possible(thd);
@@ -2243,17 +2229,12 @@ sortlength(THD *thd, Sort_keys *sort_keys, bool *multi_byte_charset,
}
else
{
- CHARSET_INFO *cs;
sortorder->item->type_handler()->sort_length(thd, sortorder->item,
sortorder);
sortorder->type= sortorder->item->type_handler()->is_packable() ?
SORT_FIELD_ATTR::VARIABLE_SIZE :
SORT_FIELD_ATTR::FIXED_SIZE;
- if (use_strnxfrm((cs=sortorder->item->collation.collation)))
- {
- *multi_byte_charset= true;
- }
- sortorder->cs= cs;
+ sortorder->cs= sortorder->item->collation.collation;
if (sortorder->is_variable_sized() && allow_packing_for_keys)
{
allow_packing_for_keys= sortorder->check_if_packing_possible(thd);
@@ -2565,8 +2546,7 @@ Type_handler_string_result::make_packed_sort_key_part(uchar *to, Item *item,
if (maybe_null)
*to++= 1;
- String tmp(param->tmp_buffer, param->sort_length, cs);
- String *res= item->str_result(&tmp);
+ String *res= item->str_result(&param->tmp_buffer);
if (!res)
{
if (maybe_null)
diff --git a/sql/sql_sort.h b/sql/sql_sort.h
index 5b3f5a67d17..cff54f18bde 100644
--- a/sql/sql_sort.h
+++ b/sql/sql_sort.h
@@ -536,7 +536,7 @@ public:
uchar *unique_buff;
bool not_killable;
- char* tmp_buffer;
+ String tmp_buffer;
// The fields below are used only by Unique class.
qsort2_cmp compare;
BUFFPEK_COMPARE_CONTEXT cmp_context;
@@ -544,6 +544,7 @@ public:
Sort_param()
{
memset(reinterpret_cast<void*>(this), 0, sizeof(*this));
+ tmp_buffer.set_thread_specific();
}
void init_for_filesort(uint sortlen, TABLE *table,
ha_rows maxrows, bool sort_positions);