Commit 1d598de9 authored by unknown's avatar unknown

fixed coredump in UDF

added Monty's patch for alter table and LAST_INSERT_ID()
added a test case for replication of ALTER TABLE on a table with auto_increment


sql/item_func.cc:
  fixed a coredump in UDF
sql/sql_table.cc:
  fixed LAST_INSERT_ID() problem after ALTER TABLE on a table with auto_increment
parent 62d9bd5d
source ../include/master-slave.inc;
connection master;
drop table if exists test;
CREATE TABLE test (name varchar(64), age smallint(3));
INSERT INTO test SET name='Andy', age=31;
INSERT test SET name='Jacob', age=2;
INSERT into test SET name='Caleb', age=1;
ALTER TABLE test ADD id int(8) ZEROFILL AUTO_INCREMENT PRIMARY KEY;
@test.master select * from test;
connection slave;
@test.master select * from test;
\ No newline at end of file
name age id
Andy 31 00000001
Jacob 2 00000002
Caleb 1 00000003
...@@ -1140,6 +1140,8 @@ udf_handler::fix_fields(THD *thd,TABLE_LIST *tables,Item_result_field *func, ...@@ -1140,6 +1140,8 @@ udf_handler::fix_fields(THD *thd,TABLE_LIST *tables,Item_result_field *func,
break; break;
} }
} }
if(thd)
thd->net.last_error[0]=0; thd->net.last_error[0]=0;
my_bool (*init)(UDF_INIT *, UDF_ARGS *, char *)= my_bool (*init)(UDF_INIT *, UDF_ARGS *, char *)=
(my_bool (*)(UDF_INIT *, UDF_ARGS *, char *)) (my_bool (*)(UDF_INIT *, UDF_ARGS *, char *))
......
...@@ -32,7 +32,7 @@ static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end); ...@@ -32,7 +32,7 @@ static char *make_unique_key_name(const char *field_name,KEY *start,KEY *end);
static int copy_data_between_tables(TABLE *from,TABLE *to, static int copy_data_between_tables(TABLE *from,TABLE *to,
List<create_field> &create, List<create_field> &create,
enum enum_duplicates handle_duplicates, enum enum_duplicates handle_duplicates,
ulong *copied,ulong *deleted); ha_rows *copied,ha_rows *deleted);
/***************************************************************************** /*****************************************************************************
** Remove all possbile tables and give a compact errormessage for all ** Remove all possbile tables and give a compact errormessage for all
...@@ -992,7 +992,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -992,7 +992,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN], char tmp_name[80],old_name[32],new_name_buff[FN_REFLEN],
*table_name,*db; *table_name,*db;
bool use_timestamp=0; bool use_timestamp=0;
ulong copied,deleted; ha_rows copied,deleted;
ulonglong next_insert_id;
uint save_time_stamp,db_create_options; uint save_time_stamp,db_create_options;
enum db_type old_db_type,new_db_type; enum db_type old_db_type,new_db_type;
DBUG_ENTER("mysql_alter_table"); DBUG_ENTER("mysql_alter_table");
...@@ -1333,11 +1334,13 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -1333,11 +1334,13 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
if (use_timestamp) if (use_timestamp)
new_table->time_stamp=0; new_table->time_stamp=0;
new_table->next_number_field=new_table->found_next_number_field; new_table->next_number_field=new_table->found_next_number_field;
thd->count_cuted_fields=1; /* calc cuted fields */ thd->count_cuted_fields=1; // calc cuted fields
thd->cuted_fields=0L; thd->cuted_fields=0L;
thd->proc_info="copy to tmp table"; thd->proc_info="copy to tmp table";
next_insert_id=thd->next_insert_id; // Remember for loggin
error=copy_data_between_tables(table,new_table,create_list,handle_duplicates, error=copy_data_between_tables(table,new_table,create_list,handle_duplicates,
&copied,&deleted); &copied,&deleted);
thd->last_insert_id=next_insert_id; // Needed for correct log
thd->count_cuted_fields=0; /* Don`t calc cuted fields */ thd->count_cuted_fields=0; /* Don`t calc cuted fields */
new_table->time_stamp=save_time_stamp; new_table->time_stamp=save_time_stamp;
...@@ -1474,8 +1477,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -1474,8 +1477,8 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
VOID(pthread_mutex_unlock(&LOCK_open)); VOID(pthread_mutex_unlock(&LOCK_open));
end_temporary: end_temporary:
sprintf(tmp_name,ER(ER_INSERT_INFO),copied+deleted,deleted, sprintf(tmp_name,ER(ER_INSERT_INFO),(ulong) (copied+deleted),
thd->cuted_fields); (ulong) deleted, thd->cuted_fields);
send_ok(&thd->net,copied+deleted,0L,tmp_name); send_ok(&thd->net,copied+deleted,0L,tmp_name);
thd->some_tables_deleted=0; thd->some_tables_deleted=0;
DBUG_RETURN(0); DBUG_RETURN(0);
...@@ -1488,7 +1491,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name, ...@@ -1488,7 +1491,7 @@ int mysql_alter_table(THD *thd,char *new_db, char *new_name,
static int static int
copy_data_between_tables(TABLE *from,TABLE *to,List<create_field> &create, copy_data_between_tables(TABLE *from,TABLE *to,List<create_field> &create,
enum enum_duplicates handle_duplicates, enum enum_duplicates handle_duplicates,
ulong *copied,ulong *deleted) ha_rows *copied,ha_rows *deleted)
{ {
int error; int error;
Copy_field *copy,*copy_end; Copy_field *copy,*copy_end;
......
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