From 6ef4dc29c3cbd131c42b852c2526312a61729be0 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Tue, 9 Sep 2003 19:23:01 +0200 Subject: [PATCH 01/15] fixed: thread lock-up on a FLASH TABLE when another thread has an open handler Bug#1204 --- sql/sql_handler.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index b0d8b18dd17..a19fcdc2d73 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -34,7 +34,7 @@ The second is to be freeed only on thread end. mysql_ha_open should then do { handler_items=concat(handler_items, free_list); free_list=0; } - But !!! do_cammand calls free_root at the end of every query and frees up + But !!! do_command calls free_root at the end of every query and frees up all the sql_alloc'ed memory. It's harder to work around... */ @@ -73,7 +73,11 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables, bool dont_send_ok) if (*ptr) { VOID(pthread_mutex_lock(&LOCK_open)); - close_thread_table(thd, ptr); + if (close_thread_table(thd, ptr)) + { + /* Tell threads waiting for refresh that something has happened */ + VOID(pthread_cond_broadcast(&COND_refresh)); + } VOID(pthread_mutex_unlock(&LOCK_open)); } else @@ -90,8 +94,11 @@ int mysql_ha_close(THD *thd, TABLE_LIST *tables, bool dont_send_ok) int mysql_ha_closeall(THD *thd, TABLE_LIST *tables) { TABLE **ptr=find_table_ptr_by_name(thd, tables->db, tables->real_name, 0); - if (*ptr) - close_thread_table(thd, ptr); + if (*ptr && close_thread_table(thd, ptr)) + { + /* Tell threads waiting for refresh that something has happened */ + VOID(pthread_cond_broadcast(&COND_refresh)); + } return 0; } From 1394684e12b85ed9808115b9fe3a80c4d84c64ef Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sat, 27 Sep 2003 18:54:22 +0200 Subject: [PATCH 02/15] make mysqld to respect socket/port options of mysqld_safe command line and [mysqld_safe] section in my.cnf, even if they are also specified in [mysql] section. --- scripts/mysqld_safe.sh | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/scripts/mysqld_safe.sh b/scripts/mysqld_safe.sh index 1c056e963cb..ece4ba098f4 100644 --- a/scripts/mysqld_safe.sh +++ b/scripts/mysqld_safe.sh @@ -51,9 +51,9 @@ parse_arguments() { ;; # these two might have been set in a [mysqld_safe] section of my.cnf - # they get passed via environment variables to mysqld_safe - --socket=*) MYSQL_UNIX_PORT=`echo "$arg" | sed -e "s;--socket=;;"` ;; - --port=*) MYSQL_TCP_PORT=`echo "$arg" | sed -e "s;--port=;;"` ;; + # they are added to mysqld command line to override settings from my.cnf + --socket=*) mysql_unix_port=`echo "$arg" | sed -e "s;--socket=;;"` ;; + --port=*) mysql_tcp_port=`echo "$arg" | sed -e "s;--port=;;"` ;; # mysqld_safe-specific options - must be set in my.cnf ([mysqld_safe])! --ledir=*) ledir=`echo "$arg" | sed -e "s;--ledir=;;"` ;; @@ -114,8 +114,7 @@ else ledir=@libexecdir@ fi -MYSQL_UNIX_PORT=${MYSQL_UNIX_PORT:-@MYSQL_UNIX_ADDR@} -MYSQL_TCP_PORT=${MYSQL_TCP_PORT:-@MYSQL_TCP_PORT@} +safe_mysql_unix_port=${mysql_unix_port:-${MYSQL_UNIX_PORT:-@MYSQL_UNIX_ADDR@}} user=@MYSQLD_USER@ niceness=0 @@ -171,9 +170,14 @@ else fi test -z "$err_log" && err_log=$DATADIR/`@HOSTNAME@`.err -export MYSQL_UNIX_PORT -export MYSQL_TCP_PORT - +if test -n "$mysql_unix_port" +then + args="--socket=$mysql_unix_port $args" +fi +if test -n "$mysql_tcp_port" +then + args="--port=$mysql_tcp_port $args" +fi if test $niceness -eq 0 then @@ -296,7 +300,7 @@ echo "Starting $MYSQLD daemon with databases from $DATADIR" echo "`date +'%y%m%d %H:%M:%S mysqld started'`" >> $err_log while true do - rm -f $MYSQL_UNIX_PORT $pid_file # Some extra safety + rm -f $safe_mysql_unix_port $pid_file # Some extra safety if test -z "$args" then $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file @MYSQLD_DEFAULT_SWITCHES@ >> $err_log 2>&1 From 9e68df23333ecb21ed776fcb983e2f98ca2d1721 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Sun, 28 Sep 2003 21:35:47 +0200 Subject: [PATCH 03/15] typo fixed (bug #1390 - incorrect mysql_config output) --- scripts/mysql_config.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mysql_config.sh b/scripts/mysql_config.sh index 3cc5b3a5016..f7c4b4ff381 100644 --- a/scripts/mysql_config.sh +++ b/scripts/mysql_config.sh @@ -62,7 +62,7 @@ get_full_path () { case $1 in /*) echo "$1";; - ./*) tmp=`pwd`/$1; echo $tmp | sed -e 's;/./;/;' ;; + ./*) tmp=`pwd`/$1; echo $tmp | sed -e 's;/\./;/;' ;; *) which $1 ;; esac } From 8c7c4de0b4a7bcffe27e4549ed4dd242d71056df Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Mon, 29 Sep 2003 11:21:17 +0200 Subject: [PATCH 04/15] enum options renamed to avoid possible name conflicts --- client/client_priv.h | 2 +- myisam/myisamchk.c | 2 +- sql/mysqld.cc | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/client_priv.h b/client/client_priv.h index 85c99951532..5029f219494 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -26,7 +26,7 @@ /* We have to define 'enum options' identical in all files to keep OS2 happy */ -enum options { OPT_CHARSETS_DIR=256, OPT_DEFAULT_CHARSET, +enum options_client { OPT_CHARSETS_DIR=256, OPT_DEFAULT_CHARSET, OPT_PAGER, OPT_NOPAGER, OPT_TEE, OPT_NOTEE, OPT_LOW_PRIORITY, OPT_AUTO_REPAIR, OPT_COMPRESS, OPT_DROP, OPT_LOCKS, OPT_KEYWORDS, OPT_DELAYED, OPT_OPTIMIZE, diff --git a/myisam/myisamchk.c b/myisam/myisamchk.c index 83edadf153f..b7627fc59fd 100644 --- a/myisam/myisamchk.c +++ b/myisam/myisamchk.c @@ -144,7 +144,7 @@ int main(int argc, char **argv) #endif } /* main */ -enum options { +enum options_mc { OPT_CHARSETS_DIR=256, OPT_SET_CHARSET,OPT_START_CHECK_POS, OPT_CORRECT_CHECKSUM, OPT_KEY_BUFFER_SIZE, OPT_MYISAM_BLOCK_SIZE, OPT_READ_BUFFER_SIZE, OPT_WRITE_BUFFER_SIZE, OPT_SORT_BUFFER_SIZE, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index bcf115feccc..cc870ed3e36 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3130,7 +3130,7 @@ extern "C" pthread_handler_decl(handle_connections_namedpipes,arg) ** handle start options ******************************************************************************/ -enum options { +enum options_mysqld { OPT_ISAM_LOG=256, OPT_SKIP_NEW, OPT_SKIP_GRANT, OPT_SKIP_LOCK, OPT_ENABLE_LOCK, OPT_USE_LOCKING, From 2667d7f8cc34d7b568ebcfce3e74f25bde6a448e Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Mon, 6 Oct 2003 14:11:16 +0200 Subject: [PATCH 05/15] fix_max_connections to resize alarm_queue (Bug #1435) --- include/queues.h | 1 + include/thr_alarm.h | 1 + mysys/queues.c | 24 +++++++++++++++++------- mysys/thr_alarm.c | 10 ++++++++++ sql/set_var.cc | 21 +++++++++++++++------ 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/include/queues.h b/include/queues.h index 699705d0869..ac15b09719b 100644 --- a/include/queues.h +++ b/include/queues.h @@ -49,6 +49,7 @@ int init_queue(QUEUE *queue,uint max_elements,uint offset_to_key, int reinit_queue(QUEUE *queue,uint max_elements,uint offset_to_key, pbool max_at_top, queue_compare compare, void *first_cmp_arg); +int resize_queue(QUEUE *queue, uint max_elements); void delete_queue(QUEUE *queue); void queue_insert(QUEUE *queue,byte *element); byte *queue_remove(QUEUE *queue,uint idx); diff --git a/include/thr_alarm.h b/include/thr_alarm.h index 8ff4472f700..a54c192b1ed 100644 --- a/include/thr_alarm.h +++ b/include/thr_alarm.h @@ -100,6 +100,7 @@ typedef struct st_alarm { #define thr_alarm_init(A) (*(A))=0 #define thr_alarm_in_use(A) (*(A)!= 0) void init_thr_alarm(uint max_alarm); +void resize_thr_alarm(uint max_alarms); my_bool thr_alarm(thr_alarm_t *alarmed, uint sec, ALARM *buff); void thr_alarm_kill(pthread_t thread_id); void thr_end_alarm(thr_alarm_t *alarmed); diff --git a/mysys/queues.c b/mysys/queues.c index fe642131d74..ae69684f9e4 100644 --- a/mysys/queues.c +++ b/mysys/queues.c @@ -44,25 +44,35 @@ int init_queue(QUEUE *queue, uint max_elements, uint offset_to_key, } /* - Reinitialize queue for new usage; Note that you can't currently resize - the number of elements! If you need this, fix it :) + Reinitialize queue for new usage; */ - int reinit_queue(QUEUE *queue, uint max_elements, uint offset_to_key, pbool max_at_top, int (*compare) (void *, byte *, byte *), void *first_cmp_arg) { DBUG_ENTER("reinit_queue"); - if (queue->max_elements < max_elements) - /* It's real easy to do realloc here, just don't want to bother */ - DBUG_RETURN(my_errno=EE_OUTOFMEMORY); - queue->elements=0; queue->compare=compare; queue->first_cmp_arg=first_cmp_arg; queue->offset_to_key=offset_to_key; queue->max_at_top= max_at_top ? (-1 ^ 1) : 0; + resize_queue(queue, max_elements); + DBUG_RETURN(0); +} + +int resize_queue(QUEUE *queue, uint max_elements) +{ + byte **new_root; + DBUG_ENTER("resize_queue"); + if (queue->max_elements == max_elements) + DBUG_RETURN(0); + if ((new_root= (byte **) my_realloc((void *)queue->root, + (max_elements+1)*sizeof(void*), MYF(MY_WME))) == 0) + DBUG_RETURN(1); + set_if_smaller(queue->elements, max_elements); + queue->max_elements=max_elements; + queue->root=new_root; DBUG_RETURN(0); } diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index 2289f8208bc..5d2ac8b0099 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -120,6 +120,16 @@ void init_thr_alarm(uint max_alarms) DBUG_VOID_RETURN; } +void resize_thr_alarm(uint max_alarms) +{ + pthread_mutex_lock(&LOCK_alarm); + /* it's ok not to shrink the queue sometimes */ + if (alarm_queue.elements < max_alarms) + resize_queue(&alarm_queue,max_alarms+1); + pthread_mutex_unlock(&LOCK_alarm); + return; +} + /* Request alarm after sec seconds. diff --git a/sql/set_var.cc b/sql/set_var.cc index 8c0859fbca4..3388fbc1932 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -86,6 +86,7 @@ static void fix_myisam_max_extra_sort_file_size(THD *thd, enum_var_type type); static void fix_myisam_max_sort_file_size(THD *thd, enum_var_type type); static void fix_max_binlog_size(THD *thd, enum_var_type type); static void fix_max_relay_log_size(THD *thd, enum_var_type type); +static void fix_max_connections(THD *thd, enum_var_type type); /* Variable definition list @@ -147,7 +148,8 @@ sys_var_long_ptr sys_max_binlog_size("max_binlog_size", &max_binlog_size, fix_max_binlog_size); sys_var_long_ptr sys_max_connections("max_connections", - &max_connections); + &max_connections, + fix_max_connections); sys_var_long_ptr sys_max_connect_errors("max_connect_errors", &max_connect_errors); sys_var_long_ptr sys_max_delayed_threads("max_delayed_threads", @@ -636,7 +638,7 @@ static void fix_max_join_size(THD *thd, enum_var_type type) thd->options&= ~OPTION_BIG_SELECTS; } } - + /* If one doesn't use the SESSION modifier, the isolation level @@ -689,7 +691,7 @@ static void fix_key_buffer_size(THD *thd, enum_var_type type) } -void fix_delay_key_write(THD *thd, enum_var_type type) +extern void fix_delay_key_write(THD *thd, enum_var_type type) { switch ((enum_delay_key_write) delay_key_write_options) { case DELAY_KEY_WRITE_NONE: @@ -705,7 +707,7 @@ void fix_delay_key_write(THD *thd, enum_var_type type) } } -void fix_max_binlog_size(THD *thd, enum_var_type type) +static void fix_max_binlog_size(THD *thd, enum_var_type type) { DBUG_ENTER("fix_max_binlog_size"); DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu", @@ -716,7 +718,7 @@ void fix_max_binlog_size(THD *thd, enum_var_type type) DBUG_VOID_RETURN; } -void fix_max_relay_log_size(THD *thd, enum_var_type type) +static void fix_max_relay_log_size(THD *thd, enum_var_type type) { DBUG_ENTER("fix_max_relay_log_size"); DBUG_PRINT("info",("max_binlog_size=%lu max_relay_log_size=%lu", @@ -726,6 +728,13 @@ void fix_max_relay_log_size(THD *thd, enum_var_type type) DBUG_VOID_RETURN; } +#include +static void +fix_max_connections(THD *thd, enum_var_type type) +{ + resize_thr_alarm(max_connections); +} + bool sys_var_long_ptr::update(THD *thd, set_var *var) { ulonglong tmp= var->value->val_int(); @@ -1478,7 +1487,7 @@ int set_var::check(THD *thd) { my_error(ER_WRONG_TYPE_FOR_VAR, MYF(0), var->name); return -1; - } + } return var->check(thd, this) ? -1 : 0; } From b58098c3b9652434c99784ce982471931706ded4 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Mon, 6 Oct 2003 20:02:27 +0200 Subject: [PATCH 06/15] bug #1434 (and related issues) --- mysql-test/t/create.test | 22 +++++++++++++++++++++- sql/sql_class.h | 4 ++-- sql/sql_insert.cc | 14 ++++++++++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index d46807f1dca..815aad560b1 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -129,8 +129,28 @@ insert into t1 values ("a", 1), ("b", 2); drop table t1; # -# Bug # 801 +# Bug #801 # create table t1 select x'4132'; drop table t1; + +# +# bug #1434 +# + +create table t1 select 1,2,3; +create table if not exists t1 select 1,2; +--error 1136 +create table if not exists t1 select 1,2,3,4; +create table if not exists t1 select 1; +select * from t1; +drop table t1; +create table t1 select 1,2,3; +create table if not exists t1 select 1,2; +--error 1136 +create table if not exists t1 select 1,2,3,4; +create table if not exists t1 select 1; +select * from t1; +drop table t1; + diff --git a/sql/sql_class.h b/sql/sql_class.h index 2ed9cb7b877..bf626eb7d92 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -703,6 +703,7 @@ class select_create: public select_insert { HA_CREATE_INFO *create_info; MYSQL_LOCK *lock; Field **field; + my_bool do_not_drop; public: select_create (const char *db_name, const char *table_name, HA_CREATE_INFO *create_info_par, @@ -711,8 +712,7 @@ public: List &select_fields,enum_duplicates duplic) :select_insert (NULL, &select_fields, duplic), db(db_name), name(table_name), extra_fields(&fields_par),keys(&keys_par), - create_info(create_info_par), - lock(0) + create_info(create_info_par), lock(0), do_not_drop(0) {} int prepare(List &list); bool send_data(List &values); diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 0a83358e8c6..ad08ad6ccd6 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1438,6 +1438,15 @@ select_create::prepare(List &values) if (!table) DBUG_RETURN(-1); // abort() deletes table + if (table->fields < values.elements) + { + do_not_drop=1; + my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW, + ER(ER_WRONG_VALUE_COUNT_ON_ROW), + MYF(0),1); + DBUG_RETURN(-1); + } + /* First field to copy */ field=table->field+table->fields - values.elements; @@ -1498,7 +1507,7 @@ bool select_create::send_eof() */ if (!table->tmp_table) hash_delete(&open_cache,(byte*) table); - lock=0; + lock=0; table=0; VOID(pthread_mutex_unlock(&LOCK_open)); } @@ -1519,7 +1528,8 @@ void select_create::abort() enum db_type table_type=table->db_type; if (!table->tmp_table) hash_delete(&open_cache,(byte*) table); - quick_rm_table(table_type,db,name); + if (!do_not_drop) + quick_rm_table(table_type,db,name); table=0; } VOID(pthread_mutex_unlock(&LOCK_open)); From 511589a4f820d7ff31dda49531bd0dfba26ac9e3 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Mon, 6 Oct 2003 20:11:39 +0200 Subject: [PATCH 07/15] results updated --- mysql-test/r/create.result | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index e6192eb6ccb..51952009f08 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -178,3 +178,25 @@ Column 'k1' cannot be null drop table t1; create table t1 select x'4132'; drop table t1; +create table t1 select 1,2,3; +create table if not exists t1 select 1,2; +create table if not exists t1 select 1,2,3,4; +Column count doesn't match value count at row 1 +create table if not exists t1 select 1; +select * from t1; +1 2 3 +1 2 3 +0 1 2 +0 0 1 +drop table t1; +create table t1 select 1,2,3; +create table if not exists t1 select 1,2; +create table if not exists t1 select 1,2,3,4; +Column count doesn't match value count at row 1 +create table if not exists t1 select 1; +select * from t1; +1 2 3 +1 2 3 +0 1 2 +0 0 1 +drop table t1; From 6f96749cca6566c096aef96a3048ad1d0ee66c7e Mon Sep 17 00:00:00 2001 From: "vva@eagle.mysql.r18.ru" <> Date: Wed, 8 Oct 2003 17:15:59 -0400 Subject: [PATCH 08/15] fixed temp directory for mysqlbinlog (was wrong on solaris) --- mysql-test/t/mysqlbinlog.test | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index c5e1be37b01..e22a37fabfd 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -39,28 +39,28 @@ select "--- Local --" as ""; # --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.001 +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ $MYSQL_TEST_DIR/var/log/master-bin.001 # this should not fail but shouldn't produce any working statements --disable_query_log select "--- Broken LOAD DATA --" as ""; --enable_query_log --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form $MYSQL_TEST_DIR/var/log/master-bin.002 +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ $MYSQL_TEST_DIR/var/log/master-bin.002 # this should show almost nothing --disable_query_log select "--- --database --" as ""; --enable_query_log --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --database=nottest $MYSQL_TEST_DIR/var/log/master-bin.001 +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --database=nottest $MYSQL_TEST_DIR/var/log/master-bin.001 # this test for position option --disable_query_log select "--- --position --" as ""; --enable_query_log --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --position=27 $MYSQL_TEST_DIR/var/log/master-bin.002 +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --position=27 $MYSQL_TEST_DIR/var/log/master-bin.002 # These are tests for remote binlog. # They should return the same as previous test. @@ -76,28 +76,28 @@ select "--- Remote --" as ""; # This is broken now # By the way it seems that remote version fetches all events with name >= master-bin.001 --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.001 +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.001 # This is broken too --disable_query_log select "--- Broken LOAD DATA --" as ""; --enable_query_log --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.002 +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.002 # And this too ! (altough it is documented) --disable_query_log select "--- --database --" as ""; --enable_query_log --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --database=nottest master-bin.001 +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --user=root --host=127.0.0.1 --port=$MASTER_MYPORT --database=nottest master-bin.001 # Strangely but this works --disable_query_log select "--- --position --" as ""; --enable_query_log --replace_result $MYSQL_TEST_DIR MYSQL_TEST_DIR ---exec $MYSQL_BINLOG --short-form --read-from-remote-server --position=27 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.002 +--exec $MYSQL_BINLOG --short-form --local-load=$MYSQL_TEST_DIR/var/tmp/ --read-from-remote-server --position=27 --user=root --host=127.0.0.1 --port=$MASTER_MYPORT master-bin.002 # clean up drop table t1; From b2500829a3685d5546658eb969ff53a36872cdaf Mon Sep 17 00:00:00 2001 From: "guilhem@mysql.com" <> Date: Thu, 9 Oct 2003 17:40:38 +0200 Subject: [PATCH 09/15] Make the slave die if master is 5.0. Indeed, 5.0 masters send a Format_description_log_event (or maybe it will be named Description_log_event) which is not recognized by 4.0, so a 4.0 can't be a slave of 5.0. We detect it early to produce a helpful message instead of "corrupted relay log" later. --- sql/slave.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/slave.cc b/sql/slave.cc index 10d451a88bc..12698c8eda4 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1017,11 +1017,12 @@ static int check_master_version(MYSQL* mysql, MASTER_INFO* mi) BINLOG_FORMAT_323_GEQ_57 ; break; case '4': - case '5': mi->old_format = BINLOG_FORMAT_CURRENT; break; default: - errmsg = "Master reported unrecognized MySQL version"; + /* 5.0 is not supported */ + errmsg = "Master reported an unrecognized MySQL version. Note that 4.0 \ +slaves can't replicate a 5.0 or newer master."; break; } From f078e50a6b85798f96789befb084eea6c6bc807e Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Tue, 14 Oct 2003 13:10:41 +0200 Subject: [PATCH 10/15] make LOCK TABLES to work when Lock_tables_priv is granted on the DB level and Select_priv is granted on the table level. --- sql/sql_parse.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 0c4e3cad763..0d743e1d56e 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2693,7 +2693,7 @@ check_access(THD *thd, ulong want_access, const char *db, ulong *save_priv, /* grant_option is set if there exists a single table or column grant */ if (db_access == want_access || ((grant_option && !dont_check_global_grants) && - !(want_access & ~TABLE_ACLS))) + !(want_access & ~(db_access | TABLE_ACLS)))) DBUG_RETURN(FALSE); /* Ok */ if (!no_errors) net_printf(&thd->net,ER_DBACCESS_DENIED_ERROR, From da97e073d46f08be7f5a3016f4ffed778ad9fc19 Mon Sep 17 00:00:00 2001 From: "paul@teton.kitebird.com" <> Date: Tue, 14 Oct 2003 10:45:03 -0500 Subject: [PATCH 11/15] Identical mysql.ico and MYSQL.ICO existed, causing problems on non-case-sensitive OSes. Deleted conflicting file. --- VC++Files/mysqlshutdown/MYSQL.ICO | Bin 318 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 VC++Files/mysqlshutdown/MYSQL.ICO diff --git a/VC++Files/mysqlshutdown/MYSQL.ICO b/VC++Files/mysqlshutdown/MYSQL.ICO deleted file mode 100644 index 1fe0b7115bbe95b1108cd2ef025f539cad262181..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 318 zcmZvUD-Hrd5JcZ5m~pGnNG`<*&;-dE{Mfn8Bxu&55QK0D6ltnvMWz)B3Y@jseC!89!*R!Xf^>Or(1!kHj<%hW7GDWsB>AX214Q+0Zs``j1a z(@j@PPTpHIC8_LJ_1=$lliIOY^&;L8mot10@Dd)vQ+0fVtLJb(3VXP9%sZG*+7-U9 Cr%L_+ From b5849f451d1e5ac82266e8cee74fa66543a8afc2 Mon Sep 17 00:00:00 2001 From: "monty@mashka.mysql.fi" <> Date: Wed, 15 Oct 2003 15:21:50 +0300 Subject: [PATCH 12/15] Add more information about memory usage to debug log --- sql/sql_test.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sql/sql_test.cc b/sql/sql_test.cc index fc3147db784..6498a52cc09 100644 --- a/sql/sql_test.cc +++ b/sql/sql_test.cc @@ -194,6 +194,8 @@ void mysql_print_status(THD *thd) printf("\nStatus information:\n\n"); my_getwd(current_dir, sizeof(current_dir),MYF(0)); printf("Current dir: %s\n", current_dir); + printf("Running threads: %d Stack size: %ld\n", thread_count, + (long) thread_stack); if (thd) thd->proc_info="locks"; thr_print_locks(); // Write some debug info @@ -271,8 +273,9 @@ Maximum total allocated space: %d\n\ Space available in freed fastbin blocks: %d\n\ Total allocated space: %d\n\ Total free space: %d\n\ -Top-most, releasable space: %d\n", - (int) info.arena, +Top-most, releasable space: %d\n\ +Estimated memory (with thread stack): %ld\n", + (int) info.arena , (int) info.ordblks, (int) info.smblks, (int) info.hblks, @@ -281,7 +284,8 @@ Top-most, releasable space: %d\n", (int) info.fsmblks, (int) info.uordblks, (int) info.fordblks, - (int) info.keepcost); + (int) info.keepcost, + (long) (thread_count * thread_stack + info.hblkhd + info.arena)); #endif puts(""); if (thd) From 4897c6649d927419d95ad9a315dc6316110be2d4 Mon Sep 17 00:00:00 2001 From: "monty@mashka.mysql.fi" <> Date: Wed, 15 Oct 2003 16:55:24 +0300 Subject: [PATCH 13/15] Updated comments --- mysys/queues.c | 26 +++++++++++++++++++++++--- mysys/thr_alarm.c | 8 ++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/mysys/queues.c b/mysys/queues.c index ae69684f9e4..93d4c303f22 100644 --- a/mysys/queues.c +++ b/mysys/queues.c @@ -61,6 +61,24 @@ int reinit_queue(QUEUE *queue, uint max_elements, uint offset_to_key, DBUG_RETURN(0); } + +/* + Resize queue + + SYNOPSIS + resize_queue() + queue Queue + max_elements New max size for queue + + NOTES + If you resize queue to be less than the elements you have in it, + the extra elements will be deleted + + RETURN + 0 ok + 1 Error. In this case the queue is unchanged +*/ + int resize_queue(QUEUE *queue, uint max_elements) { byte **new_root; @@ -68,14 +86,16 @@ int resize_queue(QUEUE *queue, uint max_elements) if (queue->max_elements == max_elements) DBUG_RETURN(0); if ((new_root= (byte **) my_realloc((void *)queue->root, - (max_elements+1)*sizeof(void*), MYF(MY_WME))) == 0) + (max_elements+1)*sizeof(void*), + MYF(MY_WME))) == 0) DBUG_RETURN(1); set_if_smaller(queue->elements, max_elements); - queue->max_elements=max_elements; - queue->root=new_root; + queue->max_elements= max_elements; + queue->root= new_root; DBUG_RETURN(0); } + void delete_queue(QUEUE *queue) { DBUG_ENTER("delete_queue"); diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index 5d2ac8b0099..36bbac16fef 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -120,16 +120,20 @@ void init_thr_alarm(uint max_alarms) DBUG_VOID_RETURN; } + void resize_thr_alarm(uint max_alarms) { pthread_mutex_lock(&LOCK_alarm); - /* it's ok not to shrink the queue sometimes */ + /* + It's ok not to shrink the queue as there may be more pending alarms than + than max_alarms + */ if (alarm_queue.elements < max_alarms) resize_queue(&alarm_queue,max_alarms+1); pthread_mutex_unlock(&LOCK_alarm); - return; } + /* Request alarm after sec seconds. From 33e5f4edec5b6ffb472e17cfc63f67895dc27719 Mon Sep 17 00:00:00 2001 From: "serg@serg.mylan" <> Date: Wed, 15 Oct 2003 17:10:47 +0200 Subject: [PATCH 14/15] dummy resize_thr_alarm for Netware --- include/thr_alarm.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/thr_alarm.h b/include/thr_alarm.h index a54c192b1ed..0dbb700b4fc 100644 --- a/include/thr_alarm.h +++ b/include/thr_alarm.h @@ -60,9 +60,10 @@ typedef my_bool ALARM; #define thr_end_alarm(A) #define thr_alarm(A,B,C) ((*(A)=1)-1) /* The following should maybe be (*(A)) */ -#define thr_got_alarm(A) 0 +#define thr_got_alarm(A) 0 #define init_thr_alarm(A) #define thr_alarm_kill(A) +#define resize_thr_alarm(N) #define end_thr_alarm() #else From 84d9d9807841cbbcb756c24ef56f0d0fe5ec3e2f Mon Sep 17 00:00:00 2001 From: "monty@mashka.mysql.fi" <> Date: Wed, 15 Oct 2003 21:41:13 +0300 Subject: [PATCH 15/15] Better fix for CREATE TABLE IF NOT EXISTS ... SELECT Fixed chsize() problem on windows Extend default timeout on windows clients to 1 year (to avoid timeout problems) --- include/mysql.h | 3 +++ libmysql/libmysql.c | 4 ++-- mysql-test/r/create.result | 16 +++++++++++++ mysql-test/t/create.test | 49 ++++++++++++++++++++++++++++---------- mysys/my_chsize.c | 13 +++++----- sql/handler.h | 18 +++++++------- sql/slave.cc | 2 ++ sql/sql_class.h | 4 ++-- sql/sql_insert.cc | 3 +-- sql/sql_table.cc | 7 ++++++ 10 files changed, 86 insertions(+), 33 deletions(-) diff --git a/include/mysql.h b/include/mysql.h index 95730c0f2f5..0c91266e19c 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -60,6 +60,9 @@ typedef int my_socket; extern unsigned int mysql_port; extern char *mysql_unix_port; +#define CLIENT_NET_READ_TIMEOUT 365*24*3600 /* Timeout on read */ +#define CLIENT_NET_WRITE_TIMEOUT 365*24*3600 /* Timeout on write */ + #ifdef __NETWARE__ #pragma pack(push, 8) /* 8 byte alignment */ #endif diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index cd4e8c77f20..d8966b30fb9 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -64,8 +64,8 @@ uint mysql_port=0; my_string mysql_unix_port=0; ulong net_buffer_length=8192; ulong max_allowed_packet= 1024L*1024L*1024L; -ulong net_read_timeout= NET_READ_TIMEOUT; -ulong net_write_timeout= NET_WRITE_TIMEOUT; +ulong net_read_timeout= CLIENT_NET_READ_TIMEOUT; +ulong net_write_timeout= CLIENT_NET_WRITE_TIMEOUT; #define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD | CLIENT_LONG_FLAG | CLIENT_TRANSACTIONS) diff --git a/mysql-test/r/create.result b/mysql-test/r/create.result index 3ebe6df21b9..627913939fb 100644 --- a/mysql-test/r/create.result +++ b/mysql-test/r/create.result @@ -200,3 +200,19 @@ select * from t1; 0 1 2 0 0 1 drop table t1; +create table t1 (a int not null, b int, primary key (a)); +insert into t1 values (1,1); +create table if not exists t1 select 2; +select * from t1; +a b +1 1 +0 2 +create table if not exists t1 select 3 as 'a',4 as 'b'; +create table if not exists t1 select 3 as 'a',3 as 'b'; +Duplicate entry '3' for key 1 +select * from t1; +a b +1 1 +0 2 +3 4 +drop table t1; diff --git a/mysql-test/t/create.test b/mysql-test/t/create.test index 815aad560b1..8aee586268f 100644 --- a/mysql-test/t/create.test +++ b/mysql-test/t/create.test @@ -18,21 +18,30 @@ drop table if exists t1; # Test of some CREATE TABLE'S that should fail # -!$1146 create table t2 type=heap select * from t1; -!$1146 create table t2 select auto+1 from t1; +--error 1146 +create table t2 type=heap select * from t1; +--error 1146 +create table t2 select auto+1 from t1; drop table if exists t1,t2; -!$1167 create table t1 (b char(0) not null, index(b)); -!$1164 create table t1 (a int not null auto_increment,primary key (a)) type=heap; -!$1163 create table t1 (a int not null,b text) type=heap; +--error 1167 +create table t1 (b char(0) not null, index(b)); +--error 1164 +create table t1 (a int not null auto_increment,primary key (a)) type=heap; +--error 1163 +create table t1 (a int not null,b text) type=heap; drop table if exists t1; -!$1164 create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) type=heap; +--error 1164 +create table t1 (ordid int(8) not null auto_increment, ord varchar(50) not null, primary key (ord,ordid)) type=heap; -- error 1044,1 create table not_existing_database.test (a int); -!$1103 create table `a/a` (a int); -!$1103 create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int); -!$1059 create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int); +--error 1103 +create table `a/a` (a int); +--error 1103 +create table `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa int); +--error 1059 +create table a (`aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa` int); # # test of dummy table names @@ -123,9 +132,12 @@ drop table t1; # create table t1 ( k1 varchar(2), k2 int, primary key(k1,k2)); insert into t1 values ("a", 1), ("b", 2); -!$1048 insert into t1 values ("c", NULL); -!$1048 insert into t1 values (NULL, 3); -!$1048 insert into t1 values (NULL, NULL); +--error 1048 +insert into t1 values ("c", NULL); +--error 1048 +insert into t1 values (NULL, 3); +--error 1048 +insert into t1 values (NULL, NULL); drop table t1; # @@ -154,3 +166,16 @@ create table if not exists t1 select 1; select * from t1; drop table t1; +# +# Test create table if not exists with duplicate key error +# + +create table t1 (a int not null, b int, primary key (a)); +insert into t1 values (1,1); +create table if not exists t1 select 2; +select * from t1; +create table if not exists t1 select 3 as 'a',4 as 'b'; +--error 1062 +create table if not exists t1 select 3 as 'a',3 as 'b'; +select * from t1; +drop table t1; diff --git a/mysys/my_chsize.c b/mysys/my_chsize.c index 8e46b0808c0..653ea569172 100644 --- a/mysys/my_chsize.c +++ b/mysys/my_chsize.c @@ -51,16 +51,17 @@ int my_chsize(File fd, my_off_t newlength, int filler, myf MyFlags) #if defined(HAVE_SETFILEPOINTER) /* This is for the moment only true on windows */ { + long is_success; HANDLE win_file= (HANDLE) _get_osfhandle(fd); long length_low, length_high; length_low= (long) (ulong) newlength; length_high= (long) ((ulonglong) newlength >> 32); - if (SetFilePointer(win_file, length_low, &length_high, FILE_BEGIN)) - { - if (SetEndOfFile(win_file)) - DBUG_RETURN(0); - } - my_errno= errno; + is_success= SetFilePointer(win_file, length_low, &length_high, FILE_BEGIN); + if (is_success == -1 && (my_errno= GetLastError()) != NO_ERROR) + goto err; + if (SetEndOfFile(win_file)) + DBUG_RETURN(0); + my_errno= GetLastError(); goto err; } #elif defined(HAVE_FTRUNCATE) diff --git a/sql/handler.h b/sql/handler.h index dfcfa44fbcd..03568e2e070 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -149,21 +149,21 @@ enum enum_tx_isolation { ISO_READ_UNCOMMITTED, ISO_READ_COMMITTED, typedef struct st_ha_create_information { - ulong table_options; - enum db_type db_type; - enum row_type row_type; - ulong avg_row_length; - ulonglong max_rows,min_rows; - ulonglong auto_increment_value; char *comment,*password; char *data_file_name, *index_file_name; - uint options; /* OR of HA_CREATE_ options */ - uint raid_type,raid_chunks; + ulonglong max_rows,min_rows; + ulonglong auto_increment_value; + ulong table_options; + ulong avg_row_length; ulong raid_chunksize; - bool if_not_exists; ulong used_fields; SQL_LIST merge_list; + enum db_type db_type; + enum row_type row_type; + uint options; /* OR of HA_CREATE_ options */ + uint raid_type,raid_chunks; uint merge_insert_method; + bool table_existed; /* 1 in create if table existed */ } HA_CREATE_INFO; diff --git a/sql/slave.cc b/sql/slave.cc index 12698c8eda4..9c380408291 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -2719,6 +2719,8 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ RPL_LOG_NAME, llstr(rli->master_log_pos,llbuff)); err: + /* Free temporary tables etc */ + thd->cleanup(); VOID(pthread_mutex_lock(&LOCK_thread_count)); thd->query = thd->db = 0; // extra safety VOID(pthread_mutex_unlock(&LOCK_thread_count)); diff --git a/sql/sql_class.h b/sql/sql_class.h index 7c663ce831b..27258c025d8 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -708,7 +708,6 @@ class select_create: public select_insert { HA_CREATE_INFO *create_info; MYSQL_LOCK *lock; Field **field; - my_bool do_not_drop; public: select_create (const char *db_name, const char *table_name, HA_CREATE_INFO *create_info_par, @@ -717,7 +716,7 @@ public: List &select_fields,enum_duplicates duplic) :select_insert (NULL, &select_fields, duplic), db(db_name), name(table_name), extra_fields(&fields_par),keys(&keys_par), - create_info(create_info_par), lock(0), do_not_drop(0) + create_info(create_info_par), lock(0) {} int prepare(List &list); bool send_data(List &values); @@ -725,6 +724,7 @@ public: void abort(); }; + class select_union :public select_result { public: TABLE *table; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index ad08ad6ccd6..3aefee61c27 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1440,7 +1440,6 @@ select_create::prepare(List &values) if (table->fields < values.elements) { - do_not_drop=1; my_printf_error(ER_WRONG_VALUE_COUNT_ON_ROW, ER(ER_WRONG_VALUE_COUNT_ON_ROW), MYF(0),1); @@ -1528,7 +1527,7 @@ void select_create::abort() enum db_type table_type=table->db_type; if (!table->tmp_table) hash_delete(&open_cache,(byte*) table); - if (!do_not_drop) + if (!create_info->table_existed) quick_rm_table(table_type,db,name); table=0; } diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 79105a94dec..94ecf33b9c6 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -728,7 +728,10 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, && find_temporary_table(thd,db,table_name)) { if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS) + { + create_info->table_existed= 1; // Mark that table existed DBUG_RETURN(0); + } my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); DBUG_RETURN(-1); } @@ -739,13 +742,17 @@ int mysql_create_table(THD *thd,const char *db, const char *table_name, { VOID(pthread_mutex_unlock(&LOCK_open)); if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS) + { + create_info->table_existed= 1; // Mark that table existed DBUG_RETURN(0); + } my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name); DBUG_RETURN(-1); } } thd->proc_info="creating table"; + create_info->table_existed= 0; // Mark that table is created if (thd->sql_mode & MODE_NO_DIR_IN_CREATE) create_info->data_file_name= create_info->index_file_name= 0;