Commit 7a1d56eb authored by Varun Gupta's avatar Varun Gupta

Attempt to use an Encoder class

parent 23bd5607
......@@ -982,10 +982,10 @@ int Aggregator_distinct::insert_record_to_unique()
if (tree->is_variable_sized())
{
uint packed_length;
if ((packed_length= tree->get_descriptor()->make_packed_record(true)) == 0)
if ((packed_length= tree->get_descriptor()->make_record(true)) == 0)
return -1; // NULL value
DBUG_ASSERT(packed_length <= tree->get_size());
return tree->unique_add(tree->get_descriptor()->get_packed_rec_ptr());
return tree->unique_add(tree->get_descriptor()->get_rec_ptr());
}
copy_fields(tmp_table_param);
......@@ -4676,7 +4676,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() ?
unique_filter->get_descriptor()->get_packed_rec_ptr() :
unique_filter->get_descriptor()->get_rec_ptr() :
(skip_nulls() ?
table->record[0] + table->s->null_bytes :
table->record[0]);
......@@ -4935,11 +4935,11 @@ int Item_func_group_concat::insert_record_to_unique()
{
uint packed_length;
if ((packed_length= unique_filter->get_descriptor()->
make_packed_record(skip_nulls())) == 0)
make_record(skip_nulls())) == 0)
return -1; // NULL value
DBUG_ASSERT(packed_length <= unique_filter->get_size());
return unique_filter->unique_add(unique_filter->get_descriptor()
->get_packed_rec_ptr());
->get_rec_ptr());
}
copy_fields(tmp_table_param);
......
......@@ -1758,10 +1758,10 @@ class Count_distinct_field: public Sql_alloc
uint length= tree->get_size();
if (tree->is_variable_sized())
{
length= tree->get_descriptor()->make_packed_record(true);
length= tree->get_descriptor()->make_record(true);
DBUG_ASSERT(length != 0);
DBUG_ASSERT(length <= tree->get_size());
return tree->unique_add(tree->get_descriptor()->get_packed_rec_ptr());
return tree->unique_add(tree->get_descriptor()->get_rec_ptr());
}
return tree->unique_add(table_field->ptr);
}
......
......@@ -876,25 +876,32 @@ int Unique_impl::write_record_to_file(uchar *key)
}
Variable_size_composite_key_desc::Variable_size_composite_key_desc(uint length)
Variable_size_keys_descriptor::Variable_size_keys_descriptor(uint length)
{
max_length= length;
flags= (1 << VARIABLE_SIZED_KEYS_WITH_ORIGINAL_VALUES);
sort_keys= NULL;
sortorder= NULL;
packed_rec_ptr= (uchar *)my_malloc(PSI_INSTRUMENT_ME,
length,
MYF(MY_WME | MY_THREAD_SPECIFIC));
tmp_buffer.alloc(length);
}
Variable_size_keys_descriptor::~Variable_size_keys_descriptor()
{
}
Variable_size_composite_key_desc::Variable_size_composite_key_desc(uint length)
: Variable_size_keys_descriptor(length)
{
}
Variable_size_composite_key_desc::~Variable_size_composite_key_desc()
Variable_size_keys_simple::Variable_size_keys_simple(uint length)
: Variable_size_keys_descriptor(length)
{
my_free(packed_rec_ptr);
}
/*
@brief
Make a record with packed values for a key
......@@ -903,7 +910,7 @@ Variable_size_composite_key_desc::~Variable_size_composite_key_desc()
0 NULL value
>0 length of the packed record
*/
uint Variable_size_composite_key_desc::make_packed_record(bool exclude_nulls)
/*uint Variable_size_composite_key_desc::make_record(bool exclude_nulls)
{
Field *field;
SORT_FIELD *sort_field;
......@@ -943,7 +950,7 @@ uint Variable_size_composite_key_desc::make_packed_record(bool exclude_nulls)
store_packed_length(orig_to, length);
return length;
}
*/
/*
@brief
......@@ -964,8 +971,8 @@ uint Variable_size_composite_key_desc::make_packed_record(bool exclude_nulls)
*/
bool
Variable_size_composite_key_desc::setup(THD *thd, Item_sum *item,
uint non_const_args, uint arg_count)
Variable_size_keys_descriptor::setup(THD *thd, Item_sum *item,
uint non_const_args, uint arg_count)
{
SORT_FIELD *sort,*pos;
if (sortorder)
......@@ -1010,7 +1017,7 @@ Variable_size_composite_key_desc::setup(THD *thd, Item_sum *item,
FALSE setup successful
*/
bool Variable_size_composite_key_desc::setup(THD *thd, Field *field)
bool Variable_size_keys_descriptor::setup(THD *thd, Field *field)
{
SORT_FIELD *sort,*pos;
if (sortorder)
......@@ -1075,11 +1082,6 @@ int Variable_size_keys_simple::compare_keys(uchar *a, uchar *b)
}
Variable_size_keys_simple::Variable_size_keys_simple(uint length)
: Variable_size_composite_key_desc(length)
{}
/* FIXED SIZE KEYS DESCRIPTOR */
......
......@@ -65,8 +65,8 @@ class Descriptor : public Sql_alloc
SORT_FIELD *get_sortorder() { return sortorder; }
/* need to be moved to a separate class */
virtual uchar *get_packed_rec_ptr() { return NULL; }
virtual uint make_packed_record(bool exclude_nulls) { return 0; }
virtual uchar *get_rec_ptr() { return NULL; }
virtual uint make_record(bool exclude_nulls) { return 0; }
};
......@@ -172,67 +172,58 @@ class Encode_record : public Sql_alloc
uchar* rec_ptr;
String tmp_buffer;
Sort_keys *sort_keys;
public:
Encode_record()
Encode_record(Sort_keys *keys)
{
sort_keys= keys;
rec_ptr= NULL;
}
virtual ~Encode_record() {}
virtual uint make_record() { return 0; }
virtual uint make_record(bool exclude_nulls) { 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(Sort_keys *keys)
: Encode_record(keys) {}
~Encode_record_for_count_distinct() {}
uint make_record() override { return 0; }
uint make_record(bool exclude_nulls) 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(Sort_keys *keys)
: Encode_record(keys) {}
~Encode_record_for_group_concat() {}
uint make_record() override { return 0; }
};
uint make_record(bool exclude_nulls) override { return 0; }
};
/*
Descriptor for variable size keys
*/
class Variable_size_composite_key_desc : public Descriptor
{
protected:
/*
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;
class Variable_size_keys_descriptor : public Descriptor
{
public:
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; }
bool setup(THD *thd, Item_sum *item, uint non_const_args, uint arg_count);
bool setup(THD *thd, Field *field);
Variable_size_keys_descriptor(uint length);
virtual ~Variable_size_keys_descriptor();
uint get_length_of_key(uchar *ptr) override
{
return read_packed_length(ptr);
}
int compare_keys(uchar *a, uchar *b) override;
uint make_record(bool exclude_nulls) { return 0;}
uchar *get_packed_rec_ptr() { return NULL; }
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);
virtual int compare_keys(uchar *a, uchar *b) override { return 0; }
// All need to be moved to some new class
// returns the length of the key along with the length bytes for the key
static uint read_packed_length(uchar *p)
......@@ -243,16 +234,25 @@ class Variable_size_composite_key_desc : public Descriptor
{
int4store(p, sz - size_of_length_field);
}
static const uint size_of_length_field= 4;
uchar *get_packed_rec_ptr() { return packed_rec_ptr; }
uint make_packed_record(bool exclude_nulls);
};
/*
Descriptor for variable size keys
*/
class Variable_size_composite_key_desc : public Variable_size_keys_descriptor
{
public:
Variable_size_composite_key_desc(uint length);
~Variable_size_composite_key_desc() {}
int compare_keys(uchar *a, uchar *b) override;
};
/* Descriptor for variable size keys with only one component */
class Variable_size_keys_simple : public Variable_size_composite_key_desc
class Variable_size_keys_simple : public Variable_size_keys_descriptor
{
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