diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2020-03-10 04:56:38 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2020-03-10 04:56:38 +0530 |
commit | 1ee8a02307951667874153361d54960cd568efe5 (patch) | |
tree | b37e4d1d9b546dbe5f8bcdecee8b323e517fb336 /sql/sql_class.h | |
parent | 980108ceebdca5c4f6c9e3a167e9ad40cb062ac8 (diff) | |
download | mariadb-git-bb-10.5-mdev6915-ext.tar.gz |
MDEV-21580: Allow packed sort keys in sort bufferbb-10.5-mdev6915-ext
This task deals with packing the sort key inside the sort buffer, which would
lead to efficient usage of the memory allocated for the sort buffer.
The changes brought by this feature are
1) Sort buffers would have sort keys of variable length
2) The format for sort keys inside the sort buffer would look like
|<sort_length><null_byte><key_part1><null_byte><key_part2>.......|
sort_length is the extra bytes that are required to store the variable
length of a sort key.
3) When packing of sort key is done we store the ORIGINAL VALUES inside
the sort buffer and not the STRXFRM form (mem-comparable sort keys).
4) Special comparison function packed_keys_comparison() is introduced
to compare 2 sort keys.
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r-- | sql/sql_class.h | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h index 939dc918003..d756b047ffe 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -6277,8 +6277,52 @@ public: /* Structs used when sorting */ struct SORT_FIELD_ATTR { - uint length; /* Length of sort field */ - uint suffix_length; /* Length suffix (0-4) */ + /* + If using mem-comparable fixed-size keys: + length of the mem-comparable image of the field, in bytes. + + If using packed keys: still the same? Not clear what is the use of it. + */ + uint length; + + /* + For most datatypes, this is 0. + The exception are the VARBINARY columns. + For those columns, the comparison actually compares + + (value_prefix(N), suffix=length(value)) + + Here value_prefix is either the whole value or its prefix if it was too + long, and the suffix is the length of the original value. + (this way, for values X and Y: if X=prefix(Y) then X compares as less + than Y + */ + uint suffix_length; + + /* + If using packed keys, number of bytes that are used to store the length + of the packed key. + + */ + uint length_bytes; + + /* Max. length of the original value, in bytes */ + uint original_length; + enum Type { FIXED_SIZE, VARIABLE_SIZE } 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); + bool check_if_packing_possible(THD *thd) const; + bool is_variable_sized() { return type == VARIABLE_SIZE; } }; |