Commit 2510f9c6 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: remove special case from store_key::store_key(), add Field_blob::new_key_field

(prep for MDEV-6065)
parent dc9b2a95
......@@ -1965,8 +1965,8 @@ Field *Field::new_field(MEM_ROOT *root, TABLE *new_table,
Field *Field::new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uchar *new_null_ptr,
uint new_null_bit)
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit)
{
Field *tmp;
if ((tmp= new_field(root, new_table, table == new_table)))
......@@ -7204,17 +7204,14 @@ Field *Field_varstring::new_field(MEM_ROOT *root, TABLE *new_table,
}
Field *Field_varstring::new_key_field(MEM_ROOT *root,
TABLE *new_table,
uchar *new_ptr, uchar *new_null_ptr,
uint new_null_bit)
Field *Field_varstring::new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit)
{
Field_varstring *res;
if ((res= (Field_varstring*) Field::new_key_field(root,
new_table,
new_ptr,
new_null_ptr,
new_null_bit)))
if ((res= (Field_varstring*) Field::new_key_field(root, new_table,
new_ptr, length,
new_null_ptr, new_null_bit)))
{
/* Keys length prefixes are always packed with 2 bytes */
res->length_bytes= 2;
......@@ -7222,7 +7219,6 @@ Field *Field_varstring::new_key_field(MEM_ROOT *root,
return res;
}
uint Field_varstring::is_equal(Create_field *new_field)
{
if (new_field->sql_type == real_type() &&
......@@ -7579,6 +7575,18 @@ int Field_blob::key_cmp(const uchar *a,const uchar *b)
}
Field *Field_blob::new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit)
{
Field_varstring *res= new (root) Field_varstring(new_ptr, length, 2,
new_null_ptr, new_null_bit, Field::NONE,
field_name, table->s, charset());
res->init(new_table);
return res;
}
/**
Save the field metadata for blob fields.
......@@ -8426,15 +8434,13 @@ Field_bit::do_last_null_byte() const
}
Field *Field_bit::new_key_field(MEM_ROOT *root,
TABLE *new_table,
uchar *new_ptr, uchar *new_null_ptr,
uint new_null_bit)
Field *Field_bit::new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit)
{
Field_bit *res;
if ((res= (Field_bit*) Field::new_key_field(root, new_table,
new_ptr, new_null_ptr,
new_null_bit)))
if ((res= (Field_bit*) Field::new_key_field(root, new_table, new_ptr, length,
new_null_ptr, new_null_bit)))
{
/* Move bits normally stored in null_pointer to new_ptr */
res->bit_ptr= new_ptr;
......
......@@ -253,9 +253,13 @@ class Field
Field(const Item &); /* Prevent use of these */
void operator=(Field &);
public:
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
static void *operator new(size_t size) throw ()
{ return sql_alloc(size); }
static void operator delete(void *ptr_arg, size_t size) { TRASH(ptr_arg, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root)
{ DBUG_ASSERT(0); }
uchar *ptr; // Position to field in record
/**
......@@ -709,8 +713,8 @@ class Field
virtual Field *new_field(MEM_ROOT *root, TABLE *new_table,
bool keep_type);
virtual Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uchar *new_null_ptr,
uint new_null_bit);
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit);
Field *clone(MEM_ROOT *mem_root, TABLE *new_table);
Field *clone(MEM_ROOT *mem_root, TABLE *new_table, my_ptrdiff_t diff,
bool stat_flag= FALSE);
......@@ -2323,8 +2327,8 @@ class Field_varstring :public Field_longstr {
{ return charset() == &my_charset_bin ? FALSE : TRUE; }
Field *new_field(MEM_ROOT *root, TABLE *new_table, bool keep_type);
Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uchar *new_null_ptr,
uint new_null_bit);
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit);
uint is_equal(Create_field *new_field);
void hash(ulong *nr, ulong *nr2);
uint length_size() { return length_bytes; }
......@@ -2457,6 +2461,9 @@ class Field_blob :public Field_longstr {
}
uint get_key_image(uchar *buff,uint length, imagetype type);
void set_key_image(const uchar *buff,uint length);
Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit);
void sql_type(String &str) const;
inline bool copy()
{
......@@ -2727,8 +2734,8 @@ class Field_bit :public Field {
virtual void set_default();
Field *new_key_field(MEM_ROOT *root, TABLE *new_table,
uchar *new_ptr, uchar *new_null_ptr,
uint new_null_bit);
uchar *new_ptr, uint32 length,
uchar *new_null_ptr, uint new_null_bit);
void set_bit_ptr(uchar *bit_ptr_arg, uchar bit_ofs_arg)
{
bit_ptr= bit_ptr_arg;
......
......@@ -4120,6 +4120,7 @@ SJ_TMP_TABLE::create_sj_weedout_tmp_table(THD *thd)
{
if (!(key_field= field->new_key_field(thd->mem_root, table,
group_buff,
key_part_info->length,
field->null_ptr,
field->null_bit)))
goto err;
......
......@@ -16204,6 +16204,7 @@ create_tmp_table(THD *thd, TMP_TABLE_PARAM *param, List<Item> &fields,
if (!(cur_group->field= field->new_key_field(thd->mem_root,table,
group_buff +
MY_TEST(maybe_null),
key_part_info->length,
field->null_ptr,
field->null_bit)))
goto err; /* purecov: inspected */
......
......@@ -1548,21 +1548,8 @@ class store_key :public Sql_alloc
store_key(THD *thd, Field *field_arg, uchar *ptr, uchar *null, uint length)
:null_key(0), null_ptr(null), err(0)
{
if (field_arg->type() == MYSQL_TYPE_BLOB
|| field_arg->type() == MYSQL_TYPE_GEOMETRY)
{
/*
Key segments are always packed with a 2 byte length prefix.
See mi_rkey for details.
*/
to_field= new Field_varstring(ptr, length, 2, null, 1,
Field::NONE, field_arg->field_name,
field_arg->table->s, field_arg->charset());
to_field->init(field_arg->table);
}
else
to_field=field_arg->new_key_field(thd->mem_root, field_arg->table,
ptr, null, 1);
to_field=field_arg->new_key_field(thd->mem_root, field_arg->table,
ptr, length, null, 1);
}
store_key(store_key &arg)
:Sql_alloc(), null_key(arg.null_key), to_field(arg.to_field),
......
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