summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc44
-rw-r--r--sql/field.h19
-rw-r--r--sql/opt_subselect.cc1
-rw-r--r--sql/sql_select.cc1
-rw-r--r--sql/sql_select.h17
5 files changed, 42 insertions, 40 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 32ea2a536ef..13cad813b82 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -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;
diff --git a/sql/field.h b/sql/field.h
index 46ec491270b..2938209004d 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -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 @@ public:
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 @@ public:
{ 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 @@ public:
}
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 @@ public:
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;
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index e00083c4b8b..6e65b5ea177 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -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;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 82eeceab857..2e4227ed8a0 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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 */
diff --git a/sql/sql_select.h b/sql/sql_select.h
index bc6aa1eda1e..dc86825e8e9 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -1548,21 +1548,8 @@ public:
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),