Commit 23bd5607 authored by Varun Gupta's avatar Varun Gupta

Working on descriptors for variable sized keys

parent 1e9b0a4e
......@@ -1064,6 +1064,32 @@ Field::make_packed_sort_key_part(uchar *buff,
}
uint
Field::make_packed_key_part(uchar *buff, const SORT_FIELD_ATTR *sort_field)
{
if (maybe_null())
{
if (is_null())
{
*buff++= 0;
return 0; // For NULL values don't write any data
}
*buff++=1;
}
memcpy(buff, ptr, sort_field->original_length);
return sort_field->original_length;
}
uint
Field_longstr::make_packed_key_part(uchar *buff,
const SORT_FIELD_ATTR *sort_field)
{
return make_packed_sort_key_part(buff, sort_field);
}
uint
Field_longstr::make_packed_sort_key_part(uchar *buff,
const SORT_FIELD_ATTR *sort_field)
......
......@@ -1468,6 +1468,9 @@ class Field: public Value_source
virtual uint make_packed_sort_key_part(uchar *buff,
const SORT_FIELD_ATTR *sort_field);
virtual uint make_packed_key_part(uchar *buff,
const SORT_FIELD_ATTR *sort_field);
virtual void make_send_field(Send_field *);
/*
......@@ -2213,6 +2216,8 @@ class Field_longstr :public Field_str
bool is_packable() const override { return true; }
uint make_packed_sort_key_part(uchar *buff,
const SORT_FIELD_ATTR *sort_field)override;
uint make_packed_key_part(uchar *buff,
const SORT_FIELD_ATTR *sort_field) override;
uchar* pack_sort_string(uchar *to, const SORT_FIELD_ATTR *sort_field);
};
......
......@@ -2587,7 +2587,7 @@ uint32 Sort_param::get_record_length_for_unique(uchar *to,
{
if (!using_packed_sortkeys())
return rec_length;
return Variable_size_keys_descriptor::read_packed_length(to) +
return Variable_size_composite_key_desc::read_packed_length(to) +
size_of_dupl_count;
}
......@@ -3018,6 +3018,28 @@ int SORT_FIELD_ATTR::compare_packed_fixed_size_vals(uchar *a, size_t *a_len,
}
int SORT_FIELD::compare_fixed_size_vals(uchar *a, size_t *a_len,
uchar *b, size_t *b_len)
{
if (maybe_null)
{
*a_len=1;
*b_len=1;
int cmp_val;
if ((cmp_val= compare_nullability(a, b)) || *a == 0)
return cmp_val;
a++;
b++;
}
else
*a_len= *b_len= 0;
*a_len+= length;
*b_len+= length;
return field->cmp(a, b);
}
/*
@brief
Comparison function to compare two packed sort keys
......
......@@ -974,7 +974,7 @@ void Aggregator_distinct::clear()
@retval
-1 NULL value, record rejected
0 record succesfully inserted into the tree
0 record successfully inserted into the tree
1 error
*/
int Aggregator_distinct::insert_record_to_unique()
......@@ -3921,7 +3921,7 @@ Item_func_group_concat::dump_leaf_variable_sized_key(void *key_arg,
pos= item->unique_filter->get_descriptor()->get_sortorder();
key_end= key + item->unique_filter->get_full_size();
key+= Variable_size_keys_descriptor::size_of_length_field;
key+= Variable_size_composite_key_desc::size_of_length_field;
ulonglong *offset_limit= &item->copy_offset_limit;
ulonglong *row_limit = &item->copy_row_limit;
......@@ -4794,7 +4794,7 @@ bool Item_sum::is_packing_allowed(TABLE *table, uint* total_length)
Unique::size_of_lengt_field is the length bytes to store the packed length
for each record inserted in the Unique tree
*/
(*total_length)+= Variable_size_keys_descriptor::size_of_length_field +
(*total_length)+= Variable_size_composite_key_desc::size_of_length_field +
size_of_packable_fields;
return true;
}
......@@ -4817,7 +4817,7 @@ Item_sum::get_unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
if (number_of_args == 1)
desc= new Variable_size_keys_simple(size_arg);
else
desc= new Variable_size_keys_descriptor(size_arg);
desc= new Variable_size_composite_key_desc(size_arg);
}
else
{
......@@ -4850,7 +4850,7 @@ Item_func_group_concat::get_unique(qsort_cmp2 comp_func,
if (number_of_args == 1)
desc= new Variable_size_keys_simple(size_arg);
else
desc= new Variable_size_keys_descriptor(size_arg);
desc= new Variable_size_composite_key_desc(size_arg);
}
else
{
......
......@@ -6461,6 +6461,8 @@ struct SORT_FIELD: public SORT_FIELD_ATTR
void setup(Field *fld, bool with_suffix);
void setup(Item *item, bool with_suffix);
void setup_for_fixed_size_keys(Field *fld);
int compare_fixed_size_vals(uchar *a, size_t *a_len,
uchar *b, size_t *b_len);
};
......
......@@ -1527,7 +1527,7 @@ class Stat_table_write_iter
*/
uint get_offset_to_value(Field *field)
{
return Variable_size_keys_descriptor::size_of_length_field +
return Variable_size_composite_key_desc::size_of_length_field +
MY_TEST(field->maybe_null());
}
......@@ -1538,7 +1538,7 @@ uint get_offset_to_value(Field *field)
*/
uchar* get_buffer_end(Field *field, uchar *to)
{
return to + Variable_size_keys_descriptor::read_packed_length(to);
return to + Variable_size_composite_key_desc::read_packed_length(to);
}
......@@ -1719,7 +1719,7 @@ class Count_distinct_field: public Sql_alloc
tree_key_length= table_field->
max_packed_col_length(table_field->pack_length());
tree_key_length+= Variable_size_keys_descriptor::size_of_length_field;
tree_key_length+= Variable_size_composite_key_desc::size_of_length_field;
tree_key_length+= MY_TEST(table_field->maybe_null());
desc= new Variable_size_keys_simple(tree_key_length);
......
......@@ -876,7 +876,7 @@ int Unique_impl::write_record_to_file(uchar *key)
}
Variable_size_keys_descriptor::Variable_size_keys_descriptor(uint length)
Variable_size_composite_key_desc::Variable_size_composite_key_desc(uint length)
{
max_length= length;
flags= (1 << VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES);
......@@ -889,7 +889,7 @@ Variable_size_keys_descriptor::Variable_size_keys_descriptor(uint length)
}
Variable_size_keys_descriptor::~Variable_size_keys_descriptor()
Variable_size_composite_key_desc::~Variable_size_composite_key_desc()
{
my_free(packed_rec_ptr);
}
......@@ -903,7 +903,7 @@ Variable_size_keys_descriptor::~Variable_size_keys_descriptor()
0 NULL value
>0 length of the packed record
*/
uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
uint Variable_size_composite_key_desc::make_packed_record(bool exclude_nulls)
{
Field *field;
SORT_FIELD *sort_field;
......@@ -920,7 +920,7 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
if ((field=sort_field->field))
{
// Field
length= field->make_packed_sort_key_part(to, sort_field);
length= field->make_packed_key_part(to, sort_field);
}
else
{ // Item
......@@ -939,7 +939,7 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
to+= length;
}
length= static_cast<int>(to - orig_to);
length= static_cast<uint>(to - orig_to);
store_packed_length(orig_to, length);
return length;
}
......@@ -964,7 +964,7 @@ uint Variable_size_keys_descriptor::make_packed_record(bool exclude_nulls)
*/
bool
Variable_size_keys_descriptor::setup(THD *thd, Item_sum *item,
Variable_size_composite_key_desc::setup(THD *thd, Item_sum *item,
uint non_const_args, uint arg_count)
{
SORT_FIELD *sort,*pos;
......@@ -1010,7 +1010,7 @@ Variable_size_keys_descriptor::setup(THD *thd, Item_sum *item,
FALSE setup successful
*/
bool Variable_size_keys_descriptor::setup(THD *thd, Field *field)
bool Variable_size_composite_key_desc::setup(THD *thd, Field *field)
{
SORT_FIELD *sort,*pos;
if (sortorder)
......@@ -1044,11 +1044,27 @@ bool Variable_size_keys_descriptor::setup(THD *thd, Field *field)
*/
int Variable_size_keys_descriptor::compare_keys(uchar *a_ptr,
int Variable_size_composite_key_desc::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);
uchar *a= a_ptr + Variable_size_composite_key_desc::size_of_length_field;
uchar *b= b_ptr + Variable_size_composite_key_desc::size_of_length_field;
int retval= 0;
size_t a_len, b_len;
for (SORT_FIELD *sort_field= sort_keys->begin();
sort_field != sort_keys->end(); sort_field++)
{
retval= sort_field->is_variable_sized() ?
sort_field->compare_packed_varstrings(a, &a_len, b, &b_len) :
sort_field->compare_packed_fixed_size_vals(a, &a_len, b, &b_len);
if (retval)
return sort_field->reverse ? -retval : retval;
a+= a_len;
b+= b_len;
}
return retval;
}
......@@ -1060,7 +1076,7 @@ int Variable_size_keys_simple::compare_keys(uchar *a, uchar *b)
Variable_size_keys_simple::Variable_size_keys_simple(uint length)
: Variable_size_keys_descriptor(length)
: Variable_size_composite_key_desc(length)
{}
......
......@@ -161,10 +161,53 @@ class Fixed_size_composite_keys_descriptor : public Fixed_size_keys_descriptor
};
class Encode_record : public Sql_alloc
{
private:
/*
Packed record ptr for a record of the table, the packed value in this
record is added to the unique tree
*/
uchar* rec_ptr;
String tmp_buffer;
public:
Encode_record()
{
rec_ptr= NULL;
}
virtual ~Encode_record() {}
virtual uint make_record() { return 0; }
uchar *get_packed_rec_ptr() { return rec_ptr; }
};
class Encode_record_for_count_distinct : public Encode_record
{
public:
Encode_record_for_count_distinct()
: Encode_record() {}
~Encode_record_for_count_distinct() {}
uint make_record() override { return 0; }
};
class Encode_record_for_group_concat : public Encode_record
{
public:
Encode_record_for_group_concat():Encode_record() {}
~Encode_record_for_group_concat() {}
uint make_record() override { return 0; }
};
/*
Descriptor for variable size keys
*/
class Variable_size_keys_descriptor : public Descriptor
class Variable_size_composite_key_desc : public Descriptor
{
protected:
/*
......@@ -176,8 +219,8 @@ class Variable_size_keys_descriptor : public Descriptor
String tmp_buffer;
public:
Variable_size_keys_descriptor(uint length);
virtual ~Variable_size_keys_descriptor();
Variable_size_composite_key_desc(uint length);
virtual ~Variable_size_composite_key_desc();
Sort_keys *get_keys() { return sort_keys; }
SORT_FIELD *get_sortorder() { return sortorder; }
......@@ -209,7 +252,7 @@ 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
class Variable_size_keys_simple : public Variable_size_composite_key_desc
{
public:
Variable_size_keys_simple(uint length);
......
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