Commit 074712ab authored by Varun Gupta's avatar Varun Gupta

More new classes for descriptors

parent 3338818c
...@@ -755,7 +755,7 @@ Aggregator_distinct::packed_key_cmp_single_arg(void *arg, ...@@ -755,7 +755,7 @@ Aggregator_distinct::packed_key_cmp_single_arg(void *arg,
{ {
Aggregator_distinct *aggr= (Aggregator_distinct *) arg; Aggregator_distinct *aggr= (Aggregator_distinct *) arg;
DBUG_ASSERT(aggr->tree); DBUG_ASSERT(aggr->tree);
return aggr->tree->get_descriptor()->compare_keys_for_single_arg(key1, key2); return aggr->tree->get_descriptor()->compare_keys(key1, key2);
} }
...@@ -1078,7 +1078,7 @@ int Aggregator_distinct::insert_record_to_unique() ...@@ -1078,7 +1078,7 @@ int Aggregator_distinct::insert_record_to_unique()
Get compare function for packed keys Get compare function for packed keys
@retval @retval
comparision function comparison function
*/ */
qsort_cmp2 Aggregator_distinct::get_compare_func_for_packed_keys() qsort_cmp2 Aggregator_distinct::get_compare_func_for_packed_keys()
{ {
......
...@@ -1722,7 +1722,7 @@ class Count_distinct_field: public Sql_alloc ...@@ -1722,7 +1722,7 @@ class Count_distinct_field: public Sql_alloc
tree_key_length+= Variable_size_keys_descriptor::size_of_length_field; tree_key_length+= Variable_size_keys_descriptor::size_of_length_field;
tree_key_length+= MY_TEST(table_field->maybe_null()); tree_key_length+= MY_TEST(table_field->maybe_null());
desc= new Variable_size_keys_descriptor(tree_key_length); desc= new Variable_size_keys_simple(tree_key_length);
if (!desc) if (!desc)
return true; // OOM return true; // OOM
tree= new Unique_impl((qsort_cmp2) simple_packed_str_key_cmp, tree= new Unique_impl((qsort_cmp2) simple_packed_str_key_cmp,
...@@ -1838,8 +1838,7 @@ int Count_distinct_field::simple_packed_str_key_cmp(void* arg, ...@@ -1838,8 +1838,7 @@ int Count_distinct_field::simple_packed_str_key_cmp(void* arg,
{ {
Count_distinct_field *compare_arg= (Count_distinct_field*)arg; Count_distinct_field *compare_arg= (Count_distinct_field*)arg;
DBUG_ASSERT(compare_arg->tree->get_descriptor()); DBUG_ASSERT(compare_arg->tree->get_descriptor());
return compare_arg->tree->get_descriptor()-> return compare_arg->tree->get_descriptor()->compare_keys(key1, key2);
compare_keys_for_single_arg(key1, key2);
} }
......
...@@ -877,10 +877,11 @@ int Unique_impl::write_record_to_file(uchar *key) ...@@ -877,10 +877,11 @@ int Unique_impl::write_record_to_file(uchar *key)
Variable_size_keys_descriptor::Variable_size_keys_descriptor(uint length) Variable_size_keys_descriptor::Variable_size_keys_descriptor(uint length)
:sortorder(NULL), sort_keys(NULL)
{ {
key_length= length; max_length= length;
flags= (1 << VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES); flags= (1 << VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES);
sort_keys= NULL;
sortorder= NULL;
packed_rec_ptr= (uchar *)my_malloc(PSI_INSTRUMENT_ME, packed_rec_ptr= (uchar *)my_malloc(PSI_INSTRUMENT_ME,
length, length,
MYF(MY_WME | MY_THREAD_SPECIFIC)); MYF(MY_WME | MY_THREAD_SPECIFIC));
...@@ -963,8 +964,8 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls) ...@@ -963,8 +964,8 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
*/ */
bool bool
Variable_size_keys_descriptor::setup(THD *thd, Item_sum *item, Descriptor::setup(THD *thd, Item_sum *item,
uint non_const_args, uint arg_count) uint non_const_args, uint arg_count)
{ {
SORT_FIELD *sort,*pos; SORT_FIELD *sort,*pos;
if (sortorder) if (sortorder)
...@@ -1009,7 +1010,7 @@ Variable_size_keys_descriptor::setup(THD *thd, Item_sum *item, ...@@ -1009,7 +1010,7 @@ Variable_size_keys_descriptor::setup(THD *thd, Item_sum *item,
FALSE setup successful FALSE setup successful
*/ */
bool Variable_size_keys_descriptor::setup(THD *thd, Field *field) bool Descriptor::setup(THD *thd, Field *field)
{ {
SORT_FIELD *sort,*pos; SORT_FIELD *sort,*pos;
if (sortorder) if (sortorder)
...@@ -1052,8 +1053,15 @@ int Variable_size_keys_descriptor::compare_keys(uchar *a_ptr, ...@@ -1052,8 +1053,15 @@ int Variable_size_keys_descriptor::compare_keys(uchar *a_ptr,
} }
int Variable_size_keys_descriptor::compare_keys_for_single_arg(uchar *a,
uchar *b) Variable_size_keys_simple::Variable_size_keys_simple(uint length)
: Variable_size_keys_descriptor(length)
{
}
int Variable_size_keys_simple::compare_keys(uchar *a, uchar *b)
{ {
return sort_keys->compare_keys_for_single_arg(a + size_of_length_field, return sort_keys->compare_keys_for_single_arg(a + size_of_length_field,
b + size_of_length_field); b + size_of_length_field);
...@@ -1062,6 +1070,8 @@ int Variable_size_keys_descriptor::compare_keys_for_single_arg(uchar *a, ...@@ -1062,6 +1070,8 @@ int Variable_size_keys_descriptor::compare_keys_for_single_arg(uchar *a,
Fixed_size_keys_descriptor::Fixed_size_keys_descriptor(uint length) Fixed_size_keys_descriptor::Fixed_size_keys_descriptor(uint length)
{ {
key_length= length; max_length= length;
flags= (1 << FIXED_SIZED_KEYS); flags= (1 << FIXED_SIZED_KEYS);
sort_keys= NULL;
sortorder= NULL;
} }
...@@ -28,13 +28,25 @@ ...@@ -28,13 +28,25 @@
class Descriptor : public Sql_alloc class Descriptor : public Sql_alloc
{ {
protected: protected:
uint key_length; /* maximum possible size of any key, in bytes */
uint max_length;
enum attributes enum attributes
{ {
FIXED_SIZED_KEYS= 0, FIXED_SIZED_KEYS= 0,
VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES
}; };
uint flags; uint flags;
/*
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;
public: public:
virtual ~Descriptor() {}; virtual ~Descriptor() {};
...@@ -44,14 +56,17 @@ class Descriptor : public Sql_alloc ...@@ -44,14 +56,17 @@ class Descriptor : public Sql_alloc
return flags & (1 << VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES); return flags & (1 << VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES);
} }
virtual int compare_keys(uchar *a, uchar *b) = 0; virtual int compare_keys(uchar *a, uchar *b) = 0;
virtual int compare_keys_for_single_arg(uchar *a, uchar *b) = 0;
// Fill structures like sort_keys, sortorder
virtual bool setup(THD *thd, Item_sum *item, virtual bool setup(THD *thd, Item_sum *item,
uint non_const_args, uint arg_count) { return false; } uint non_const_args, uint arg_count);
virtual bool setup(THD *thd, Field *field) { return false; } virtual bool setup(THD *thd, Field *field);
virtual Sort_keys *get_keys() { return sort_keys; }
SORT_FIELD *get_sortorder() { return sortorder; }
/* need to be moved to a separate class */
virtual uchar *get_packed_rec_ptr() { return NULL; } virtual uchar *get_packed_rec_ptr() { return NULL; }
virtual uint make_packed_record(bool exclude_nulls) { return 0; } virtual uint make_packed_record(bool exclude_nulls) { return 0; }
virtual Sort_keys *get_keys() { return NULL; }
SORT_FIELD *get_sortorder() { return NULL; }
}; };
...@@ -63,9 +78,17 @@ class Fixed_size_keys_descriptor : public Descriptor ...@@ -63,9 +78,17 @@ class Fixed_size_keys_descriptor : public Descriptor
public: public:
Fixed_size_keys_descriptor(uint length); Fixed_size_keys_descriptor(uint length);
~Fixed_size_keys_descriptor() {} ~Fixed_size_keys_descriptor() {}
uint get_length_of_key(uchar *ptr) override { return key_length; } uint get_length_of_key(uchar *ptr) override { return max_length; }
virtual int compare_keys(uchar *a, uchar *b) override { return 0; }
};
class Fixed_size_keys_simple_descriptor : public Fixed_size_keys_descriptor
{
public:
Fixed_size_keys_simple_descriptor(uint length);
~Fixed_size_keys_simple_descriptor() {}
int compare_keys(uchar *a, uchar *b) override { return 0; } int compare_keys(uchar *a, uchar *b) override { return 0; }
int compare_keys_for_single_arg(uchar *a, uchar *b) override { return 0; }
}; };
...@@ -74,6 +97,7 @@ class Fixed_size_keys_descriptor : public Descriptor ...@@ -74,6 +97,7 @@ class Fixed_size_keys_descriptor : public Descriptor
*/ */
class Variable_size_keys_descriptor : public Descriptor class Variable_size_keys_descriptor : public Descriptor
{ {
protected:
/* /*
Packed record ptr for a record of the table, the packed value in this Packed record ptr for a record of the table, the packed value in this
record is added to the unique tree record is added to the unique tree
...@@ -82,18 +106,6 @@ class Variable_size_keys_descriptor : public Descriptor ...@@ -82,18 +106,6 @@ class Variable_size_keys_descriptor : public Descriptor
String tmp_buffer; 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;
public: public:
Variable_size_keys_descriptor(uint length); Variable_size_keys_descriptor(uint length);
~Variable_size_keys_descriptor(); ~Variable_size_keys_descriptor();
...@@ -108,12 +120,7 @@ class Variable_size_keys_descriptor : public Descriptor ...@@ -108,12 +120,7 @@ class Variable_size_keys_descriptor : public Descriptor
return read_packed_length(ptr); return read_packed_length(ptr);
} }
int compare_keys(uchar *a, uchar *b) override; 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 // returns the length of the key along with the length bytes for the key
static uint read_packed_length(uchar *p) static uint read_packed_length(uchar *p)
{ {
...@@ -128,6 +135,17 @@ class Variable_size_keys_descriptor : public Descriptor ...@@ -128,6 +135,17 @@ class Variable_size_keys_descriptor : public Descriptor
}; };
/* Descriptor for variable size keys with only one component */
class Variable_size_keys_simple : public Variable_size_keys_descriptor
{
public:
Variable_size_keys_simple(uint length);
~Variable_size_keys_simple() {}
int compare_keys(uchar *a, uchar *b) override;
};
/* /*
Unique -- An abstract class for unique (removing duplicates). Unique -- An abstract class for unique (removing duplicates).
*/ */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment