Commit 67546a26 authored by Varun Gupta's avatar Varun Gupta

trying setup for fixed size descriptors

parent 5876acb3
......@@ -2834,12 +2834,28 @@ void SORT_FIELD::setup(Item *item_arg, bool with_suffix)
}
void SORT_FIELD::setup_for_fixed_size_keys(Field *fld)
{
field= fld;
item= NULL;
reverse= false;
SORT_FIELD_ATTR::setup_for_fixed_size_keys(fld);
}
void SORT_FIELD_ATTR::setup_for_fixed_size_keys(Field *field)
{
original_length= length= field->pack_length();
cs= field->charset();
suffix_length= 0;
type= SORT_FIELD_ATTR::FIXED_SIZE;
maybe_null= field->maybe_null();
length_bytes= 0;
}
void SORT_FIELD_ATTR::setup(Field *fld, bool with_suffix)
{
/*
For unique needs to be set to FALSE always
but we can even pass the reverse as an argument to the function
*/
original_length= length= (with_suffix ?
fld->sort_length() :
fld->sort_length_without_suffix());
......
......@@ -6448,6 +6448,7 @@ struct SORT_FIELD_ATTR
bool check_if_packing_possible(THD *thd) const;
bool is_variable_sized() { return type == VARIABLE_SIZE; }
void setup(Field *fld, bool with_suffix);
void setup_for_fixed_size_keys(Field *fld);
int compare_nullability(uchar *a, uchar *b);
};
......@@ -6459,6 +6460,7 @@ struct SORT_FIELD: public SORT_FIELD_ATTR
bool reverse; /* if descending sort */
void setup(Field *fld, bool with_suffix);
void setup(Item *item, bool with_suffix);
void setup_for_fixed_size_keys(Field *fld);
};
......
......@@ -1725,7 +1725,7 @@ class Count_distinct_field: public Sql_alloc
desc= new Variable_size_keys_simple(tree_key_length);
if (!desc)
return true; // OOM
tree= new Unique_impl((qsort_cmp2) simple_packed_str_key_cmp,
tree= new Unique_impl((qsort_cmp2) key_cmp,
(void*) this, tree_key_length,
max_heap_table_size, 1, desc);
if (!tree)
......@@ -1734,12 +1734,15 @@ class Count_distinct_field: public Sql_alloc
}
tree_key_length= table_field->pack_length();
desc= new Fixed_size_keys_descriptor(tree_key_length);
desc= new Fixed_size_keys_simple(tree_key_length);
if (!desc)
return true; // OOM
tree= new Unique_impl((qsort_cmp2) simple_str_key_cmp, (void*) table_field,
tree= new Unique_impl((qsort_cmp2) key_cmp, (void*) this,
tree_key_length, max_heap_table_size, 1, desc);
return tree == NULL;
if (!tree)
return true; // OOM
return tree->get_descriptor()->setup(thd, table_field);
}
......@@ -1816,7 +1819,7 @@ class Count_distinct_field: public Sql_alloc
return table_field->collected_stats->histogram.get_values();
}
static int simple_packed_str_key_cmp(void* arg, uchar* key1, uchar* key2);
static int key_cmp(void* arg, uchar* key1, uchar* key2);
};
/*
......@@ -1832,9 +1835,9 @@ class Count_distinct_field: public Sql_alloc
@retval = 0 if key1 = key2
@retval > 0 if key1 > key2
*/
int Count_distinct_field::simple_packed_str_key_cmp(void* arg,
uchar* key1,
uchar* key2)
int Count_distinct_field::key_cmp(void* arg,
uchar* key1,
uchar* key2)
{
Count_distinct_field *compare_arg= (Count_distinct_field*)arg;
DBUG_ASSERT(compare_arg->tree->get_descriptor());
......
......@@ -1083,6 +1083,21 @@ Fixed_size_keys_descriptor::setup(THD *thd, Item_sum *item,
bool
Fixed_size_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_for_fixed_size_keys(field);
return false;
}
......@@ -1100,3 +1115,8 @@ Fixed_size_keys_descriptor::Fixed_size_keys_descriptor(uint length)
sort_keys= NULL;
sortorder= NULL;
}
Fixed_size_keys_simple::Fixed_size_keys_simple(uint length)
:Fixed_size_keys_descriptor(length)
{}
......@@ -77,7 +77,7 @@ class Fixed_size_keys_descriptor : public Descriptor
{
public:
Fixed_size_keys_descriptor(uint length);
~Fixed_size_keys_descriptor() {}
virtual ~Fixed_size_keys_descriptor() {}
uint get_length_of_key(uchar *ptr) override { return max_length; }
bool setup(THD *thd, Field *field);
bool setup(THD *thd, Item_sum *item,
......@@ -111,7 +111,7 @@ class Variable_size_keys_descriptor : public Descriptor
public:
Variable_size_keys_descriptor(uint length);
~Variable_size_keys_descriptor();
virtual ~Variable_size_keys_descriptor();
Sort_keys *get_keys() { return sort_keys; }
SORT_FIELD *get_sortorder() { return sortorder; }
......
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