diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2020-11-21 04:07:55 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2020-11-21 05:03:19 +0530 |
commit | a4b29ac1e6edc9b61ba00a085f55503969153689 (patch) | |
tree | 468afc97f12111061e1b5b82432a8fe6f2339615 | |
parent | 1e5533e070c4b7cfcfaabaac936e076f3c732999 (diff) | |
download | mariadb-git-10.5-mdev21829-unique-interface.tar.gz |
more-changes 210.5-mdev21829-unique-interface
-rw-r--r-- | sql/filesort.cc | 182 | ||||
-rw-r--r-- | sql/item_sum.cc | 65 | ||||
-rw-r--r-- | sql/item_sum.h | 11 | ||||
-rw-r--r-- | sql/sql_sort.h | 42 | ||||
-rw-r--r-- | sql/sql_statistics.cc | 18 | ||||
-rw-r--r-- | sql/uniques.cc | 178 | ||||
-rw-r--r-- | sql/uniques.h | 39 |
7 files changed, 230 insertions, 305 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc index 0ee1b85d1e7..4949d63c6d2 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -3243,185 +3243,3 @@ static uint make_packed_sortkey(Sort_param *param, uchar *to) Sort_keys::store_sortkey_length(orig_to, length); return length; } - - -Variable_sized_keys::Variable_sized_keys(uint size): - packed_rec_ptr(NULL), - sortorder(NULL), sort_keys(NULL), - key_length(size) -{ - packed_rec_ptr= (uchar *)my_malloc(PSI_INSTRUMENT_ME, - size, - MYF(MY_WME | MY_THREAD_SPECIFIC)); - tmp_buffer.alloc(size); -} - - -Variable_sized_keys::~Variable_sized_keys() -{ - my_free(packed_rec_ptr); -} - - -/* - @brief - Setup the structures that are used when Unique stores packed values - - @param thd thread structure - @param item item of aggregate function - @param non_const_args number of non constant arguments - @param arg_count total number of arguments - - @note - This implementation is used by GROUP_CONCAT and COUNT_DISTINCT - as it can have more than one arguments in the argument list. - - @retval - TRUE error - FALSE setup successful -*/ - -bool -Variable_sized_keys::setup(THD *thd, Item_sum *item, - uint non_const_args, uint arg_count) -{ - SORT_FIELD *sort,*pos; - if (sortorder) - return false; - DBUG_ASSERT(sort_keys == NULL); - sortorder= (SORT_FIELD*) thd->alloc(sizeof(SORT_FIELD) * non_const_args); - pos= sort= sortorder; - if (!pos) - return true; - sort_keys= new Sort_keys(sortorder, non_const_args); - if (!sort_keys) - return true; - sort=pos= sortorder; - for (uint i= 0; i < arg_count; i++) - { - Item *arg= item->get_arg(i); - if (arg->const_item()) - continue; - - if (arg->type() == Item::FIELD_ITEM) - { - Field *field= ((Item_field*)arg)->field; - pos->setup(field, false); - } - else - pos->setup(arg, false); - pos++; - } - return false; -} - - -/* - @brief - Setup the structures that are used when Unique stores packed values - - @param thd thread structure - @param field field structure - - @retval - TRUE error - FALSE setup successful -*/ - -bool Variable_sized_keys::setup(THD *thd, Field *field) -{ - SORT_FIELD *sort,*pos; - if (sortorder) - return false; - - DBUG_ASSERT(sort_keys == NULL); - sortorder= (SORT_FIELD*) thd->alloc(sizeof(SORT_FIELD)); - pos= sort= sortorder; - if (!pos) - return true; - sort_keys= new Sort_keys(sortorder, 1); - if (!sort_keys) - return true; - sort=pos= sortorder; - pos->setup(field, false); // Nulls are always excluded - - return false; -} - - -/* - @brief - Compare two packed keys inside the Unique tree - - @param a_ptr packed sort key - @param b_ptr packed sort key - - @retval - >0 key a_ptr greater than b_ptr - =0 key a_ptr equal to b_ptr - <0 key a_ptr less than b_ptr - -*/ - -int Variable_sized_keys::compare_packed_keys(uchar *a_ptr, uchar *b_ptr) -{ - return sort_keys->compare_keys(a_ptr + size_of_length_field, - b_ptr + size_of_length_field); -} - - -int Variable_sized_keys::compare_keys_for_single_arg(uchar *a, uchar *b) -{ - return sort_keys->compare_keys_for_single_arg(a + size_of_length_field, - b + size_of_length_field); -} - - -/* - @brief - Make a record with packed values for a key - - @retval - 0 NULL value - >0 length of the packed record -*/ -uint Variable_sized_keys::make_packed_record(bool exclude_nulls) -{ - Field *field; - SORT_FIELD *sort_field; - uint length; - uchar *orig_to, *to; - orig_to= to= packed_rec_ptr; - to+= size_of_length_field; - - for (sort_field=sort_keys->begin() ; - sort_field != sort_keys->end() ; - sort_field++) - { - bool maybe_null=0; - if ((field=sort_field->field)) - { - // Field - length= field->make_packed_sort_key_part(to, sort_field); - } - else - { // Item - Item *item= sort_field->item; - length= item->type_handler()->make_packed_sort_key_part(to, item, - sort_field, - &tmp_buffer); - } - - if ((maybe_null= sort_field->maybe_null)) - { - if (exclude_nulls && length == 0) - return 0; // NULL value - to++; - } - to+= length; - } - - length= static_cast<int>(to - orig_to); - store_packed_length(orig_to, length); - return length; -} diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 8df2b8adce5..972a428978a 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -723,8 +723,8 @@ Aggregator_distinct::composite_packed_key_cmp(void* arg, uchar* key1, uchar* key2) { Aggregator_distinct *aggr= (Aggregator_distinct *) arg; - DBUG_ASSERT(aggr->variable_sized_keys); - return aggr->variable_sized_keys->compare_packed_keys(key1, key2); + DBUG_ASSERT(aggr->tree); + return aggr->tree->get_descriptor()->compare_keys(key1, key2); } @@ -746,8 +746,8 @@ int Aggregator_distinct::packed_key_cmp_single_arg(void *arg, uchar *key1, uchar *key2) { Aggregator_distinct *aggr= (Aggregator_distinct *) arg; - DBUG_ASSERT(aggr->variable_sized_keys); - return aggr->variable_sized_keys->compare_keys_for_single_arg(key1, key2); + DBUG_ASSERT(aggr->tree); + return aggr->tree->get_descriptor()->compare_keys_for_single_arg(key1, key2); } @@ -924,10 +924,6 @@ bool Aggregator_distinct::setup(THD *thd) { compare_key= get_compare_func_for_packed_keys(); cmp_arg= (void*)this; - - variable_sized_keys= new Variable_sized_keys(tree_key_length); - if (variable_sized_keys == NULL) - return true; } DBUG_ASSERT(tree == 0); @@ -1044,10 +1040,10 @@ int Aggregator_distinct::insert_record_to_unique() if (tree->is_packed()) { uint packed_length; - if ((packed_length= variable_sized_keys->make_packed_record(true)) == 0) + if ((packed_length= tree->get_descriptor()->make_packed_record(true)) == 0) return -1; // NULL value DBUG_ASSERT(packed_length <= tree->get_size()); - return tree->unique_add(variable_sized_keys->get_packed_rec_ptr()); + return tree->unique_add(tree->get_descriptor()->get_packed_rec_ptr()); } copy_fields(tmp_table_param); @@ -1920,11 +1916,6 @@ Aggregator_distinct::~Aggregator_distinct() delete tmp_table_param; tmp_table_param= NULL; } - if (variable_sized_keys) - { - delete variable_sized_keys; - variable_sized_keys= NULL; - } } @@ -3761,10 +3752,10 @@ int group_concat_packed_key_cmp_with_distinct(void *arg, { Item_func_group_concat *item_func= (Item_func_group_concat*)arg; - DBUG_ASSERT(item_func->variable_sized_keys); + DBUG_ASSERT(item_func->unique_filter); uchar *a= (uchar*)a_ptr; uchar *b= (uchar*)b_ptr; - return item_func->variable_sized_keys->compare_packed_keys(a, b); + return item_func->unique_filter->get_descriptor()->compare_keys(a, b); } @@ -4040,7 +4031,7 @@ Item_func_group_concat::dump_leaf_variable_sized_key(void *key_arg, uint old_length= result->length(); SORT_FIELD *pos; - pos= item->variable_sized_keys->get_sortorder(); + pos= item->unique_filter->get_descriptor()->get_sortorder(); key_end= key + item->unique_filter->get_full_size(); key+= Variable_sized_keys_descriptor::size_of_length_field; @@ -4163,8 +4154,7 @@ Item_func_group_concat(THD *thd, Name_resolution_context *context_arg, warning_for_row(FALSE), force_copy_fields(0), row_limit(NULL), offset_limit(NULL), limit_clause(limit_clause), - copy_offset_limit(0), copy_row_limit(0), original(0), - variable_sized_keys(NULL) + copy_offset_limit(0), copy_row_limit(0), original(0) { Item *item_select; Item **arg_ptr; @@ -4233,8 +4223,7 @@ Item_func_group_concat::Item_func_group_concat(THD *thd, force_copy_fields(item->force_copy_fields), row_limit(item->row_limit), offset_limit(item->offset_limit), limit_clause(item->limit_clause),copy_offset_limit(item->copy_offset_limit), - copy_row_limit(item->copy_row_limit), original(item), - variable_sized_keys(item->variable_sized_keys) + copy_row_limit(item->copy_row_limit), original(item) { quick_group= item->quick_group; result.set_charset(collation.collation); @@ -4296,11 +4285,6 @@ void Item_func_group_concat::cleanup() delete unique_filter; unique_filter= NULL; } - if (variable_sized_keys) - { - delete variable_sized_keys; - variable_sized_keys= NULL; - } } DBUG_ASSERT(tree == 0); } @@ -4695,13 +4679,6 @@ bool Item_func_group_concat::setup(THD *thd) tree_len= 0; } - if (allow_packing) - { - variable_sized_keys= new Variable_sized_keys(tree_key_length); - if (variable_sized_keys == NULL) - DBUG_RETURN(TRUE); //OOM - } - if (distinct) { unique_filter= get_unique(get_comparator_function_for_distinct(allow_packing), @@ -4709,10 +4686,10 @@ bool Item_func_group_concat::setup(THD *thd) tree_key_length + get_null_bytes(), ram_limitation(thd), 0, allow_packing); - if (!unique_filter || (variable_sized_keys && - variable_sized_keys->setup(thd, this, - non_const_items, - arg_count_field))) + if (!unique_filter || + (unique_filter->get_descriptor()->setup(thd, this, + non_const_items, + arg_count_field))) DBUG_RETURN(TRUE); } if ((row_limit && row_limit->cmp_type() != INT_RESULT) || @@ -4750,7 +4727,7 @@ String* Item_func_group_concat::val_str(String* str) tree_walk(tree, &dump_leaf_key, this, left_root_right); else if (distinct) // distinct (and no order by). unique_filter->walk(table, - variable_sized_keys ? + unique_filter->is_packed() ? dump_leaf_variable_sized_key : dump_leaf_key, this); else if (row_limit && copy_row_limit == (ulonglong)row_limit->val_int()) @@ -4810,7 +4787,7 @@ qsort_cmp2 Item_func_group_concat::get_comparator_function_for_order_by() uchar* Item_func_group_concat::get_record_pointer() { return is_distinct_packed() ? - variable_sized_keys->get_packed_rec_ptr() : + unique_filter->get_descriptor()->get_packed_rec_ptr() : (skip_nulls() ? table->record[0] + table->s->null_bytes : table->record[0]); @@ -4845,8 +4822,6 @@ uint Item_func_group_concat::get_null_bytes() bool Item_func_group_concat::is_distinct_packed() { - DBUG_ASSERT((variable_sized_keys != NULL) == - (unique_filter && unique_filter->is_packed())); return unique_filter && unique_filter->is_packed(); } @@ -5027,10 +5002,12 @@ int Item_func_group_concat::insert_record_to_unique() if (unique_filter->is_packed()) { uint packed_length; - if ((packed_length= variable_sized_keys->make_packed_record(skip_nulls())) == 0) + if ((packed_length= unique_filter->get_descriptor()-> + make_packed_record(skip_nulls())) == 0) return -1; // NULL value DBUG_ASSERT(packed_length <= unique_filter->get_size()); - return unique_filter->unique_add(variable_sized_keys->get_packed_rec_ptr()); + return unique_filter->unique_add(unique_filter->get_descriptor() + ->get_packed_rec_ptr()); } copy_fields(tmp_table_param); diff --git a/sql/item_sum.h b/sql/item_sum.h index e7d86137d8c..9bb07bfda52 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -312,7 +312,6 @@ class Window_spec; but still return false from Item_sum::const_item(). */ class Unique_impl; -class Variable_sized_keys; class Item_sum :public Item_func_or_sum { @@ -682,16 +681,10 @@ class Aggregator_distinct : public Aggregator */ bool use_distinct_values; - /* - Used to store information about variable sized keys - @see sql_sort.h for the class definition - */ - Variable_sized_keys *variable_sized_keys; - public: Aggregator_distinct (Item_sum *sum) : Aggregator(sum), table(NULL), tmp_table_param(NULL), tree(NULL), - always_null(false), use_distinct_values(false), variable_sized_keys(NULL) {} + always_null(false), use_distinct_values(false) {} virtual ~Aggregator_distinct (); Aggregator_type Aggrtype() { return DISTINCT_AGGREGATOR; } @@ -1919,8 +1912,6 @@ protected: */ Item_func_group_concat *original; - Variable_sized_keys *variable_sized_keys; - /* Used by Item_func_group_concat and Item_func_json_arrayagg. The latter needs null values but the former doesn't. diff --git a/sql/sql_sort.h b/sql/sql_sort.h index 342add1445b..b9efe53aa79 100644 --- a/sql/sql_sort.h +++ b/sql/sql_sort.h @@ -718,47 +718,5 @@ void reuse_freed_buff(QUEUE *queue, Merge_chunk *reuse, uint key_length); <keypart1_value> : the value for the keypart. */ -class Variable_sized_keys : public Sql_alloc -{ - /* - Packed record ptr for a record of the table, the packed value in this - record is added to the unique tree - */ - uchar* packed_rec_ptr; - - String tmp_buffer; - - /* - Array of SORT_FIELD structure storing the information about the key parts - in the sort key of the Unique tree - @see Unique::setup() - */ - SORT_FIELD *sortorder; - - /* - Structure storing information about usage of keys - */ - Sort_keys *sort_keys; - - uint key_length; - -public: - Variable_sized_keys(uint size); - ~Variable_sized_keys(); - - uchar *get_packed_rec_ptr() { return packed_rec_ptr; } - Sort_keys *get_keys() { return sort_keys; } - SORT_FIELD *get_sortorder() { return sortorder; } - bool setup(THD *thd, Item_sum *item, uint non_const_args, uint arg_count); - bool setup(THD *thd, Field *field); - uint make_packed_record(bool exclude_nulls); - int compare_packed_keys(uchar *a, uchar *b); - int compare_keys_for_single_arg(uchar *a, uchar *b); - static void store_packed_length(uchar *p, uint sz) - { - int4store(p, sz - size_of_length_field); - } - static const uint size_of_length_field= 4; -}; #endif /* SQL_SORT_INCLUDED */ diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index d6125ce37c7..8dda3b27b8c 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -1657,7 +1657,6 @@ protected: ulonglong distincts; ulonglong distincts_single_occurence; - Variable_sized_keys *variable_size_keys; public: @@ -1683,15 +1682,12 @@ public: table_field= field; tree_key_length= 0; tree= NULL; - variable_size_keys= NULL; } virtual ~Count_distinct_field() { delete tree; tree= NULL; - delete variable_size_keys; - variable_size_keys= NULL; } /* @@ -1720,9 +1716,6 @@ public: tree_key_length+= Variable_sized_keys_descriptor::size_of_length_field; tree_key_length+= MY_TEST(table_field->maybe_null()); - variable_size_keys= new Variable_sized_keys(tree_key_length); - if (!variable_size_keys) - return true; // OOM Descriptor *desc= new Variable_sized_keys_descriptor(tree_key_length); if (!desc) @@ -1732,7 +1725,7 @@ public: max_heap_table_size, 1, desc); if (!tree) return true; // OOM - return variable_size_keys->setup(thd, table_field); + return tree->get_descriptor()->setup(thd, table_field); } tree_key_length= table_field->pack_length(); @@ -1758,11 +1751,10 @@ public: uint length= tree->get_size(); if (tree->is_packed()) { - DBUG_ASSERT(variable_size_keys); - length= variable_size_keys->make_packed_record(true); + length= tree->get_descriptor()->make_packed_record(true); DBUG_ASSERT(length != 0); DBUG_ASSERT(length <= tree->get_size()); - return tree->unique_add(variable_size_keys->get_packed_rec_ptr()); + return tree->unique_add(tree->get_descriptor()->get_packed_rec_ptr()); } return tree->unique_add(table_field->ptr); } @@ -1840,8 +1832,8 @@ int Count_distinct_field::simple_packed_str_key_cmp(void* arg, uchar* key1, uchar* key2) { Count_distinct_field *compare_arg= (Count_distinct_field*)arg; - DBUG_ASSERT(compare_arg->variable_size_keys); - return compare_arg->variable_size_keys->compare_keys_for_single_arg(key1, key2); + DBUG_ASSERT(compare_arg->tree->get_descriptor()); + return compare_arg->tree->get_descriptor()->compare_keys_for_single_arg(key1, key2); } diff --git a/sql/uniques.cc b/sql/uniques.cc index 082bacceff4..3da78f8d5ab 100644 --- a/sql/uniques.cc +++ b/sql/uniques.cc @@ -374,6 +374,7 @@ Unique_impl::~Unique_impl() close_cached_file(&file); delete_tree(&tree, 0); delete_dynamic(&file_ptrs); + delete m_descriptor; } @@ -876,9 +877,186 @@ int Unique_impl::write_record_to_file(uchar *key) Variable_sized_keys_descriptor::Variable_sized_keys_descriptor(uint length) + :sortorder(NULL), sort_keys(NULL) { key_length= length; flags= (1 << VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES); + packed_rec_ptr= (uchar *)my_malloc(PSI_INSTRUMENT_ME, + length, + MYF(MY_WME | MY_THREAD_SPECIFIC)); + tmp_buffer.alloc(length); +} + + +Variable_sized_keys_descriptor::~Variable_sized_keys_descriptor() +{ + my_free(packed_rec_ptr); +} + + +/* + @brief + Make a record with packed values for a key + + @retval + 0 NULL value + >0 length of the packed record +*/ +uint Variable_sized_keys_descriptor::make_packed_record(bool exclude_nulls) +{ + Field *field; + SORT_FIELD *sort_field; + uint length; + uchar *orig_to, *to; + orig_to= to= packed_rec_ptr; + to+= size_of_length_field; + + for (sort_field=sort_keys->begin() ; + sort_field != sort_keys->end() ; + sort_field++) + { + bool maybe_null=0; + if ((field=sort_field->field)) + { + // Field + length= field->make_packed_sort_key_part(to, sort_field); + } + else + { // Item + Item *item= sort_field->item; + length= item->type_handler()->make_packed_sort_key_part(to, item, + sort_field, + &tmp_buffer); + } + + if ((maybe_null= sort_field->maybe_null)) + { + if (exclude_nulls && length == 0) + return 0; // NULL value + to++; + } + to+= length; + } + + length= static_cast<int>(to - orig_to); + store_packed_length(orig_to, length); + return length; +} + + +/* + @brief + Setup the structures that are used when Unique stores packed values + + @param thd thread structure + @param item item of aggregate function + @param non_const_args number of non constant arguments + @param arg_count total number of arguments + + @note + This implementation is used by GROUP_CONCAT and COUNT_DISTINCT + as it can have more than one arguments in the argument list. + + @retval + TRUE error + FALSE setup successful +*/ + +bool +Variable_sized_keys_descriptor::setup(THD *thd, Item_sum *item, + uint non_const_args, uint arg_count) +{ + SORT_FIELD *sort,*pos; + if (sortorder) + return false; + DBUG_ASSERT(sort_keys == NULL); + sortorder= (SORT_FIELD*) thd->alloc(sizeof(SORT_FIELD) * non_const_args); + pos= sort= sortorder; + if (!pos) + return true; + sort_keys= new Sort_keys(sortorder, non_const_args); + if (!sort_keys) + return true; + sort=pos= sortorder; + for (uint i= 0; i < arg_count; i++) + { + Item *arg= item->get_arg(i); + if (arg->const_item()) + continue; + + if (arg->type() == Item::FIELD_ITEM) + { + Field *field= ((Item_field*)arg)->field; + pos->setup(field, false); + } + else + pos->setup(arg, false); + pos++; + } + return false; +} + + +/* + @brief + Setup the structures that are used when Unique stores packed values + + @param thd thread structure + @param field field structure + + @retval + TRUE error + FALSE setup successful +*/ + +bool Variable_sized_keys_descriptor::setup(THD *thd, Field *field) +{ + SORT_FIELD *sort,*pos; + if (sortorder) + return false; + + DBUG_ASSERT(sort_keys == NULL); + sortorder= (SORT_FIELD*) thd->alloc(sizeof(SORT_FIELD)); + pos= sort= sortorder; + if (!pos) + return true; + sort_keys= new Sort_keys(sortorder, 1); + if (!sort_keys) + return true; + sort=pos= sortorder; + pos->setup(field, false); // Nulls are always excluded + + return false; +} + + +/* + @brief + Compare two packed keys inside the Unique tree + + @param a_ptr packed sort key + @param b_ptr packed sort key + + @retval + >0 key a_ptr greater than b_ptr + =0 key a_ptr equal to b_ptr + <0 key a_ptr less than b_ptr + +*/ + +int Variable_sized_keys_descriptor::compare_keys(uchar *a_ptr, + uchar *b_ptr) +{ + return sort_keys->compare_keys(a_ptr + size_of_length_field, + b_ptr + size_of_length_field); +} + + +int Variable_sized_keys_descriptor::compare_keys_for_single_arg(uchar *a, + uchar *b) +{ + return sort_keys->compare_keys_for_single_arg(a + size_of_length_field, + b + size_of_length_field); } diff --git a/sql/uniques.h b/sql/uniques.h index 551c6d5411c..acbc7ef364b 100644 --- a/sql/uniques.h +++ b/sql/uniques.h @@ -39,14 +39,15 @@ public: return flags & (1 << VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES); } virtual int compare_keys(uchar *a, uchar *b) = 0; - bool setup(THD *thd, Item_sum *item, uint non_const_args, uint arg_count) - { - return false; - } - bool setup(THD *thd, Field *field) - { - return false; - } + virtual int compare_keys_for_single_arg(uchar *a, uchar *b) = 0; + virtual bool setup(THD *thd, Item_sum *item, + uint non_const_args, uint arg_count) { return false; } + virtual bool setup(THD *thd, Field *field) { return false; } + virtual uchar *get_packed_rec_ptr() { return NULL; } + virtual uint make_packed_record(bool exclude_nulls) { return 0; } + virtual Sort_keys *get_keys() { return NULL; } + SORT_FIELD *get_sortorder() { return NULL; } + }; @@ -57,6 +58,7 @@ public: ~Fixed_sized_keys_descriptor() {} uint get_length_of_key(uchar *ptr) override { return key_length; } int compare_keys(uchar *a, uchar *b) override { return 0; } + int compare_keys_for_single_arg(uchar *a, uchar *b) override { return 0; } }; @@ -68,6 +70,8 @@ class Variable_sized_keys_descriptor : public Descriptor */ uchar* packed_rec_ptr; + String tmp_buffer; + /* Array of SORT_FIELD structure storing the information about the key parts in the sort key of the Unique tree @@ -82,26 +86,33 @@ class Variable_sized_keys_descriptor : public Descriptor public: Variable_sized_keys_descriptor(uint length); - ~Variable_sized_keys_descriptor() {} + ~Variable_sized_keys_descriptor(); uchar *get_packed_rec_ptr() { return packed_rec_ptr; } Sort_keys *get_keys() { return sort_keys; } SORT_FIELD *get_sortorder() { return sortorder; } - // Fill structures like sort_keys, sortorder - bool setup() {return false;} - uint make_packed_record(bool exclude_nulls) {return 0;} + uint make_packed_record(bool exclude_nulls); uint get_length_of_key(uchar *ptr) override { return read_packed_length(ptr); } - int compare_keys(uchar *a, uchar *b) override { return 0; } - int compare_keys_for_single_arg(uchar *a, uchar *b) { return 0;} + int compare_keys(uchar *a, uchar *b) override; + int compare_keys_for_single_arg(uchar *a, uchar *b); + + // Fill structures like sort_keys, sortorder + bool setup(THD *thd, Item_sum *item, + uint non_const_args, uint arg_count); + bool setup(THD *thd, Field *field); // returns the length of the key along with the length bytes for the key static uint read_packed_length(uchar *p) { return size_of_length_field + uint4korr(p); } + void store_packed_length(uchar *p, uint sz) + { + int4store(p, sz - size_of_length_field); + } static const uint size_of_length_field= 4; }; |