diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-08-04 07:55:16 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-08-04 07:55:16 +0300 |
commit | 9a7948e3f6d3fd7528e49f43eb4d41f8f55c8a35 (patch) | |
tree | 68f8e54f6c2484dc7791bee8c594d3d07c611d29 /sql/filesort.cc | |
parent | 56990b18d914b8150c9f777d134724d2b3390360 (diff) | |
parent | bbd70fcc43cc889e4593594ee5ca436fe1433aac (diff) | |
download | mariadb-git-9a7948e3f6d3fd7528e49f43eb4d41f8f55c8a35.tar.gz |
Merge 10.5 into 10.6
Diffstat (limited to 'sql/filesort.cc')
-rw-r--r-- | sql/filesort.cc | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc index 03af9c7b49a..1e811473a32 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -316,7 +316,8 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, while (memory_available >= min_sort_memory) { ulonglong keys= memory_available / (param.rec_length + sizeof(char*)); - param.max_keys_per_buffer= (uint) MY_MIN(num_rows, keys); + param.max_keys_per_buffer= (uint) MY_MAX(MERGEBUFF2, + MY_MIN(num_rows, keys)); sort->alloc_sort_buffer(param.max_keys_per_buffer, param.rec_length); if (sort->sort_buffer_size() > 0) break; @@ -2110,9 +2111,7 @@ Type_handler_string_result::sort_length(THD *thd, SORT_FIELD_ATTR *sortorder) const { CHARSET_INFO *cs; - sortorder->length= item->max_length; - set_if_smaller(sortorder->length, thd->variables.max_sort_length); - sortorder->original_length= item->max_length; + sortorder->set_length_and_original_length(thd, item->max_length); if (use_strnxfrm((cs= item->collation.collation))) { @@ -2219,9 +2218,9 @@ sortlength(THD *thd, Sort_keys *sort_keys, bool *allow_packing_for_sortkeys) { Field *field= sortorder->field; CHARSET_INFO *cs= sortorder->field->sort_charset(); - sortorder->length= sortorder->field->sort_length(); + sortorder->set_length_and_original_length(thd, field->sort_length()); + sortorder->suffix_length= sortorder->field->sort_suffix_length(); - sortorder->original_length= sortorder->length; sortorder->type= field->is_packable() ? SORT_FIELD_ATTR::VARIABLE_SIZE : SORT_FIELD_ATTR::FIXED_SIZE; @@ -2554,7 +2553,6 @@ Type_handler_string_result::make_packed_sort_key_part(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, Sort_param *param) const { - CHARSET_INFO *cs= item->collation.collation; bool maybe_null= item->maybe_null; if (maybe_null) @@ -2584,7 +2582,7 @@ Type_handler_string_result::make_packed_sort_key_part(uchar *to, Item *item, return sort_field->original_length; } } - return sort_field->pack_sort_string(to, res->lex_cstring(), cs); + return sort_field->pack_sort_string(to, res); } @@ -2757,6 +2755,14 @@ bool SORT_FIELD_ATTR::check_if_packing_possible(THD *thd) const } +void SORT_FIELD_ATTR::set_length_and_original_length(THD *thd, uint length_arg) +{ + length= length_arg; + set_if_smaller(length, thd->variables.max_sort_length); + original_length= length_arg; +} + + /* Compare function used for packing sort keys */ @@ -2940,13 +2946,12 @@ int compare_packed_sort_keys(void *sort_param, */ uint -SORT_FIELD_ATTR::pack_sort_string(uchar *to, const LEX_CSTRING &str, - CHARSET_INFO *cs) const +SORT_FIELD_ATTR::pack_sort_string(uchar *to, String *str) const { uchar *orig_to= to; uint32 length, data_length; - DBUG_ASSERT(str.length <= UINT32_MAX); - length= (uint32)str.length; + DBUG_ASSERT(str->length() <= UINT32_MAX); + length= (uint32) str->length(); if (length + suffix_length <= original_length) data_length= length; @@ -2957,13 +2962,13 @@ SORT_FIELD_ATTR::pack_sort_string(uchar *to, const LEX_CSTRING &str, store_key_part_length(data_length + suffix_length, to, length_bytes); to+= length_bytes; // copying data length bytes to the buffer - memcpy(to, (uchar*)str.str, data_length); + memcpy(to, (uchar*)str->ptr(), data_length); to+= data_length; - if (cs == &my_charset_bin && suffix_length) + if (str->charset() == &my_charset_bin && suffix_length) { // suffix length stored in bigendian form - store_bigendian(str.length, to, suffix_length); + store_bigendian(length, to, suffix_length); to+= suffix_length; } return static_cast<uint>(to - orig_to); |