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/filesort.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/filesort.h')
-rw-r--r-- | sql/filesort.h | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/sql/filesort.h b/sql/filesort.h index 5102ee2326f..9f71da02c96 100644 --- a/sql/filesort.h +++ b/sql/filesort.h @@ -25,9 +25,12 @@ class THD; struct TABLE; class Filesort_tracker; struct SORT_FIELD; +struct SORT_FIELD_ATTR; typedef struct st_order ORDER; class JOIN; class Addon_fields; +class Sort_keys; + /** Sorting related info. @@ -57,6 +60,7 @@ public: bool sort_positions; Filesort_tracker *tracker; + Sort_keys *sort_keys; Filesort(ORDER *order_arg, ha_rows limit_arg, bool sort_positions_arg, SQL_SELECT *select_arg): @@ -66,14 +70,15 @@ public: select(select_arg), own_select(false), using_pq(false), - sort_positions(sort_positions_arg) + sort_positions(sort_positions_arg), + sort_keys(NULL) { DBUG_ASSERT(order); }; ~Filesort() { cleanup(); } /* Prepare ORDER BY list for sorting. */ - uint make_sortorder(THD *thd, JOIN *join, table_map first_table_bit); + Sort_keys* make_sortorder(THD *thd, JOIN *join, table_map first_table_bit); private: void cleanup(); @@ -88,6 +93,7 @@ class SORT_INFO public: SORT_INFO() :addon_fields(NULL), record_pointers(0), + sort_keys(NULL), sorted_result_in_fsbuf(FALSE) { buffpek.str= 0; @@ -121,6 +127,7 @@ public: LEX_STRING buffpek; /* Buffer for buffpek structures */ Addon_fields *addon_fields; /* Addon field descriptors */ uchar *record_pointers; /* If sorted in memory */ + Sort_keys *sort_keys; /* Sort key descriptors*/ /** If the entire result of filesort fits in memory, we skip the merge phase. @@ -201,6 +208,7 @@ public: template<bool Packed_addon_fields> inline void unpack_addon_fields(uchar *buff); + bool using_packed_sortkeys(); friend SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, Filesort_tracker* tracker, JOIN *join, @@ -216,5 +224,8 @@ bool filesort_use_addons(TABLE *table, uint sortlength, uint *m_packable_length); void change_double_for_sort(double nr,uchar *to); +void store_length(uchar *to, uint length, uint pack_length); +void +reverse_key(uchar *to, const SORT_FIELD_ATTR *sort_field); #endif /* FILESORT_INCLUDED */ |