diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/field.cc | 24 | ||||
-rw-r--r-- | sql/field.h | 13 | ||||
-rw-r--r-- | sql/filesort.cc | 108 | ||||
-rw-r--r-- | sql/filesort.h | 8 | ||||
-rw-r--r-- | sql/sql_class.h | 15 | ||||
-rw-r--r-- | sql/sql_type.h | 6 |
6 files changed, 56 insertions, 118 deletions
diff --git a/sql/field.cc b/sql/field.cc index 5416520bfcf..527de2fe20b 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -1084,30 +1084,6 @@ Field_longstr::pack_sort_string(uchar *to, const SORT_FIELD_ATTR *sort_field) } -/* - The default implementation assumes values are fixed-size and compared with - memcmp. -*/ - -int -Field::compare_packed_sort_keys(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD *sortorder)const -{ - return compare_packed_fixed_size_vals(a, a_len, b, b_len, sortorder, - sortorder->field->maybe_null()); -} - - -int -Field_longstr::compare_packed_sort_keys(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD *sortorder) const -{ - return compare_packed_varstrings(charset(), a, a_len, b, b_len, sortorder, - sortorder->field->maybe_null()); -} - /** @brief Determine the relative position of the field value in a numeric interval diff --git a/sql/field.h b/sql/field.h index 3d134a640d9..2bdf55ba395 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1428,16 +1428,6 @@ public: */ virtual uint make_packed_sort_key(uchar *buff, const SORT_FIELD_ATTR *sort_field); - /* - Compare two packed sort keys - @param a Pointer to key - @param a_len OUT The length of the value stored. This is only - reliable when a compares as equal to b. - The same for b. - */ - virtual int compare_packed_sort_keys(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD *sortorder) const; virtual void make_send_field(Send_field *); virtual void sort_string(uchar *buff,uint length)=0; virtual bool optimize_range(uint idx, uint part) const; @@ -2168,9 +2158,6 @@ public: const Item *item, bool is_eq_func) const; bool is_packable() override { return true; } - int compare_packed_sort_keys(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD *sortorder)const override; uint make_packed_sort_key(uchar *buff, const SORT_FIELD_ATTR *sort_field)override; uchar* pack_sort_string(uchar *to, const SORT_FIELD_ATTR *sort_field); diff --git a/sql/filesort.cc b/sql/filesort.cc index 3b9b66495ab..57a7a60e704 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -2212,13 +2212,15 @@ sortlength(THD *thd, Sort_keys *sort_keys, bool *multi_byte_charset, sortorder->length= sortorder->field->sort_length(); sortorder->suffix_length= sortorder->field->sort_suffix_length(); sortorder->original_length= sortorder->length; + sortorder->fixed_type= !field->is_packable(); + sortorder->cs= cs; if (use_strnxfrm((cs=sortorder->field->sort_charset()))) { *multi_byte_charset= true; sortorder->length= (uint) cs->strnxfrmlen(sortorder->length); } - if (field->is_packable() && allow_packing_for_keys) + if (!sortorder->fixed_type && allow_packing_for_keys) { allow_packing_for_keys= check_if_packing_possible(thd, cs, sortorder); sortorder->length_bytes= @@ -2226,7 +2228,7 @@ sortlength(THD *thd, Sort_keys *sort_keys, bool *multi_byte_charset, thd->variables.max_sort_length)); } - if (sortorder->field->maybe_null()) + if ((sortorder->maybe_null= sortorder->field->maybe_null())) nullable_cols++; // Place for NULL marker } else @@ -2234,12 +2236,13 @@ sortlength(THD *thd, Sort_keys *sort_keys, bool *multi_byte_charset, CHARSET_INFO *cs; sortorder->item->type_handler()->sort_length(thd, sortorder->item, sortorder); + sortorder->fixed_type= !sortorder->item->type_handler()->is_packable(); if (use_strnxfrm((cs=sortorder->item->collation.collation))) { *multi_byte_charset= true; } - if (sortorder->item->type_handler()->is_packable() && - allow_packing_for_keys) + sortorder->cs= cs; + if (!sortorder->fixed_type && allow_packing_for_keys) { allow_packing_for_keys= check_if_packing_possible(thd, cs, sortorder); sortorder->length_bytes= @@ -2247,7 +2250,7 @@ sortlength(THD *thd, Sort_keys *sort_keys, bool *multi_byte_charset, thd->variables.max_sort_length)); } - if (sortorder->item->maybe_null) + if ((sortorder->maybe_null= sortorder->item->maybe_null)) nullable_cols++; // Place for NULL marker } set_if_smaller(sortorder->length, thd->variables.max_sort_length); @@ -2529,6 +2532,7 @@ void Sort_param::try_to_pack_sortkeys() rec_length= sort_length + addon_length; } + uint Type_handler_string_result::make_packed_sort_key(uchar *to, Item *item, const SORT_FIELD_ATTR *sort_field, @@ -2689,31 +2693,6 @@ Type_handler_timestamp_common::make_packed_sort_key(uchar *to, Item *item, } -int -Type_handler_string_result::compare_packed_sort_keys(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD *sortorder)const -{ - return compare_packed_varstrings(sortorder->item->collation.collation, - a, a_len, b, b_len, sortorder, - sortorder->item->maybe_null); -} - - -/* - The default implementation assumes values are fixed-size and compared with - memcmp. -*/ -int -Type_handler::compare_packed_sort_keys(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD *sortorder)const -{ - return compare_packed_fixed_size_vals(a, a_len, b, b_len, sortorder, - sortorder->item->maybe_null); -} - - /* @brief Reverse the key for DESC clause @@ -2785,10 +2764,8 @@ qsort2_cmp get_packed_keys_compare_ptr() suffix_bytes are used only for binary columns. */ -int compare_packed_varstrings(CHARSET_INFO *cs, uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD_ATTR *sort_field, - bool maybe_null) +int SORT_FIELD_ATTR::compare_packed_varstrings(uchar *a, size_t *a_len, + uchar *b, size_t *b_len) { int retval; size_t a_length, b_length; @@ -2815,24 +2792,24 @@ int compare_packed_varstrings(CHARSET_INFO *cs, uchar *a, size_t *a_len, else *a_len= *b_len= 0; - a_length= read_lowendian(a, sort_field->length_bytes); - b_length= read_lowendian(b, sort_field->length_bytes); + a_length= read_lowendian(a, length_bytes); + b_length= read_lowendian(b, length_bytes); - *a_len+= sort_field->length_bytes + a_length; - *b_len+= sort_field->length_bytes + b_length; + *a_len+= length_bytes + a_length; + *b_len+= length_bytes + b_length; - retval= cs->strnncollsp(a + sort_field->length_bytes, - a_length - sort_field->suffix_length, - b + sort_field->length_bytes, - b_length - sort_field->suffix_length); + retval= cs->strnncollsp(a + length_bytes, + a_length - suffix_length, + b + length_bytes, + b_length - suffix_length); - if (!retval && sort_field->suffix_length) + if (!retval && suffix_length) { DBUG_ASSERT(cs == &my_charset_bin); // comparing the length stored in suffix bytes for binary strings - a= a + sort_field->length_bytes + a_length - sort_field->suffix_length; - b= b + sort_field->length_bytes + b_length - sort_field->suffix_length; - retval= memcmp(a, b, sort_field->suffix_length); + a= a + length_bytes + a_length - suffix_length; + b= b + length_bytes + b_length - suffix_length; + retval= memcmp(a, b, suffix_length); } return retval; @@ -2846,10 +2823,8 @@ int compare_packed_varstrings(CHARSET_INFO *cs, uchar *a, size_t *a_len, This is used for ordering fixed-size columns when the sorting procedure used packed-value format. */ -int compare_packed_fixed_size_vals(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD_ATTR *sort_field, - bool maybe_null) +int SORT_FIELD_ATTR::compare_packed_fixed_size_vals(uchar *a, size_t *a_len, + uchar *b, size_t *b_len) { if (maybe_null) { @@ -2873,9 +2848,9 @@ int compare_packed_fixed_size_vals(uchar *a, size_t *a_len, else *a_len= *b_len= 0; - *a_len+= sort_field->length; - *b_len+= sort_field->length; - return memcmp(a,b, sort_field->length); + *a_len+= length; + *b_len+= length; + return memcmp(a,b, length); } @@ -2895,7 +2870,7 @@ int compare_packed_fixed_size_vals(uchar *a, size_t *a_len, */ int compare_packed_sort_keys(void *sort_param, - unsigned char **a_ptr, unsigned char **b_ptr) + unsigned char **a_ptr, unsigned char **b_ptr) { int retval= 0; size_t a_len, b_len; @@ -2909,19 +2884,9 @@ int compare_packed_sort_keys(void *sort_param, for (SORT_FIELD *sort_field= sort_keys->begin(); sort_field != sort_keys->end(); sort_field++) { - if (sort_field->field) - { - retval= sort_field->field->compare_packed_sort_keys(a, &a_len, - b, &b_len, - sort_field); - } - else - { - Item *item= sort_field->item; - retval= item->type_handler()->compare_packed_sort_keys(a, &a_len, - b, &b_len, - sort_field); - } + retval= sort_field->fixed_type ? + sort_field->compare_packed_fixed_size_vals(a, &a_len, b, &b_len): + sort_field->compare_packed_varstrings(a, &a_len, b, &b_len); if (retval) return sort_field->reverse ? -retval : retval; @@ -2941,6 +2906,9 @@ int compare_packed_sort_keys(void *sort_param, } +/* + TODO varun: add comments here +*/ uint SORT_FIELD_ATTR::pack_sort_string(uchar *to, const LEX_CSTRING &str, CHARSET_INFO *cs) const @@ -2971,6 +2939,9 @@ SORT_FIELD_ATTR::pack_sort_string(uchar *to, const LEX_CSTRING &str, } +/* + TODO varun: add comments here +*/ static uint make_sortkey(Sort_param *param, uchar *to) { Field *field; @@ -3007,6 +2978,9 @@ static uint make_sortkey(Sort_param *param, uchar *to) } +/* + TODO varun: add comments here +*/ static uint make_packed_sortkey(Sort_param *param, uchar *to) { Field *field; diff --git a/sql/filesort.h b/sql/filesort.h index 2d219921b73..9e0e86d2ff0 100644 --- a/sql/filesort.h +++ b/sql/filesort.h @@ -225,14 +225,6 @@ bool filesort_use_addons(TABLE *table, uint sortlength, void change_double_for_sort(double nr,uchar *to); void store_length(uchar *to, uint length, uint pack_length); -int compare_packed_fixed_size_vals(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD_ATTR *sort_field, - bool maybe_null); -int compare_packed_varstrings(CHARSET_INFO *cs, uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD_ATTR *sort_field, - bool maybe_null); void reverse_key(uchar *to, bool maybe_null, const SORT_FIELD_ATTR *sort_field); bool check_if_packing_possible(THD *thd, CHARSET_INFO *cs, diff --git a/sql/sql_class.h b/sql/sql_class.h index 1413c360b61..9862ced5728 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -6284,8 +6284,23 @@ struct SORT_FIELD_ATTR /* Max. length of the original value, in bytes */ uint original_length; + /* + FALSE : for packable datatypes like CHAR, VARCHAR and BLOBS + TRUE : otherwise + */ + bool fixed_type; + /* + TRUE : if the item or field is NULLABLE + FALSE : otherwise + */ + bool maybe_null; + CHARSET_INFO *cs; uint pack_sort_string(uchar *to, const LEX_CSTRING &str, CHARSET_INFO *cs) const; + int compare_packed_fixed_size_vals(uchar *a, size_t *a_len, + uchar *b, size_t *b_len); + int compare_packed_varstrings(uchar *a, size_t *a_len, + uchar *b, size_t *b_len); }; diff --git a/sql/sql_type.h b/sql/sql_type.h index 8fcbd8ccdb2..3481cd4c2b2 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -3773,9 +3773,6 @@ public: const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const= 0; virtual bool is_packable() const { return false; } - virtual int compare_packed_sort_keys(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD *sortorder) const; /* create a compact sort key which can be compared with a comparison @@ -5089,9 +5086,6 @@ public: void sort_length(THD *thd, const Type_std_attributes *item, SORT_FIELD_ATTR *attr) const override; - int compare_packed_sort_keys(uchar *a, size_t *a_len, - uchar *b, size_t *b_len, - const SORT_FIELD *sortorder) const override; bool is_packable()const override { return true; } bool union_element_finalize(const Item * item) const override; uint calc_key_length(const Column_definition &def) const override; |