summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
Diffstat (limited to 'sql')
-rw-r--r--sql/field.cc6
-rw-r--r--sql/field.h5
-rw-r--r--sql/field_conv.cc12
-rw-r--r--sql/ha_ndbcluster_tables.h2
-rw-r--r--sql/item_sum.cc11
-rw-r--r--sql/key.cc51
-rw-r--r--sql/mysql_priv.h3
-rw-r--r--sql/mysqld.cc2
-rw-r--r--sql/sql_class.cc4
-rw-r--r--sql/sql_select.cc9
-rw-r--r--sql/table.cc20
11 files changed, 71 insertions, 54 deletions
diff --git a/sql/field.cc b/sql/field.cc
index 09e919d872a..0453a4be6c3 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1237,12 +1237,6 @@ Field::Field(char *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
}
-uint Field::offset()
-{
- return (uint) (ptr - (char*) table->record[0]);
-}
-
-
void Field::hash(ulong *nr, ulong *nr2)
{
if (is_null())
diff --git a/sql/field.h b/sql/field.h
index 9b81931d416..b3541b38973 100644
--- a/sql/field.h
+++ b/sql/field.h
@@ -342,7 +342,10 @@ public:
virtual int pack_cmp(const char *b, uint key_length_arg,
my_bool insert_or_update)
{ return cmp(ptr,b); }
- uint offset(); // Should be inline ...
+ uint offset(byte *record)
+ {
+ return (uint) (ptr - (char*) record);
+ }
void copy_from_tmp(int offset);
uint fill_cache_field(struct st_cache_field *copy);
virtual bool get_date(TIME *ltime,uint fuzzydate);
diff --git a/sql/field_conv.cc b/sql/field_conv.cc
index 7bc6c432d1c..01b5306f5a4 100644
--- a/sql/field_conv.cc
+++ b/sql/field_conv.cc
@@ -119,12 +119,12 @@ set_field_to_null(Field *field)
return 0;
}
field->reset();
- if (current_thd->count_cuted_fields == CHECK_FIELD_WARN)
+ if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
{
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, WARN_DATA_TRUNCATED, 1);
return 0;
}
- if (!current_thd->no_errors)
+ if (!field->table->in_use->no_errors)
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
return -1;
}
@@ -176,12 +176,12 @@ set_field_to_null_with_conversions(Field *field, bool no_conversions)
field->table->auto_increment_field_not_null= FALSE;
return 0; // field is set in handler.cc
}
- if (current_thd->count_cuted_fields == CHECK_FIELD_WARN)
+ if (field->table->in_use->count_cuted_fields == CHECK_FIELD_WARN)
{
field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, ER_BAD_NULL_ERROR, 1);
return 0;
}
- if (!current_thd->no_errors)
+ if (!field->table->in_use->no_errors)
my_error(ER_BAD_NULL_ERROR, MYF(0), field->field_name);
return -1;
}
@@ -403,7 +403,7 @@ static void do_varstring1(Copy_field *copy)
if (length > copy->to_length- 1)
{
length=copy->to_length - 1;
- if (current_thd->count_cuted_fields)
+ if (copy->from_field->table->in_use->count_cuted_fields)
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
WARN_DATA_TRUNCATED, 1);
}
@@ -418,7 +418,7 @@ static void do_varstring2(Copy_field *copy)
if (length > copy->to_length- HA_KEY_BLOB_LENGTH)
{
length=copy->to_length-HA_KEY_BLOB_LENGTH;
- if (current_thd->count_cuted_fields)
+ if (copy->from_field->table->in_use->count_cuted_fields)
copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN,
WARN_DATA_TRUNCATED, 1);
}
diff --git a/sql/ha_ndbcluster_tables.h b/sql/ha_ndbcluster_tables.h
index 12124cd8820..9d7fda33102 100644
--- a/sql/ha_ndbcluster_tables.h
+++ b/sql/ha_ndbcluster_tables.h
@@ -15,7 +15,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#define NDB_REP_DB "cluster"
+#define NDB_REP_DB "mysql"
#define NDB_REP_TABLE "binlog_index"
#define NDB_APPLY_TABLE "apply_status"
#define NDB_SCHEMA_TABLE "schema"
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index c656faa7c49..5e0e64116b9 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -2928,13 +2928,14 @@ int group_concat_key_cmp_with_distinct(void* arg, byte* key1,
*/
Field *field= (*field_item)->get_tmp_table_field();
/*
- If field_item is a const item then either get_tp_table_field returns 0
+ If field_item is a const item then either get_tmp_table_field returns 0
or it is an item over a const table.
*/
if (field && !(*field_item)->const_item())
{
int res;
- uint offset= field->offset() - table->s->null_bytes;
+ uint offset= (field->offset(field->table->record[0]) -
+ table->s->null_bytes);
if ((res= field->cmp((char *) key1 + offset, (char *) key2 + offset)))
return res;
}
@@ -2972,7 +2973,8 @@ int group_concat_key_cmp_with_order(void* arg, byte* key1, byte* key2)
if (field && !item->const_item())
{
int res;
- uint offset= field->offset() - table->s->null_bytes;
+ uint offset= (field->offset(field->table->record[0]) -
+ table->s->null_bytes);
if ((res= field->cmp((char *) key1 + offset, (char *) key2 + offset)))
return (*order_item)->asc ? res : -res;
}
@@ -3039,7 +3041,8 @@ int dump_leaf_key(byte* key, element_count count __attribute__((unused)),
because it contains both order and arg list fields.
*/
Field *field= (*arg)->get_tmp_table_field();
- uint offset= field->offset() - table->s->null_bytes;
+ uint offset= (field->offset(field->table->record[0]) -
+ table->s->null_bytes);
DBUG_ASSERT(offset < table->s->reclength);
res= field->val_str(&tmp, (char *) key + offset);
}
diff --git a/sql/key.cc b/sql/key.cc
index be21bf11c3c..dceeab1c011 100644
--- a/sql/key.cc
+++ b/sql/key.cc
@@ -19,37 +19,54 @@
#include "mysql_priv.h"
- /*
- ** Search after with key field is. If no key starts with field test
- ** if field is part of some key.
- **
- ** returns number of key. keylength is set to length of key before
- ** (not including) field
- ** Used when calculating key for NEXT_NUMBER
- */
-
-int find_ref_key(KEY *key, uint key_count, Field *field, uint *key_length)
+/*
+ Search after a key that starts with 'field'
+
+ SYNOPSIS
+ find_ref_key()
+ key First key to check
+ key_count How many keys to check
+ record Start of record
+ field Field to search after
+ key_length On partial match, contains length of fields before
+ field
+
+ NOTES
+ Used when calculating key for NEXT_NUMBER
+
+ IMPLEMENTATION
+ If no key starts with field test if field is part of some key. If we find
+ one, then return first key and set key_length to the number of bytes
+ preceding 'field'.
+
+ RETURN
+ -1 field is not part of the key
+ # Key part for key matching key.
+ key_length is set to length of key before (not including) field
+*/
+
+int find_ref_key(KEY *key, uint key_count, byte *record, Field *field,
+ uint *key_length)
{
reg2 int i;
reg3 KEY *key_info;
uint fieldpos;
- fieldpos= field->offset();
-
- /* Test if some key starts as fieldpos */
+ fieldpos= field->offset(record);
+ /* Test if some key starts as fieldpos */
for (i= 0, key_info= key ;
i < (int) key_count ;
i++, key_info++)
{
if (key_info->key_part[0].offset == fieldpos)
- { /* Found key. Calc keylength */
+ { /* Found key. Calc keylength */
*key_length=0;
- return(i); /* Use this key */
+ return(i); /* Use this key */
}
}
- /* Test if some key contains fieldpos */
+ /* Test if some key contains fieldpos */
for (i= 0, key_info= key;
i < (int) key_count ;
i++, key_info++)
@@ -62,7 +79,7 @@ int find_ref_key(KEY *key, uint key_count, Field *field, uint *key_length)
j++, key_part++)
{
if (key_part->offset == fieldpos)
- return(i); /* Use this key */
+ return(i); /* Use this key */
*key_length+=key_part->store_length;
}
}
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 0bf75982626..e68fb4e442e 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1427,7 +1427,8 @@ void print_plan(JOIN* join,uint idx, double record_count, double read_time,
#endif
void mysql_print_status();
/* key.cc */
-int find_ref_key(KEY *key, uint key_count, Field *field, uint *key_length);
+int find_ref_key(KEY *key, uint key_count, byte *record, Field *field,
+ uint *key_length);
void key_copy(byte *to_key, byte *from_record, KEY *key_info, uint key_length);
void key_restore(byte *to_record, byte *from_key, KEY *key_info,
uint key_length);
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 05cc75f1c05..355b3f174dd 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -3187,7 +3187,7 @@ server.");
using_update_log=1;
}
- if (plugin_init(0))
+ if (plugin_init(opt_bootstrap))
{
sql_print_error("Failed to init plugins.");
return 1;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 5da8d27a887..7f31cde7819 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -2520,7 +2520,9 @@ my_size_t THD::max_row_length_blob(TABLE *table, const byte *data) const
for (uint *ptr= beg ; ptr != end ; ++ptr)
{
Field_blob* const blob= (Field_blob*) table->field[*ptr];
- length+= blob->get_length((const char *) (data + blob->offset())) + 2;
+ length+= blob->get_length((const char*) (data +
+ blob->offset(table->record[0]))) +
+ HA_KEY_BLOB_LENGTH;
}
return length;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e5399c03e17..9db7d1dd398 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -9488,7 +9488,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
bool maybe_null=(*cur_group->item)->maybe_null;
key_part_info->null_bit=0;
key_part_info->field= field;
- key_part_info->offset= field->offset();
+ key_part_info->offset= field->offset(table->record[0]);
key_part_info->length= (uint16) field->key_length();
key_part_info->type= (uint8) field->key_type();
key_part_info->key_type =
@@ -9585,7 +9585,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
{
key_part_info->null_bit=0;
key_part_info->field= *reg_field;
- key_part_info->offset= (*reg_field)->offset();
+ key_part_info->offset= (*reg_field)->offset(table->record[0]);
key_part_info->length= (uint16) (*reg_field)->pack_length();
key_part_info->type= (uint8) (*reg_field)->key_type();
key_part_info->key_type =
@@ -12557,8 +12557,9 @@ remove_duplicates(JOIN *join, TABLE *entry,List<Item> &fields, Item *having)
DBUG_RETURN(0);
}
Field **first_field=entry->field+entry->s->fields - field_count;
- offset= field_count ?
- entry->field[entry->s->fields - field_count]->offset() : 0;
+ offset= (field_count ?
+ entry->field[entry->s->fields - field_count]->
+ offset(entry->record[0]) : 0);
reclength=entry->s->reclength-offset;
free_io_cache(entry); // Safety
diff --git a/sql/table.cc b/sql/table.cc
index f15555138f8..58649c1d0f7 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -30,7 +30,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share,
uchar *head, File file);
static void fix_type_pointers(const char ***array, TYPELIB *point_to_type,
uint types, char **names);
-static uint find_field(Field **fields, uint start, uint length);
+static uint find_field(Field **fields, byte *record, uint start, uint length);
/* Get column name from column hash */
@@ -1070,6 +1070,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
Field *field;
if (new_field_pack_flag <= 1)
key_part->fieldnr= (uint16) find_field(share->field,
+ share->default_values,
(uint) key_part->offset,
(uint) key_part->length);
if (!key_part->fieldnr)
@@ -1233,24 +1234,19 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head,
if (share->found_next_number_field)
{
- /*
- We must have a table object for find_ref_key to calculate field offset
- */
- TABLE tmp_table;
- tmp_table.record[0]= share->default_values;
-
reg_field= *share->found_next_number_field;
- reg_field->table= &tmp_table;
if ((int) (share->next_number_index= (uint)
- find_ref_key(share->key_info, share->keys, reg_field,
+ find_ref_key(share->key_info, share->keys,
+ share->default_values, reg_field,
&share->next_number_key_offset)) < 0)
{
+ /* Wrong field definition */
+ DBUG_ASSERT(0);
reg_field->unireg_check= Field::NONE; /* purecov: inspected */
share->found_next_number_field= 0;
}
else
reg_field->flags |= AUTO_INCREMENT_FLAG;
- reg_field->table= 0;
}
if (share->blob_fields)
@@ -1970,7 +1966,7 @@ TYPELIB *typelib(MEM_ROOT *mem_root, List<String> &strings)
# field number +1
*/
-static uint find_field(Field **fields, uint start, uint length)
+static uint find_field(Field **fields, byte *record, uint start, uint length)
{
Field **field;
uint i, pos;
@@ -1978,7 +1974,7 @@ static uint find_field(Field **fields, uint start, uint length)
pos= 0;
for (field= fields, i=1 ; *field ; i++,field++)
{
- if ((*field)->offset() == start)
+ if ((*field)->offset(record) == start)
{
if ((*field)->key_length() == length)
return (i);