From ec54dcb054d5de896b39d3e61a8afba1d8b35915 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Fri, 17 Jun 2005 08:56:04 -0700 Subject: [PATCH 01/42] Fix spurious permissions problem when CONVERT_TZ() is used in a multi-table update query. (Bug #9979) --- mysql-test/r/timezone_grant.result | 7 +++++++ mysql-test/t/timezone_grant.test | 12 ++++++++++++ sql/sql_parse.cc | 5 +++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/timezone_grant.result b/mysql-test/r/timezone_grant.result index 685f8007ac7..471cacde300 100644 --- a/mysql-test/r/timezone_grant.result +++ b/mysql-test/r/timezone_grant.result @@ -45,6 +45,13 @@ select * from mysql.time_zone_name; ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for table 'time_zone_name' select Name, convert_tz('2004-11-30 12:00:00', Name, 'UTC') from mysql.time_zone_name; ERROR 42000: SELECT command denied to user 'mysqltest_1'@'localhost' for table 'time_zone_name' +drop table t1, t2; +create table t1 (a int, b datetime); +create table t2 (a int, b varchar(40)); +update t1 set b = '2005-01-01 10:00'; +update t1 set b = convert_tz(b, 'UTC', 'UTC'); +update t1 join t2 on (t1.a = t2.a) set t1.b = '2005-01-01 10:00' where t2.b = 'foo'; +update t1 join t2 on (t1.a = t2.a) set t1.b = convert_tz('2005-01-01 10:00','UTC','UTC') where t2.b = 'foo'; delete from mysql.user where user like 'mysqltest\_%'; delete from mysql.db where user like 'mysqltest\_%'; delete from mysql.tables_priv where user like 'mysqltest\_%'; diff --git a/mysql-test/t/timezone_grant.test b/mysql-test/t/timezone_grant.test index 501315668f5..8627866a0bf 100644 --- a/mysql-test/t/timezone_grant.test +++ b/mysql-test/t/timezone_grant.test @@ -61,6 +61,18 @@ select * from mysql.time_zone_name; --error 1142 select Name, convert_tz('2004-11-30 12:00:00', Name, 'UTC') from mysql.time_zone_name; +# +# Bug #9979: Use of CONVERT_TZ in multiple-table UPDATE causes bogus +# privilege error +# +drop table t1, t2; +create table t1 (a int, b datetime); +create table t2 (a int, b varchar(40)); +update t1 set b = '2005-01-01 10:00'; +update t1 set b = convert_tz(b, 'UTC', 'UTC'); +update t1 join t2 on (t1.a = t2.a) set t1.b = '2005-01-01 10:00' where t2.b = 'foo'; +update t1 join t2 on (t1.a = t2.a) set t1.b = convert_tz('2005-01-01 10:00','UTC','UTC') where t2.b = 'foo'; + # Clean-up connection default; delete from mysql.user where user like 'mysqltest\_%'; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f0ea0a762bd..a515441ee1b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1938,7 +1938,8 @@ mysql_execute_command(THD *thd) that is not a SHOW command or a select that only access local variables, but for now this is probably good enough. */ - if (tables || &lex->select_lex != lex->all_selects_list) + if (tables || &lex->select_lex != lex->all_selects_list || + lex->time_zone_tables_used) mysql_reset_errors(thd); #ifdef HAVE_REPLICATION @@ -5354,7 +5355,7 @@ int multi_update_precheck(THD *thd, TABLE_LIST *tables) /* Is there tables of subqueries? */ - if (&lex->select_lex != lex->all_selects_list) + if (&lex->select_lex != lex->all_selects_list || lex->time_zone_tables_used) { DBUG_PRINT("info",("Checking sub query list")); for (table= tables; table; table= table->next) From de9909faec7ae81b7946f314b97ff2da8be7fe2e Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Thu, 7 Jul 2005 11:49:44 -0700 Subject: [PATCH 02/42] Fix crash caused by calling DES_ENCRYPT() without the --des-key-file option having been passed to the server. (Bug #11643) --- BitKeeper/etc/config | 2 +- mysql-test/r/func_des_encrypt.result | 3 +++ mysql-test/t/func_des_encrypt.test | 9 +++++++++ sql/des_key_file.cc | 18 ++++++++++++------ sql/item_strfunc.cc | 11 +++++++++++ sql/mysql_priv.h | 1 + 6 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 mysql-test/r/func_des_encrypt.result create mode 100644 mysql-test/t/func_des_encrypt.test diff --git a/BitKeeper/etc/config b/BitKeeper/etc/config index c609fcdbd49..f1e8e29fbfb 100644 --- a/BitKeeper/etc/config +++ b/BitKeeper/etc/config @@ -24,7 +24,7 @@ description: MySQL - fast and reliable SQL database # repository is commercial it can be an internal email address or "none" # to disable logging. # -logging: logging@openlogging.org +logging: none # # If this field is set, all checkins will appear to be made by this user, # in effect making this a single user package. Single user packages are diff --git a/mysql-test/r/func_des_encrypt.result b/mysql-test/r/func_des_encrypt.result new file mode 100644 index 00000000000..46b30bdab58 --- /dev/null +++ b/mysql-test/r/func_des_encrypt.result @@ -0,0 +1,3 @@ +select des_encrypt('hello'); +des_encrypt('hello') +€Ö2nV“Ø} diff --git a/mysql-test/t/func_des_encrypt.test b/mysql-test/t/func_des_encrypt.test new file mode 100644 index 00000000000..201a0051c58 --- /dev/null +++ b/mysql-test/t/func_des_encrypt.test @@ -0,0 +1,9 @@ +-- source include/have_openssl.inc + +# This test can't be in func_encrypt.test, because it requires +# --des-key-file to not be set. + +# +# Bug #11643: des_encrypt() causes server to die +# +select des_encrypt('hello'); diff --git a/sql/des_key_file.cc b/sql/des_key_file.cc index c6b4c5f2c34..558e3f16ad2 100644 --- a/sql/des_key_file.cc +++ b/sql/des_key_file.cc @@ -22,7 +22,17 @@ struct st_des_keyschedule des_keyschedule[10]; uint des_default_key; pthread_mutex_t LOCK_des_key_file; -static int initialized; +static int initialized= 0; + +void +init_des_key_file() +{ + if (!initialized) + { + initialized=1; + pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); + } +} /* Function which loads DES keys from plaintext file into memory on MySQL @@ -45,11 +55,7 @@ load_des_key_file(const char *file_name) DBUG_ENTER("load_des_key_file"); DBUG_PRINT("enter",("name: %s",file_name)); - if (!initialized) - { - initialized=1; - pthread_mutex_init(&LOCK_des_key_file,MY_MUTEX_INIT_FAST); - } + init_des_key_file(); VOID(pthread_mutex_lock(&LOCK_des_key_file)); if ((file=my_open(file_name,O_RDONLY | O_BINARY ,MYF(MY_WME))) < 0 || diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 881a8a7c915..7fb27470b8e 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -388,6 +388,9 @@ String *Item_func_des_encrypt::val_str(String *str) if (arg_count == 1) { + /* Make sure LOCK_des_key_file was initialized. */ + init_des_key_file(); + /* Protect against someone doing FLUSH DES_KEY_FILE */ VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number=des_default_key]; @@ -398,6 +401,10 @@ String *Item_func_des_encrypt::val_str(String *str) key_number= (uint) args[1]->val_int(); if (key_number > 9) goto error; + + /* Make sure LOCK_des_key_file was initialized. */ + init_des_key_file(); + VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number]; VOID(pthread_mutex_unlock(&LOCK_des_key_file)); @@ -485,6 +492,10 @@ String *Item_func_des_decrypt::val_str(String *str) // Check if automatic key and that we have privilege to uncompress using it if (!(current_thd->master_access & SUPER_ACL) || key_number > 9) goto error; + + /* Make sure LOCK_des_key_file was initialized. */ + init_des_key_file(); + VOID(pthread_mutex_lock(&LOCK_des_key_file)); keyschedule= des_keyschedule[key_number]; VOID(pthread_mutex_unlock(&LOCK_des_key_file)); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index cc58e34d582..5c97269b5ce 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -624,6 +624,7 @@ extern char *des_key_file; extern struct st_des_keyschedule des_keyschedule[10]; extern uint des_default_key; extern pthread_mutex_t LOCK_des_key_file; +void init_des_key_file(); bool load_des_key_file(const char *file_name); void free_des_key_file(); #endif /* HAVE_OPENSSL */ From e3feff334f7d9fc4bd361c3d3329f84c1fdea21b Mon Sep 17 00:00:00 2001 From: "joerg@mysql.com" <> Date: Mon, 11 Jul 2005 15:59:49 +0200 Subject: [PATCH 03/42] cmd-line-utils/libedit/chared.c: Fix compile problem caused by use of "uint" which is undefined on QNX. --- cmd-line-utils/libedit/chared.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd-line-utils/libedit/chared.c b/cmd-line-utils/libedit/chared.c index 21fc8bc2c1d..4cb6e00d26e 100644 --- a/cmd-line-utils/libedit/chared.c +++ b/cmd-line-utils/libedit/chared.c @@ -51,13 +51,13 @@ cv_undo(EditLine *el) { c_undo_t *vu = &el->el_chared.c_undo; c_redo_t *r = &el->el_chared.c_redo; - uint size; + int size; /* Save entire line for undo */ size = el->el_line.lastchar - el->el_line.buffer; vu->len = size; vu->cursor = el->el_line.cursor - el->el_line.buffer; - memcpy(vu->buf, el->el_line.buffer, size); + memcpy(vu->buf, el->el_line.buffer, (size_t)size); /* save command info for redo */ r->count = el->el_state.doingarg ? el->el_state.argument : 0; From 7ae4a6043c074235fc944e7fba25b903d5a17bb8 Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Mon, 11 Jul 2005 10:37:21 -0700 Subject: [PATCH 04/42] Apply security patch to bundled zlib for CAN-2005-2096. (Bug #11844) --- zlib/inftrees.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zlib/inftrees.c b/zlib/inftrees.c index 8a896b28793..509461d9273 100644 --- a/zlib/inftrees.c +++ b/zlib/inftrees.c @@ -134,7 +134,7 @@ unsigned short FAR *work; left -= count[len]; if (left < 0) return -1; /* over-subscribed */ } - if (left > 0 && (type == CODES || (codes - count[0] != 1))) + if (left > 0 && (type == CODES || max != 1)) return -1; /* incomplete set */ /* generate offsets into symbol table for each length for sorting */ From dc55af92ffee58f45f9c53cbeda7ca34931f2f74 Mon Sep 17 00:00:00 2001 From: "lars@mysql.com" <> Date: Tue, 12 Jul 2005 06:01:26 +0200 Subject: [PATCH 05/42] BUG#6987: Added note when stat is failing on relay log, added mutex for log rotatation. --- sql/log.cc | 2 ++ sql/slave.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/sql/log.cc b/sql/log.cc index c8a3b512b6d..a67f35e30bf 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -853,6 +853,8 @@ int MYSQL_LOG::purge_logs(const char *to_log, of space that deletion will free. In most cases, deletion won't work either, so it's not a problem. */ + sql_print_information("Failed to execute my_stat on file '%s'", + log_info.log_file_name); tmp= 0; } } diff --git a/sql/slave.cc b/sql/slave.cc index 5a2d3af3845..68769fc1f98 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -4462,6 +4462,7 @@ void rotate_relay_log(MASTER_INFO* mi) RELAY_LOG_INFO* rli= &mi->rli; lock_slave_threads(mi); + pthread_mutex_lock(&mi->data_lock); pthread_mutex_lock(&rli->data_lock); /* We need to test inited because otherwise, new_file() will attempt to lock @@ -4492,6 +4493,7 @@ void rotate_relay_log(MASTER_INFO* mi) rli->relay_log.harvest_bytes_written(&rli->log_space_total); end: pthread_mutex_unlock(&rli->data_lock); + pthread_mutex_unlock(&mi->data_lock); unlock_slave_threads(mi); DBUG_VOID_RETURN; } From c37aece4706a53abf35af22c905c16ef013be62d Mon Sep 17 00:00:00 2001 From: "mskold@mysql.com" <> Date: Tue, 12 Jul 2005 10:39:58 +0200 Subject: [PATCH 06/42] Disabled internal ndb system table test, since it only works on case sensitive systems --- mysql-test/r/ndb_autodiscover.result | 14 -------------- mysql-test/t/ndb_autodiscover.test | 23 ++++++++++++----------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/mysql-test/r/ndb_autodiscover.result b/mysql-test/r/ndb_autodiscover.result index b278d6eb048..5a1a82832fa 100644 --- a/mysql-test/r/ndb_autodiscover.result +++ b/mysql-test/r/ndb_autodiscover.result @@ -358,20 +358,6 @@ Database mysql test use test; -CREATE TABLE sys.SYSTAB_0 (a int); -ERROR 42S01: Table 'SYSTAB_0' already exists -select * from sys.SYSTAB_0; -ERROR HY000: Failed to open 'SYSTAB_0', error while unpacking from engine -CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int); -show warnings; -Level Code Message -select * from sys.SYSTAB_0; -ERROR HY000: Failed to open 'SYSTAB_0', error while unpacking from engine -drop table sys.SYSTAB_0; -ERROR 42S02: Unknown table 'SYSTAB_0' -drop table IF EXISTS sys.SYSTAB_0; -Warnings: -Note 1051 Unknown table 'SYSTAB_0' CREATE TABLE t9 ( a int NOT NULL PRIMARY KEY, b int diff --git a/mysql-test/t/ndb_autodiscover.test b/mysql-test/t/ndb_autodiscover.test index 49ed8c894fe..1eed78b43df 100644 --- a/mysql-test/t/ndb_autodiscover.test +++ b/mysql-test/t/ndb_autodiscover.test @@ -460,19 +460,20 @@ use test; # a table with tha same name as a table that can't be # discovered( for example a table created via NDBAPI) ---error 1050 -CREATE TABLE sys.SYSTAB_0 (a int); ---error 1105 -select * from sys.SYSTAB_0; +# Test disabled since it doesn't work on case insensitive systems +#--error 1050 +#CREATE TABLE sys.SYSTAB_0 (a int); +#--error 1105 +#select * from sys.SYSTAB_0; -CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int); -show warnings; ---error 1105 -select * from sys.SYSTAB_0; +#CREATE TABLE IF NOT EXISTS sys.SYSTAB_0 (a int); +#show warnings; +#--error 1105 +#select * from sys.SYSTAB_0; ---error 1051 -drop table sys.SYSTAB_0; -drop table IF EXISTS sys.SYSTAB_0; +#--error 1051 +#drop table sys.SYSTAB_0; +#drop table IF EXISTS sys.SYSTAB_0; ###################################################### # Note! This should always be the last step in this From 55e70fd1f66cfd259d382e422c60d01cd914e05a Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Tue, 12 Jul 2005 16:30:45 +0000 Subject: [PATCH 07/42] Fix for BUG#11821: Make Item_type_holder be able to work with MIN(field), MAX(field). --- mysql-test/r/subselect.result | 6 ++++++ mysql-test/t/subselect.test | 8 ++++++++ sql/item.cc | 8 ++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index 1f3542802a7..8615c8e661b 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -2721,3 +2721,9 @@ SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessioni ip count( e.itemid ) 10.10.10.1 1 drop tables t1,t2; +create table t1 (fld enum('0','1')); +insert into t1 values ('1'); +select * from (select max(fld) from t1) as foo; +max(fld) +1 +drop table t1; diff --git a/mysql-test/t/subselect.test b/mysql-test/t/subselect.test index e585022563f..12593438805 100644 --- a/mysql-test/t/subselect.test +++ b/mysql-test/t/subselect.test @@ -1746,3 +1746,11 @@ CREATE TABLE `t2` ( INSERT INTO `t2` VALUES (1, 1, 1, '10.10.10.1'); SELECT s.ip, count( e.itemid ) FROM `t1` e JOIN t2 s ON s.sessionid = e.sessionid WHERE e.sessionid = ( SELECT sessionid FROM t2 ORDER BY sessionid DESC LIMIT 1 ) GROUP BY s.ip HAVING count( e.itemid ) >0 LIMIT 0 , 30; drop tables t1,t2; + +# BUG#11821 : Select from subselect using aggregate function on an enum +# segfaults: +create table t1 (fld enum('0','1')); +insert into t1 values ('1'); +select * from (select max(fld) from t1) as foo; +drop table t1; + diff --git a/sql/item.cc b/sql/item.cc index c96794ff482..3bdaf856f2a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3121,9 +3121,13 @@ void Item_type_holder::get_full_info(Item *item) if (fld_type == MYSQL_TYPE_ENUM || fld_type == MYSQL_TYPE_SET) { + if (item->type() == Item::SUM_FUNC_ITEM && + (((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC || + ((Item_sum*)item)->sum_func() == Item_sum::MIN_FUNC)) + item = ((Item_sum*)item)->args[0]; /* - We can have enum/set type after merging only if we have one enum/set - field and number of NULL fields + We can have enum/set type after merging only if we have one enum|set + field (or MIN|MAX(enum|set field)) and number of NULL fields */ DBUG_ASSERT((enum_set_typelib && get_real_type(item) == MYSQL_TYPE_NULL) || From c31d71c065304b7cd1c237174da19a8d4270fb26 Mon Sep 17 00:00:00 2001 From: "reggie@linux.site" <> Date: Tue, 12 Jul 2005 10:31:09 -0600 Subject: [PATCH 08/42] Fixed some vio code that was using ___WIN__ instead of __WIN__ --- include/my_global.h | 2 +- sql/net_serv.cc | 2 +- vio/vio.c | 4 ++-- vio/viosocket.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/my_global.h b/include/my_global.h index a7e6bba82b6..eab6050d2dc 100644 --- a/include/my_global.h +++ b/include/my_global.h @@ -797,7 +797,7 @@ typedef off_t os_off_t; #define socket_errno WSAGetLastError() #define SOCKET_EINTR WSAEINTR #define SOCKET_EAGAIN WSAEINPROGRESS -#define SOCKET_EWOULDBLOCK WSAEINPROGRESS +#define SOCKET_EWOULDBLOCK WSAEWOULDBLOCK #define SOCKET_ENFILE ENFILE #define SOCKET_EMFILE EMFILE #elif defined(OS2) diff --git a/sql/net_serv.cc b/sql/net_serv.cc index bd4505a3d7f..9d84d0b2427 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -132,7 +132,7 @@ my_bool my_net_init(NET *net, Vio* vio) if (vio != 0) /* If real connection */ { net->fd = vio_fd(vio); /* For perl DBI/DBD */ -#if defined(MYSQL_SERVER) && !defined(___WIN__) && !defined(__EMX__) && !defined(OS2) +#if defined(MYSQL_SERVER) && !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) if (!(test_flags & TEST_BLOCKING)) { my_bool old_mode; diff --git a/vio/vio.c b/vio/vio.c index 978780d2632..4660efe3048 100644 --- a/vio/vio.c +++ b/vio/vio.c @@ -130,7 +130,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) sprintf(vio->desc, (vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"), vio->sd); -#if !defined(___WIN__) && !defined(__EMX__) && !defined(OS2) +#if !defined(__WIN__) && !defined(__EMX__) && !defined(OS2) #if !defined(NO_FCNTL_NONBLOCK) #if defined(__FreeBSD__) fcntl(sd, F_SETFL, vio->fcntl_mode); /* Yahoo! FreeBSD patch */ @@ -145,7 +145,7 @@ Vio *vio_new(my_socket sd, enum enum_vio_type type, my_bool localhost) { /* set to blocking mode by default */ ulong arg=0, r; - r = ioctlsocket(sd,FIONBIO,(void*) &arg, sizeof(arg)); + r = ioctlsocket(sd,FIONBIO,(void*) &arg); vio->fcntl_mode &= ~O_NONBLOCK; } #endif diff --git a/vio/viosocket.c b/vio/viosocket.c index 904b75583a9..c7561890ead 100644 --- a/vio/viosocket.c +++ b/vio/viosocket.c @@ -82,7 +82,7 @@ int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode, DBUG_PRINT("enter", ("set_blocking_mode: %d old_mode: %d", (int) set_blocking_mode, (int) *old_mode)); -#if !defined(___WIN__) && !defined(__EMX__) +#if !defined(__WIN__) && !defined(__EMX__) #if !defined(NO_FCNTL_NONBLOCK) if (vio->sd >= 0) { @@ -115,7 +115,7 @@ int vio_blocking(Vio * vio __attribute__((unused)), my_bool set_blocking_mode, vio->fcntl_mode |= O_NONBLOCK; /* set bit */ } if (old_fcntl != vio->fcntl_mode) - r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg, sizeof(arg)); + r = ioctlsocket(vio->sd,FIONBIO,(void*) &arg); } #ifndef __EMX__ else From 5150fdcc04efca4e2dd7bb435bc0e3438cc2f5be Mon Sep 17 00:00:00 2001 From: "bar@mysql.com" <> Date: Wed, 13 Jul 2005 13:00:17 +0500 Subject: [PATCH 09/42] ctype_utf8.result: adding test case sql_table.cc: sql_table.cc: - do not create a new item when charsets are the same - return ER_INVALID_DEFAULT if default value cannot be converted into the column character set. item.cc: - Allow conversion not only to Unicode, but also to and from "binary". - Adding safe_charset_converter() for Item_num and Item_varbinary, returning a fixed const Item. --- mysql-test/r/ctype_utf8.result | 4 ++++ mysql-test/t/ctype_utf8.test | 9 +++++++ sql/item.cc | 44 +++++++++++++++++++++++++++++++++- sql/item.h | 2 ++ sql/sql_table.cc | 11 ++++++--- 5 files changed, 66 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 3a8265b01f7..290d6d93421 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -905,6 +905,10 @@ select * from t1 where city = 'Durban '; id city 2 Durban drop table t1; +create table t1 (x set('A', 'B') default 0) character set utf8; +ERROR 42000: Invalid default value for 'x' +create table t1 (x enum('A', 'B') default 0) character set utf8; +ERROR 42000: Invalid default value for 'x' SET NAMES UTF8; CREATE TABLE t1 ( `id` int(20) NOT NULL auto_increment, diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 0a847057258..638d1f1de5c 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -747,6 +747,15 @@ select * from t1 where city = 'Durban'; select * from t1 where city = 'Durban '; drop table t1; +# +# Bug #11819 CREATE TABLE with a SET DEFAULT 0 and UTF8 crashes server. +# +--error 1067 +create table t1 (x set('A', 'B') default 0) character set utf8; +--error 1067 +create table t1 (x enum('A', 'B') default 0) character set utf8; + + # # Test for bug #11167: join for utf8 varchar value longer than 255 bytes # diff --git a/sql/item.cc b/sql/item.cc index c96794ff482..ee78d596891 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -212,15 +212,43 @@ bool Item::eq(const Item *item, bool binary_cmp) const Item *Item::safe_charset_converter(CHARSET_INFO *tocs) { /* + Allow conversion from and to "binary". Don't allow automatic conversion to non-Unicode charsets, as it potentially loses data. */ - if (!(tocs->state & MY_CS_UNICODE)) + if (collation.collation != &my_charset_bin && + tocs != &my_charset_bin && + !(tocs->state & MY_CS_UNICODE)) return NULL; // safe conversion is not possible return new Item_func_conv_charset(this, tocs); } +/* + Created mostly for mysql_prepare_table(). Important + when a string ENUM/SET column is described with a numeric default value: + + CREATE TABLE t1(a SET('a') DEFAULT 1); + + We cannot use generic Item::safe_charset_converter(), because + the latter returns a non-fixed Item, so val_str() crashes afterwards. + Override Item_num method, to return a fixed item. +*/ +Item *Item_num::safe_charset_converter(CHARSET_INFO *tocs) +{ + Item_string *conv; + char buf[64]; + String *s, tmp(buf, sizeof(buf), &my_charset_bin); + s= val_str(&tmp); + if ((conv= new Item_string(s->ptr(), s->length(), s->charset()))) + { + conv->str_value.copy(); + conv->str_value.shrink_to_length(); + } + return conv; +} + + Item *Item_string::safe_charset_converter(CHARSET_INFO *tocs) { Item_string *conv; @@ -2151,6 +2179,20 @@ bool Item_varbinary::eq(const Item *arg, bool binary_cmp) const return FALSE; } + +Item *Item_varbinary::safe_charset_converter(CHARSET_INFO *tocs) +{ + Item_string *conv; + String tmp, *str= val_str(&tmp); + + if (!(conv= new Item_string(str->ptr(), str->length(), tocs))) + return NULL; + conv->str_value.copy(); + conv->str_value.shrink_to_length(); + return conv; +} + + /* Pack data in buffer for sending */ diff --git a/sql/item.h b/sql/item.h index 8de2adeb730..20d6718609c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -334,6 +334,7 @@ class Item_num: public Item { public: virtual Item_num *neg()= 0; + Item *safe_charset_converter(CHARSET_INFO *tocs); }; #define NO_CACHED_FIELD_INDEX ((uint)(-1)) @@ -835,6 +836,7 @@ public: // to prevent drop fixed flag (no need parent cleanup call) void cleanup() {} bool eq(const Item *item, bool binary_cmp) const; + virtual Item *safe_charset_converter(CHARSET_INFO *tocs); }; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index b68b20c32a3..e27cd7196ed 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -557,10 +557,15 @@ int mysql_prepare_table(THD *thd, HA_CREATE_INFO *create_info, Convert the default value from client character set into the column character set if necessary. */ - if (sql_field->def) + if (sql_field->def && cs != sql_field->def->collation.collation) { - sql_field->def= - sql_field->def->safe_charset_converter(cs); + if (!(sql_field->def= + sql_field->def->safe_charset_converter(cs))) + { + /* Could not convert */ + my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name); + DBUG_RETURN(-1); + } } if (sql_field->sql_type == FIELD_TYPE_SET) From 672e1f20cb0d98b7d3330e367fe0c78b48a39f93 Mon Sep 17 00:00:00 2001 From: "gluh@eagle.intranet.mysql.r18.ru" <> Date: Wed, 13 Jul 2005 14:23:09 +0500 Subject: [PATCH 10/42] Bug #9854 hex() and out of range handling added out of range handling --- mysql-test/r/func_str.result | 3 +++ mysql-test/t/func_str.test | 5 +++++ sql/item_strfunc.cc | 16 ++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index fb2716fd232..18a04574596 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -865,3 +865,6 @@ abc abc c bc abc abcd abcd d cd bcd abcd abcde abcde e de cde bcde abcde drop table t1; +select hex(29223372036854775809), hex(-29223372036854775809); +hex(29223372036854775809) hex(-29223372036854775809) +FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 668e865d73a..ae3cdc361ab 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -606,3 +606,8 @@ insert t1 values ('ab'), ('abc'), ('abcd'), ('abcde'); select *,substring(b,1),substring(b,-1),substring(b,-2),substring(b,-3),substring(b,-4),substring(b,-5) from t1; select * from (select *,substring(b,1),substring(b,-1),substring(b,-2),substring(b,-3),substring(b,-4),substring(b,-5) from t1) t; drop table t1; + +# +# Bug #9854 hex() and out of range handling +# +select hex(29223372036854775809), hex(-29223372036854775809); diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index d57b3b89bf9..6a4dd0d7418 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2348,9 +2348,21 @@ String *Item_func_hex::val_str(String *str) DBUG_ASSERT(fixed == 1); if (args[0]->result_type() != STRING_RESULT) { - /* Return hex of unsigned longlong value */ - longlong dec= args[0]->val_int(); + ulonglong dec; char ans[65],*ptr; + /* Return hex of unsigned longlong value */ + if (args[0]->result_type() == REAL_RESULT) + { + double val= args[0]->val(); + if ((val <= (double) LONGLONG_MIN) || + (val >= (double) (ulonglong) ULONGLONG_MAX)) + dec= ~(longlong) 0; + else + dec= (ulonglong) (val + (val > 0 ? 0.5 : -0.5)); + } + else + dec= (ulonglong) args[0]->val_int(); + if ((null_value= args[0]->null_value)) return 0; ptr= longlong2str(dec,ans,16); From 1826c398970de0ea20f7329b63768512f0184dbd Mon Sep 17 00:00:00 2001 From: "mats@mysql.com" <> Date: Wed, 13 Jul 2005 13:49:35 +0200 Subject: [PATCH 11/42] Bug#11905: Tables used in rpl_deadlock are not dropped at the end of the test, causing subsequent tests to fail. --- mysql-test/r/rpl_deadlock.result | 2 +- mysql-test/t/rpl_deadlock.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/rpl_deadlock.result b/mysql-test/r/rpl_deadlock.result index 8808a973855..8eb9d64fcae 100644 --- a/mysql-test/r/rpl_deadlock.result +++ b/mysql-test/r/rpl_deadlock.result @@ -84,4 +84,4 @@ a show slave status; Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master # 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 13110 # # master-bin.000001 Yes Yes 0 0 13110 # None 0 No # -drop table t1,t2; +drop table t1,t2,t3,t4; diff --git a/mysql-test/t/rpl_deadlock.test b/mysql-test/t/rpl_deadlock.test index 9ad6362f7e7..da932df5347 100644 --- a/mysql-test/t/rpl_deadlock.test +++ b/mysql-test/t/rpl_deadlock.test @@ -107,5 +107,5 @@ select * from t2; show slave status; connection master; -drop table t1,t2; +drop table t1,t2,t3,t4; sync_slave_with_master; From bef558b7ee2ebfd091949194354e4b4c33ef12fc Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Wed, 13 Jul 2005 17:38:55 +0400 Subject: [PATCH 12/42] - a fix for Bug#11458 "Prepared statement with subselects return random data": remove the fix for another bug (8807) that added OUTER_REF_TABLE_BIT to all subqueries that used a placeholder to prevent their evaluation at prepare. As this bit hanged in Item_subselect::used_tables_cache for ever, a constant subquery with a placeholder was never evaluated as such, which caused wrong choice of the execution plan for the statement. - to fix Bug#8807 backport a better fix from 5.0 - post-review fixes. --- mysql-test/r/ps.result | 57 +++++++++++++++++++++++++++++++++++ mysql-test/t/ps.test | 68 ++++++++++++++++++++++++++++++++++++++++++ sql/item.cc | 29 +----------------- sql/item.h | 1 - sql/item_subselect.h | 1 - sql/mysql_priv.h | 2 ++ sql/sql_lex.h | 1 + sql/sql_parse.cc | 8 +++++ sql/sql_prepare.cc | 13 +++++--- 9 files changed, 146 insertions(+), 34 deletions(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index ca38f1c75cb..b1b06dc4019 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -563,3 +563,60 @@ execute stmt; execute stmt; deallocate prepare stmt; drop table t1; +create table t1 ( +id int(11) unsigned not null primary key auto_increment, +partner_id varchar(35) not null, +t1_status_id int(10) unsigned +); +insert into t1 values ("1", "partner1", "10"), ("2", "partner2", "10"), +("3", "partner3", "10"), ("4", "partner4", "10"); +create table t2 ( +id int(11) unsigned not null default '0', +t1_line_id int(11) unsigned not null default '0', +article_id varchar(20), +sequence int(11) not null default '0', +primary key (id,t1_line_id) +); +insert into t2 values ("1", "1", "sup", "0"), ("2", "1", "sup", "1"), +("2", "2", "sup", "2"), ("2", "3", "sup", "3"), +("2", "4", "imp", "4"), ("3", "1", "sup", "0"), +("4", "1", "sup", "0"); +create table t3 ( +id int(11) not null default '0', +preceeding_id int(11) not null default '0', +primary key (id,preceeding_id) +); +create table t4 ( +user_id varchar(50) not null, +article_id varchar(20) not null, +primary key (user_id,article_id) +); +insert into t4 values("nicke", "imp"); +prepare stmt from +'select distinct t1.partner_id +from t1 left join t3 on t1.id = t3.id + left join t1 pp on pp.id = t3.preceeding_id +where + exists ( + select * + from t2 as pl_inner + where pl_inner.id = t1.id + and pl_inner.sequence <= ( + select min(sequence) from t2 pl_seqnr + where pl_seqnr.id = t1.id + ) + and exists ( + select * from t4 + where t4.article_id = pl_inner.article_id + and t4.user_id = ? + ) + ) + and t1.id = ? +group by t1.id +having count(pp.id) = 0'; +set @user_id = 'nicke'; +set @id = '2'; +execute stmt using @user_id, @id; +partner_id +execute stmt using @user_id, @id; +partner_id diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index bb1052c7337..24276acf933 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -581,3 +581,71 @@ execute stmt; execute stmt; deallocate prepare stmt; drop table t1; + +# +# Bug#11458 "Prepared statement with subselects return random data": +# drop PARAM_TABLE_BIT from the list of tables used by a subquery +# +create table t1 ( + id int(11) unsigned not null primary key auto_increment, + partner_id varchar(35) not null, + t1_status_id int(10) unsigned +); + +insert into t1 values ("1", "partner1", "10"), ("2", "partner2", "10"), + ("3", "partner3", "10"), ("4", "partner4", "10"); + +create table t2 ( + id int(11) unsigned not null default '0', + t1_line_id int(11) unsigned not null default '0', + article_id varchar(20), + sequence int(11) not null default '0', + primary key (id,t1_line_id) +); + +insert into t2 values ("1", "1", "sup", "0"), ("2", "1", "sup", "1"), + ("2", "2", "sup", "2"), ("2", "3", "sup", "3"), + ("2", "4", "imp", "4"), ("3", "1", "sup", "0"), + ("4", "1", "sup", "0"); + +create table t3 ( + id int(11) not null default '0', + preceeding_id int(11) not null default '0', + primary key (id,preceeding_id) +); + +create table t4 ( + user_id varchar(50) not null, + article_id varchar(20) not null, + primary key (user_id,article_id) +); + +insert into t4 values("nicke", "imp"); + +prepare stmt from +'select distinct t1.partner_id +from t1 left join t3 on t1.id = t3.id + left join t1 pp on pp.id = t3.preceeding_id +where + exists ( + select * + from t2 as pl_inner + where pl_inner.id = t1.id + and pl_inner.sequence <= ( + select min(sequence) from t2 pl_seqnr + where pl_seqnr.id = t1.id + ) + and exists ( + select * from t4 + where t4.article_id = pl_inner.article_id + and t4.user_id = ? + ) + ) + and t1.id = ? +group by t1.id +having count(pp.id) = 0'; +set @user_id = 'nicke'; +set @id = '2'; +execute stmt using @user_id, @id; +execute stmt using @user_id, @id; + diff --git a/sql/item.cc b/sql/item.cc index 3bdaf856f2a..19b88c115b9 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -889,6 +889,7 @@ void Item_param::set_null() max_length= 0; decimals= 0; state= NULL_VALUE; + item_type= Item::NULL_ITEM; DBUG_VOID_RETURN; } @@ -1339,34 +1340,6 @@ bool Item_param::convert_str_value(THD *thd) return rc; } -bool Item_param::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) -{ - DBUG_ASSERT(fixed == 0); - SELECT_LEX *cursel= (SELECT_LEX *) thd->lex->current_select; - - /* - Parameters in a subselect should mark the subselect as not constant - during prepare - */ - if (state == NO_VALUE) - { - /* - SELECT_LEX_UNIT::item set only for subqueries, so test of it presence - can be barrier to stop before derived table SELECT or very outer SELECT - */ - for(; - cursel->master_unit()->item; - cursel= cursel->outer_select()) - { - Item_subselect *subselect_item= cursel->master_unit()->item; - subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT; - subselect_item->const_item_cache= 0; - } - } - fixed= 1; - return 0; -} - bool Item_param::basic_const_item() const { diff --git a/sql/item.h b/sql/item.h index 8de2adeb730..a8b0bfe9512 100644 --- a/sql/item.h +++ b/sql/item.h @@ -564,7 +564,6 @@ public: bool get_time(TIME *tm); bool get_date(TIME *tm, uint fuzzydate); int save_in_field(Field *field, bool no_conversions); - bool fix_fields(THD *, struct st_table_list *, Item **); void set_null(); void set_int(longlong i, uint32 max_length_arg); diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 20ba838e61c..dec32398a80 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -119,7 +119,6 @@ public: friend class Item_in_optimizer; friend bool Item_field::fix_fields(THD *, TABLE_LIST *, Item **); friend bool Item_ref::fix_fields(THD *, TABLE_LIST *, Item **); - friend bool Item_param::fix_fields(THD *, TABLE_LIST *, Item **); }; /* single value subselect */ diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index cc58e34d582..953bcf5585c 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -251,6 +251,8 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset; #define UNCACHEABLE_SIDEEFFECT 4 // forcing to save JOIN for explain #define UNCACHEABLE_EXPLAIN 8 +/* Don't evaluate subqueries in prepare even if they're not correlated */ +#define UNCACHEABLE_PREPARE 16 #ifdef EXTRA_DEBUG /* diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 927982e444f..07b5c9d8edf 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -257,6 +257,7 @@ public: UNCACHEABLE_RAND UNCACHEABLE_SIDEEFFECT UNCACHEABLE_EXPLAIN + UNCACHEABLE_PREPARE */ uint8 uncacheable; enum sub_select_type linkage; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index d7fd3239df5..dc55a842263 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -4123,6 +4123,14 @@ mysql_new_select(LEX *lex, bool move_down) select_lex->select_number= ++lex->thd->select_number; select_lex->init_query(); select_lex->init_select(); + /* + Don't evaluate this subquery during statement prepare even if + it's a constant one. The flag is switched off in the end of + mysql_stmt_prepare. + */ + if (lex->thd->current_arena->is_stmt_prepare()) + select_lex->uncacheable|= UNCACHEABLE_PREPARE; + if (move_down) { lex->subqueries= TRUE; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 9e2612c5661..f7e2bd0467e 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1657,13 +1657,18 @@ int mysql_stmt_prepare(THD *thd, char *packet, uint packet_length, { stmt->setup_set_params(); SELECT_LEX *sl= stmt->lex->all_selects_list; - /* - Save WHERE clause pointers, because they may be changed during query - optimisation. - */ for (; sl; sl= sl->next_select_in_list()) { + /* + Save WHERE clause pointers, because they may be changed + during query optimisation. + */ sl->prep_where= sl->where; + /* + Switch off a temporary flag that prevents evaluation of + subqueries in statement prepare. + */ + sl->uncacheable&= ~UNCACHEABLE_PREPARE; } stmt->state= Item_arena::PREPARED; } From ae949ccdd59255f7f52cc17d201a485e1eb871b6 Mon Sep 17 00:00:00 2001 From: "joerg@mysql.com" <> Date: Wed, 13 Jul 2005 15:55:22 +0200 Subject: [PATCH 13/42] 4.1.13 has been cloned off --- configure.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index 0889e9a3257..af7ce8b1c3d 100644 --- a/configure.in +++ b/configure.in @@ -5,7 +5,7 @@ AC_INIT(sql/mysqld.cc) AC_CANONICAL_SYSTEM # The Docs Makefile.am parses this line! # remember to also change ndb version below and update version.c in ndb -AM_INIT_AUTOMAKE(mysql, 4.1.13) +AM_INIT_AUTOMAKE(mysql, 4.1.14) AM_CONFIG_HEADER(config.h) PROTOCOL_VERSION=10 @@ -16,7 +16,7 @@ SHARED_LIB_VERSION=14:0:0 # ndb version NDB_VERSION_MAJOR=4 NDB_VERSION_MINOR=1 -NDB_VERSION_BUILD=13 +NDB_VERSION_BUILD=14 NDB_VERSION_STATUS="" # Set all version vars based on $VERSION. How do we do this more elegant ? From 2dc2ec3ef75f618a2042d10d76c51735e3a2ae7c Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Wed, 13 Jul 2005 18:01:04 +0400 Subject: [PATCH 14/42] Cleanup after test for Bug#11458 --- mysql-test/r/ps.result | 2 ++ mysql-test/t/ps.test | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index b1b06dc4019..566dac07fd5 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -620,3 +620,5 @@ execute stmt using @user_id, @id; partner_id execute stmt using @user_id, @id; partner_id +deallocate prepare stmt; +drop table t1, t2, t3, t4; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 24276acf933..a25d4447c20 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -648,4 +648,5 @@ set @user_id = 'nicke'; set @id = '2'; execute stmt using @user_id, @id; execute stmt using @user_id, @id; - +deallocate prepare stmt; +drop table t1, t2, t3, t4; From 1755df76498e9ce0941800525a488ae45b841074 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Wed, 13 Jul 2005 23:43:46 +0400 Subject: [PATCH 15/42] A fix and a test case for Bug#9379 (collation of a parameter marker is binary). --- mysql-test/r/ps.result | 19 +++++++++++++++++++ mysql-test/t/ps.test | 16 ++++++++++++++++ sql/item.cc | 3 +++ sql/item_func.cc | 15 ++++++++++++++- 4 files changed, 52 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 566dac07fd5..cdba113ae40 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -622,3 +622,22 @@ execute stmt using @user_id, @id; partner_id deallocate prepare stmt; drop table t1, t2, t3, t4; +prepare stmt from 'select ?=?'; +set @a='CHRISTINE '; +set @b='CHRISTINE'; +execute stmt using @a, @b; +?=? +1 +execute stmt using @a, @b; +?=? +1 +set @a=1, @b=2; +execute stmt using @a, @b; +?=? +0 +set @a='CHRISTINE '; +set @b='CHRISTINE'; +execute stmt using @a, @b; +?=? +1 +deallocate prepare stmt; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index a25d4447c20..0fa14024d11 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -650,3 +650,19 @@ execute stmt using @user_id, @id; execute stmt using @user_id, @id; deallocate prepare stmt; drop table t1, t2, t3, t4; + +# +# Bug#9379: make sure that Item::collation is reset when one sets +# a parameter marker from a string variable. +# +prepare stmt from 'select ?=?'; +set @a='CHRISTINE '; +set @b='CHRISTINE'; +execute stmt using @a, @b; +execute stmt using @a, @b; +set @a=1, @b=2; +execute stmt using @a, @b; +set @a='CHRISTINE '; +set @b='CHRISTINE'; +execute stmt using @a, @b; +deallocate prepare stmt; diff --git a/sql/item.cc b/sql/item.cc index 19b88c115b9..ed39fe177cd 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1089,6 +1089,7 @@ void Item_param::reset() to the binary log. */ str_value.set_charset(&my_charset_bin); + collation.set(&my_charset_bin, DERIVATION_COERCIBLE); state= NO_VALUE; maybe_null= 1; null_value= 0; @@ -1336,6 +1337,8 @@ bool Item_param::convert_str_value(THD *thd) */ str_value_ptr.set(str_value.ptr(), str_value.length(), str_value.charset()); + /* Synchronize item charset with value charset */ + collation.set(str_value.charset(), DERIVATION_COERCIBLE); } return rc; } diff --git a/sql/item_func.cc b/sql/item_func.cc index 442ef15bba8..4e0b6d8813f 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -188,7 +188,20 @@ bool Item_func::agg_arg_charsets(DTCollation &coll, break; // we cannot return here, we need to restore "arena". } conv->fix_fields(thd, 0, &conv); - *arg= conv; + /* + If in statement prepare, then we create a converter for two + constant items, do it once and then reuse it. + If we're in execution of a prepared statement, arena is NULL, + and the conv was created in runtime memory. This can be + the case only if the argument is a parameter marker ('?'), + because for all true constants the charset converter has already + been created in prepare. In this case register the change for + rollback. + */ + if (arena) + *arg= conv; + else + thd->change_item_tree(arg, conv); } if (arena) thd->restore_backup_item_arena(arena, &backup); From ef1e748ef1d8ac2735222dae9e89d2a7edb99fc6 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Thu, 14 Jul 2005 00:15:23 +0400 Subject: [PATCH 16/42] A test case for Bug#9442 "Set parameter make query fail if column character set is UCS2". The bug is no longer repeatable. --- mysql-test/r/ps.result | 19 +++++++++++++++++++ mysql-test/t/ps.test | 13 +++++++++++++ 2 files changed, 32 insertions(+) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index cdba113ae40..ee558e0ea89 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -641,3 +641,22 @@ execute stmt using @a, @b; ?=? 1 deallocate prepare stmt; +create table t1 (utext varchar(20) character set ucs2); +insert into t1 values ("lily"); +insert into t1 values ("river"); +prepare stmt from 'select utext from t1 where utext like ?'; +set @param1='%%'; +execute stmt using @param1; +utext +lily +river +execute stmt using @param1; +utext +lily +river +select utext from t1 where utext like '%%'; +utext +lily +river +drop table t1; +deallocate prepare stmt; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 0fa14024d11..01d62a2e198 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -666,3 +666,16 @@ set @a='CHRISTINE '; set @b='CHRISTINE'; execute stmt using @a, @b; deallocate prepare stmt; +# +# Bug#9442 Set parameter make query fail if column character set is UCS2 +# +create table t1 (utext varchar(20) character set ucs2); +insert into t1 values ("lily"); +insert into t1 values ("river"); +prepare stmt from 'select utext from t1 where utext like ?'; +set @param1='%%'; +execute stmt using @param1; +execute stmt using @param1; +select utext from t1 where utext like '%%'; +drop table t1; +deallocate prepare stmt; From 03a6d0c73176b8be8eab6c70f9821e77b4440241 Mon Sep 17 00:00:00 2001 From: "reggie@linux.site" <> Date: Thu, 14 Jul 2005 03:49:54 -0600 Subject: [PATCH 17/42] fixed function sig so it will compile with Visual C++ 8 --- regex/regerror.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/regex/regerror.c b/regex/regerror.c index 0a7b7c8da2c..9caa5b95a4c 100644 --- a/regex/regerror.c +++ b/regex/regerror.c @@ -56,11 +56,7 @@ static struct rerr { */ /* ARGSUSED */ size_t -regerror(errcode, preg, errbuf, errbuf_size) -int errcode; -const regex_t *preg; -char *errbuf; -size_t errbuf_size; +regerror(int errcode, const regex_t *preg, char *errbuf, size_t errbuf_size) { register struct rerr *r; register size_t len; From 62b8e6fdd153c62a1143a65be5b3c84d37bef890 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Thu, 14 Jul 2005 15:13:23 +0400 Subject: [PATCH 18/42] A fix and a test case for Bug#9735. No separate typecode for MEDIUMTEXT/LONGTEXT is added, as we have no sound decision yet what typecodes and for what types are sent by the server (aka what constitutes a distinct type in MySQL). --- mysql-test/r/ps_2myisam.result | 20 ++++++++--------- mysql-test/r/ps_3innodb.result | 20 ++++++++--------- mysql-test/r/ps_4heap.result | 16 +++++++------- mysql-test/r/ps_5merge.result | 40 +++++++++++++++++----------------- mysql-test/r/ps_6bdb.result | 20 ++++++++--------- mysql-test/r/ps_7ndb.result | 20 ++++++++--------- sql/field.cc | 4 +++- tests/mysql_client_test.c | 31 +++++++++++++++++++++++++- 8 files changed, 101 insertions(+), 70 deletions(-) diff --git a/mysql-test/r/ps_2myisam.result b/mysql-test/r/ps_2myisam.result index c569c9842f7..4b655cfb854 100644 --- a/mysql-test/r/ps_2myisam.result +++ b/mysql-test/r/ps_2myisam.result @@ -77,8 +77,8 @@ def test t9 t9 c25 c25 252 65535 4 Y 144 0 63 def test t9 t9 c26 c26 252 65535 4 Y 16 0 8 def test t9 t9 c27 c27 252 16777215 10 Y 144 0 63 def test t9 t9 c28 c28 252 16777215 10 Y 16 0 8 -def test t9 t9 c29 c29 252 16777215 8 Y 144 0 63 -def test t9 t9 c30 c30 252 16777215 8 Y 16 0 8 +def test t9 t9 c29 c29 252 4294967295 8 Y 144 0 63 +def test t9 t9 c30 c30 252 4294967295 8 Y 16 0 8 def test t9 t9 c31 c31 254 5 3 Y 256 0 8 def test t9 t9 c32 c32 254 24 7 Y 2048 0 8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 @@ -1812,17 +1812,17 @@ def test t5 t5 param02 param02 5 20 1 Y 32768 31 63 def test t5 t5 const03 const03 5 23 1 N 32769 31 63 def test t5 t5 param03 param03 5 20 1 Y 32768 31 63 def test t5 t5 const04 const04 254 3 3 N 1 0 8 -def test t5 t5 param04 param04 252 16777215 3 Y 16 0 8 +def test t5 t5 param04 param04 252 4294967295 3 Y 16 0 8 def test t5 t5 const05 const05 254 3 3 N 129 0 63 -def test t5 t5 param05 param05 252 16777215 3 Y 144 0 63 +def test t5 t5 param05 param05 252 4294967295 3 Y 144 0 63 def test t5 t5 const06 const06 253 10 10 N 1 0 8 -def test t5 t5 param06 param06 252 16777215 10 Y 16 0 8 +def test t5 t5 param06 param06 252 4294967295 10 Y 16 0 8 def test t5 t5 const07 const07 10 10 10 Y 128 0 63 -def test t5 t5 param07 param07 252 16777215 10 Y 144 0 63 +def test t5 t5 param07 param07 252 4294967295 10 Y 144 0 63 def test t5 t5 const08 const08 253 19 19 N 1 0 8 -def test t5 t5 param08 param08 252 16777215 19 Y 16 0 8 +def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 -def test t5 t5 param09 param09 252 16777215 19 Y 144 0 63 +def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 @@ -1830,8 +1830,8 @@ def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 -def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 -def test t5 t5 param15 param15 252 16777215 0 Y 144 0 63 +def test t5 t5 param14 param14 252 4294967295 0 Y 16 0 8 +def test t5 t5 param15 param15 252 4294967295 0 Y 144 0 63 const01 8 param01 8 const02 8.0 diff --git a/mysql-test/r/ps_3innodb.result b/mysql-test/r/ps_3innodb.result index 930aea2e381..4d2a62887d6 100644 --- a/mysql-test/r/ps_3innodb.result +++ b/mysql-test/r/ps_3innodb.result @@ -77,8 +77,8 @@ def test t9 t9 c25 c25 252 65535 4 Y 144 0 63 def test t9 t9 c26 c26 252 65535 4 Y 16 0 8 def test t9 t9 c27 c27 252 16777215 10 Y 144 0 63 def test t9 t9 c28 c28 252 16777215 10 Y 16 0 8 -def test t9 t9 c29 c29 252 16777215 8 Y 144 0 63 -def test t9 t9 c30 c30 252 16777215 8 Y 16 0 8 +def test t9 t9 c29 c29 252 4294967295 8 Y 144 0 63 +def test t9 t9 c30 c30 252 4294967295 8 Y 16 0 8 def test t9 t9 c31 c31 254 5 3 Y 256 0 8 def test t9 t9 c32 c32 254 24 7 Y 2048 0 8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 @@ -1795,17 +1795,17 @@ def test t5 t5 param02 param02 5 20 1 Y 32768 31 63 def test t5 t5 const03 const03 5 23 1 N 32769 31 63 def test t5 t5 param03 param03 5 20 1 Y 32768 31 63 def test t5 t5 const04 const04 254 3 3 N 1 0 8 -def test t5 t5 param04 param04 252 16777215 3 Y 16 0 8 +def test t5 t5 param04 param04 252 4294967295 3 Y 16 0 8 def test t5 t5 const05 const05 254 3 3 N 129 0 63 -def test t5 t5 param05 param05 252 16777215 3 Y 144 0 63 +def test t5 t5 param05 param05 252 4294967295 3 Y 144 0 63 def test t5 t5 const06 const06 253 10 10 N 1 0 8 -def test t5 t5 param06 param06 252 16777215 10 Y 16 0 8 +def test t5 t5 param06 param06 252 4294967295 10 Y 16 0 8 def test t5 t5 const07 const07 10 10 10 Y 128 0 63 -def test t5 t5 param07 param07 252 16777215 10 Y 144 0 63 +def test t5 t5 param07 param07 252 4294967295 10 Y 144 0 63 def test t5 t5 const08 const08 253 19 19 N 1 0 8 -def test t5 t5 param08 param08 252 16777215 19 Y 16 0 8 +def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 -def test t5 t5 param09 param09 252 16777215 19 Y 144 0 63 +def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 @@ -1813,8 +1813,8 @@ def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 -def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 -def test t5 t5 param15 param15 252 16777215 0 Y 144 0 63 +def test t5 t5 param14 param14 252 4294967295 0 Y 16 0 8 +def test t5 t5 param15 param15 252 4294967295 0 Y 144 0 63 const01 8 param01 8 const02 8.0 diff --git a/mysql-test/r/ps_4heap.result b/mysql-test/r/ps_4heap.result index 083a4b221fe..a4919b664c4 100644 --- a/mysql-test/r/ps_4heap.result +++ b/mysql-test/r/ps_4heap.result @@ -1796,17 +1796,17 @@ def test t5 t5 param02 param02 5 20 1 Y 32768 31 63 def test t5 t5 const03 const03 5 23 1 N 32769 31 63 def test t5 t5 param03 param03 5 20 1 Y 32768 31 63 def test t5 t5 const04 const04 254 3 3 N 1 0 8 -def test t5 t5 param04 param04 252 16777215 3 Y 16 0 8 +def test t5 t5 param04 param04 252 4294967295 3 Y 16 0 8 def test t5 t5 const05 const05 254 3 3 N 129 0 63 -def test t5 t5 param05 param05 252 16777215 3 Y 144 0 63 +def test t5 t5 param05 param05 252 4294967295 3 Y 144 0 63 def test t5 t5 const06 const06 253 10 10 N 1 0 8 -def test t5 t5 param06 param06 252 16777215 10 Y 16 0 8 +def test t5 t5 param06 param06 252 4294967295 10 Y 16 0 8 def test t5 t5 const07 const07 10 10 10 Y 128 0 63 -def test t5 t5 param07 param07 252 16777215 10 Y 144 0 63 +def test t5 t5 param07 param07 252 4294967295 10 Y 144 0 63 def test t5 t5 const08 const08 253 19 19 N 1 0 8 -def test t5 t5 param08 param08 252 16777215 19 Y 16 0 8 +def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 -def test t5 t5 param09 param09 252 16777215 19 Y 144 0 63 +def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 @@ -1814,8 +1814,8 @@ def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 -def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 -def test t5 t5 param15 param15 252 16777215 0 Y 144 0 63 +def test t5 t5 param14 param14 252 4294967295 0 Y 16 0 8 +def test t5 t5 param15 param15 252 4294967295 0 Y 144 0 63 const01 8 param01 8 const02 8.0 diff --git a/mysql-test/r/ps_5merge.result b/mysql-test/r/ps_5merge.result index 1edd617ffc6..f98cc1b3cdf 100644 --- a/mysql-test/r/ps_5merge.result +++ b/mysql-test/r/ps_5merge.result @@ -120,8 +120,8 @@ def test t9 t9 c25 c25 252 65535 4 Y 144 0 63 def test t9 t9 c26 c26 252 65535 4 Y 16 0 8 def test t9 t9 c27 c27 252 16777215 10 Y 144 0 63 def test t9 t9 c28 c28 252 16777215 10 Y 16 0 8 -def test t9 t9 c29 c29 252 16777215 8 Y 144 0 63 -def test t9 t9 c30 c30 252 16777215 8 Y 16 0 8 +def test t9 t9 c29 c29 252 4294967295 8 Y 144 0 63 +def test t9 t9 c30 c30 252 4294967295 8 Y 16 0 8 def test t9 t9 c31 c31 254 5 3 Y 256 0 8 def test t9 t9 c32 c32 254 24 7 Y 2048 0 8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 @@ -1732,17 +1732,17 @@ def test t5 t5 param02 param02 5 20 1 Y 32768 31 63 def test t5 t5 const03 const03 5 23 1 N 32769 31 63 def test t5 t5 param03 param03 5 20 1 Y 32768 31 63 def test t5 t5 const04 const04 254 3 3 N 1 0 8 -def test t5 t5 param04 param04 252 16777215 3 Y 16 0 8 +def test t5 t5 param04 param04 252 4294967295 3 Y 16 0 8 def test t5 t5 const05 const05 254 3 3 N 129 0 63 -def test t5 t5 param05 param05 252 16777215 3 Y 144 0 63 +def test t5 t5 param05 param05 252 4294967295 3 Y 144 0 63 def test t5 t5 const06 const06 253 10 10 N 1 0 8 -def test t5 t5 param06 param06 252 16777215 10 Y 16 0 8 +def test t5 t5 param06 param06 252 4294967295 10 Y 16 0 8 def test t5 t5 const07 const07 10 10 10 Y 128 0 63 -def test t5 t5 param07 param07 252 16777215 10 Y 144 0 63 +def test t5 t5 param07 param07 252 4294967295 10 Y 144 0 63 def test t5 t5 const08 const08 253 19 19 N 1 0 8 -def test t5 t5 param08 param08 252 16777215 19 Y 16 0 8 +def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 -def test t5 t5 param09 param09 252 16777215 19 Y 144 0 63 +def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 @@ -1750,8 +1750,8 @@ def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 -def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 -def test t5 t5 param15 param15 252 16777215 0 Y 144 0 63 +def test t5 t5 param14 param14 252 4294967295 0 Y 16 0 8 +def test t5 t5 param15 param15 252 4294967295 0 Y 144 0 63 const01 8 param01 8 const02 8.0 @@ -3134,8 +3134,8 @@ def test t9 t9 c25 c25 252 65535 4 Y 144 0 63 def test t9 t9 c26 c26 252 65535 4 Y 16 0 8 def test t9 t9 c27 c27 252 16777215 10 Y 144 0 63 def test t9 t9 c28 c28 252 16777215 10 Y 16 0 8 -def test t9 t9 c29 c29 252 16777215 8 Y 144 0 63 -def test t9 t9 c30 c30 252 16777215 8 Y 16 0 8 +def test t9 t9 c29 c29 252 4294967295 8 Y 144 0 63 +def test t9 t9 c30 c30 252 4294967295 8 Y 16 0 8 def test t9 t9 c31 c31 254 5 3 Y 256 0 8 def test t9 t9 c32 c32 254 24 7 Y 2048 0 8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 @@ -4746,17 +4746,17 @@ def test t5 t5 param02 param02 5 20 1 Y 32768 31 63 def test t5 t5 const03 const03 5 23 1 N 32769 31 63 def test t5 t5 param03 param03 5 20 1 Y 32768 31 63 def test t5 t5 const04 const04 254 3 3 N 1 0 8 -def test t5 t5 param04 param04 252 16777215 3 Y 16 0 8 +def test t5 t5 param04 param04 252 4294967295 3 Y 16 0 8 def test t5 t5 const05 const05 254 3 3 N 129 0 63 -def test t5 t5 param05 param05 252 16777215 3 Y 144 0 63 +def test t5 t5 param05 param05 252 4294967295 3 Y 144 0 63 def test t5 t5 const06 const06 253 10 10 N 1 0 8 -def test t5 t5 param06 param06 252 16777215 10 Y 16 0 8 +def test t5 t5 param06 param06 252 4294967295 10 Y 16 0 8 def test t5 t5 const07 const07 10 10 10 Y 128 0 63 -def test t5 t5 param07 param07 252 16777215 10 Y 144 0 63 +def test t5 t5 param07 param07 252 4294967295 10 Y 144 0 63 def test t5 t5 const08 const08 253 19 19 N 1 0 8 -def test t5 t5 param08 param08 252 16777215 19 Y 16 0 8 +def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 -def test t5 t5 param09 param09 252 16777215 19 Y 144 0 63 +def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 @@ -4764,8 +4764,8 @@ def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 -def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 -def test t5 t5 param15 param15 252 16777215 0 Y 144 0 63 +def test t5 t5 param14 param14 252 4294967295 0 Y 16 0 8 +def test t5 t5 param15 param15 252 4294967295 0 Y 144 0 63 const01 8 param01 8 const02 8.0 diff --git a/mysql-test/r/ps_6bdb.result b/mysql-test/r/ps_6bdb.result index 06be8750cc4..acd7f45de95 100644 --- a/mysql-test/r/ps_6bdb.result +++ b/mysql-test/r/ps_6bdb.result @@ -77,8 +77,8 @@ def test t9 t9 c25 c25 252 65535 4 Y 144 0 63 def test t9 t9 c26 c26 252 65535 4 Y 16 0 8 def test t9 t9 c27 c27 252 16777215 10 Y 144 0 63 def test t9 t9 c28 c28 252 16777215 10 Y 16 0 8 -def test t9 t9 c29 c29 252 16777215 8 Y 144 0 63 -def test t9 t9 c30 c30 252 16777215 8 Y 16 0 8 +def test t9 t9 c29 c29 252 4294967295 8 Y 144 0 63 +def test t9 t9 c30 c30 252 4294967295 8 Y 16 0 8 def test t9 t9 c31 c31 254 5 3 Y 256 0 8 def test t9 t9 c32 c32 254 24 7 Y 2048 0 8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 @@ -1795,17 +1795,17 @@ def test t5 t5 param02 param02 5 20 1 Y 32768 31 63 def test t5 t5 const03 const03 5 23 1 N 32769 31 63 def test t5 t5 param03 param03 5 20 1 Y 32768 31 63 def test t5 t5 const04 const04 254 3 3 N 1 0 8 -def test t5 t5 param04 param04 252 16777215 3 Y 16 0 8 +def test t5 t5 param04 param04 252 4294967295 3 Y 16 0 8 def test t5 t5 const05 const05 254 3 3 N 129 0 63 -def test t5 t5 param05 param05 252 16777215 3 Y 144 0 63 +def test t5 t5 param05 param05 252 4294967295 3 Y 144 0 63 def test t5 t5 const06 const06 253 10 10 N 1 0 8 -def test t5 t5 param06 param06 252 16777215 10 Y 16 0 8 +def test t5 t5 param06 param06 252 4294967295 10 Y 16 0 8 def test t5 t5 const07 const07 10 10 10 Y 128 0 63 -def test t5 t5 param07 param07 252 16777215 10 Y 144 0 63 +def test t5 t5 param07 param07 252 4294967295 10 Y 144 0 63 def test t5 t5 const08 const08 253 19 19 N 1 0 8 -def test t5 t5 param08 param08 252 16777215 19 Y 16 0 8 +def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 -def test t5 t5 param09 param09 252 16777215 19 Y 144 0 63 +def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 @@ -1813,8 +1813,8 @@ def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 -def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 -def test t5 t5 param15 param15 252 16777215 0 Y 144 0 63 +def test t5 t5 param14 param14 252 4294967295 0 Y 16 0 8 +def test t5 t5 param15 param15 252 4294967295 0 Y 144 0 63 const01 8 param01 8 const02 8.0 diff --git a/mysql-test/r/ps_7ndb.result b/mysql-test/r/ps_7ndb.result index f5750d947b5..27a1ea0925d 100644 --- a/mysql-test/r/ps_7ndb.result +++ b/mysql-test/r/ps_7ndb.result @@ -77,8 +77,8 @@ def test t9 t9 c25 c25 252 65535 4 Y 144 0 63 def test t9 t9 c26 c26 252 65535 4 Y 16 0 8 def test t9 t9 c27 c27 252 16777215 10 Y 144 0 63 def test t9 t9 c28 c28 252 16777215 10 Y 16 0 8 -def test t9 t9 c29 c29 252 16777215 8 Y 144 0 63 -def test t9 t9 c30 c30 252 16777215 8 Y 16 0 8 +def test t9 t9 c29 c29 252 4294967295 8 Y 144 0 63 +def test t9 t9 c30 c30 252 4294967295 8 Y 16 0 8 def test t9 t9 c31 c31 254 5 3 Y 256 0 8 def test t9 t9 c32 c32 254 24 7 Y 2048 0 8 c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 c22 c23 c24 c25 c26 c27 c28 c29 c30 c31 c32 @@ -1795,17 +1795,17 @@ def test t5 t5 param02 param02 5 20 1 Y 32768 31 63 def test t5 t5 const03 const03 5 23 1 N 32769 31 63 def test t5 t5 param03 param03 5 20 1 Y 32768 31 63 def test t5 t5 const04 const04 254 3 3 N 1 0 8 -def test t5 t5 param04 param04 252 16777215 3 Y 16 0 8 +def test t5 t5 param04 param04 252 4294967295 3 Y 16 0 8 def test t5 t5 const05 const05 254 3 3 N 129 0 63 -def test t5 t5 param05 param05 252 16777215 3 Y 144 0 63 +def test t5 t5 param05 param05 252 4294967295 3 Y 144 0 63 def test t5 t5 const06 const06 253 10 10 N 1 0 8 -def test t5 t5 param06 param06 252 16777215 10 Y 16 0 8 +def test t5 t5 param06 param06 252 4294967295 10 Y 16 0 8 def test t5 t5 const07 const07 10 10 10 Y 128 0 63 -def test t5 t5 param07 param07 252 16777215 10 Y 144 0 63 +def test t5 t5 param07 param07 252 4294967295 10 Y 144 0 63 def test t5 t5 const08 const08 253 19 19 N 1 0 8 -def test t5 t5 param08 param08 252 16777215 19 Y 16 0 8 +def test t5 t5 param08 param08 252 4294967295 19 Y 16 0 8 def test t5 t5 const09 const09 12 19 19 Y 128 0 63 -def test t5 t5 param09 param09 252 16777215 19 Y 144 0 63 +def test t5 t5 param09 param09 252 4294967295 19 Y 144 0 63 def test t5 t5 const10 const10 3 10 9 N 32769 0 63 def test t5 t5 param10 param10 8 20 9 Y 32768 0 63 def test t5 t5 const11 const11 3 4 4 Y 32768 0 63 @@ -1813,8 +1813,8 @@ def test t5 t5 param11 param11 8 20 4 Y 32768 0 63 def test t5 t5 const12 const12 254 0 0 Y 128 0 63 def test t5 t5 param12 param12 8 20 0 Y 32768 0 63 def test t5 t5 param13 param13 5 20 0 Y 32768 31 63 -def test t5 t5 param14 param14 252 16777215 0 Y 16 0 8 -def test t5 t5 param15 param15 252 16777215 0 Y 144 0 63 +def test t5 t5 param14 param14 252 4294967295 0 Y 16 0 8 +def test t5 t5 param15 param15 252 4294967295 0 Y 144 0 63 const01 8 param01 8 const02 8.0 diff --git a/sql/field.cc b/sql/field.cc index 64d5babd159..39a99830b14 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -47,6 +47,8 @@ uchar Field_null::null[1]={1}; const char field_separator=','; #define DOUBLE_TO_STRING_CONVERSION_BUFFER_SIZE 320 +#define BLOB_PACK_LENGTH_TO_MAX_LENGH(arg) \ +((ulong) ((LL(1) << min(arg, 4) * 8) - LL(1))) /* Rules for merging different types of fields in UNION @@ -5445,7 +5447,7 @@ Field_blob::Field_blob(char *ptr_arg, uchar *null_ptr_arg, uchar null_bit_arg, enum utype unireg_check_arg, const char *field_name_arg, struct st_table *table_arg,uint blob_pack_length, CHARSET_INFO *cs) - :Field_str(ptr_arg, (1L << min(blob_pack_length,3)*8)-1L, + :Field_str(ptr_arg, BLOB_PACK_LENGTH_TO_MAX_LENGH(blob_pack_length), null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, table_arg, cs), packlength(blob_pack_length) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index dbee6e77e4f..f874276a656 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -672,7 +672,7 @@ static void verify_prepare_field(MYSQL_RES *result, fprintf(stdout, "\n org_table:`%s`\t(expected: `%s`)", field->org_table, org_table); fprintf(stdout, "\n database :`%s`\t(expected: `%s`)", field->db, db); - fprintf(stdout, "\n length :`%ld`\t(expected: `%ld`)", + fprintf(stdout, "\n length :`%lu`\t(expected: `%lu`)", field->length, length * cs->mbmaxlen); fprintf(stdout, "\n maxlength:`%ld`", field->max_length); fprintf(stdout, "\n charsetnr:`%d`", field->charsetnr); @@ -11670,6 +11670,34 @@ static void test_bug8378() #endif } + +/* Test correct max length for MEDIUMTEXT and LONGTEXT columns */ + +static void test_bug9735() +{ + MYSQL_RES *res; + int rc; + + myheader("test_bug9735"); + + rc= mysql_query(mysql, "drop table if exists t1"); + myquery(rc); + rc= mysql_query(mysql, "create table t1 (a mediumtext, b longtext) " + "character set latin1"); + myquery(rc); + rc= mysql_query(mysql, "select * from t1"); + myquery(rc); + res= mysql_store_result(mysql); + verify_prepare_field(res, 0, "a", "a", MYSQL_TYPE_BLOB, + "t1", "t1", current_db, (1U << 24)-1, 0); + verify_prepare_field(res, 1, "b", "b", MYSQL_TYPE_BLOB, + "t1", "t1", current_db, ~0U, 0); + mysql_free_result(res); + rc= mysql_query(mysql, "drop table t1"); + myquery(rc); +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -11884,6 +11912,7 @@ static struct my_tests_st my_tests[]= { { "test_bug8330", test_bug8330 }, { "test_bug7990", test_bug7990 }, { "test_bug8378", test_bug8378 }, + { "test_bug9735", test_bug9735 }, { 0, 0 } }; From adfa1a259603f45da13fca4963b3bd90837b8bcf Mon Sep 17 00:00:00 2001 From: "reggie@linux.site" <> Date: Thu, 14 Jul 2005 06:04:29 -0600 Subject: [PATCH 19/42] Bug #7403 error "Forcing close of thread 1 user: 'xxx'" The problem was that on Windows, the socket was in a blocking state trying to read. Setting killed=1 is not enough to break the socket out of it's read loop. You have to cancel the read request or close the socket (which close_connection does). --- sql/mysqld.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index a757c47366d..1434775cff3 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -657,7 +657,7 @@ static void close_connections(void) { DBUG_PRINT("quit",("Informing thread %ld that it's time to die", tmp->thread_id)); - tmp->killed=1; + close_connection(tmp, 0, 1); if (tmp->mysys_var) { tmp->mysys_var->abort=1; From e1273aec6dfcb163542e449a31bf2f8aa3e0fa63 Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Thu, 14 Jul 2005 15:13:36 +0000 Subject: [PATCH 20/42] Fix for BUG#11700: in add_not_null_conds(), call full fix_fields() for the created NOT NULL. This is needed because in some cases range optimization is performed twice and added NOT NULL item must have correct const_table_map() value. --- mysql-test/r/select.result | 35 ++++++++++++++++++++++++++++++++ mysql-test/t/select.test | 41 ++++++++++++++++++++++++++++++++++++++ sql/sql_select.cc | 12 ++++++++--- 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index abf5c8c87ad..8160c5a2f3d 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2524,3 +2524,38 @@ select * from t3 left join t1 on t3.id = t1.uid, t2 where t2.ident in (0, t1.gid id name gid uid ident level 1 fs NULL NULL 0 READ drop table t1,t2,t3; +CREATE TABLE t1 ( +acct_id int(11) NOT NULL default '0', +profile_id smallint(6) default NULL, +UNIQUE KEY t1$acct_id (acct_id), +KEY t1$profile_id (profile_id) +); +INSERT INTO t1 VALUES (132,17),(133,18); +CREATE TABLE t2 ( +profile_id smallint(6) default NULL, +queue_id int(11) default NULL, +seq int(11) default NULL, +KEY t2$queue_id (queue_id) +); +INSERT INTO t2 VALUES (17,31,4),(17,30,3),(17,36,2),(17,37,1); +CREATE TABLE t3 ( +id int(11) NOT NULL default '0', +qtype int(11) default NULL, +seq int(11) default NULL, +warn_lvl int(11) default NULL, +crit_lvl int(11) default NULL, +rr1 tinyint(4) NOT NULL default '0', +rr2 int(11) default NULL, +default_queue tinyint(4) NOT NULL default '0', +KEY t3$qtype (qtype), +KEY t3$id (id) +); +INSERT INTO t3 VALUES (30,1,29,NULL,NULL,0,NULL,0),(31,1,28,NULL,NULL,0,NULL,0), +(36,1,34,NULL,NULL,0,NULL,0),(37,1,35,NULL,NULL,0,121,0); +SELECT COUNT(*) FROM t1 a STRAIGHT_JOIN t2 pq STRAIGHT_JOIN t3 q +WHERE +(pq.profile_id = a.profile_id) AND (a.acct_id = 132) AND +(pq.queue_id = q.id) AND (q.rr1 <> 1); +COUNT(*) +4 +drop table t1,t2,t3; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index baaab6e4189..37e4324152b 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2075,3 +2075,44 @@ INSERT INTO `t3` VALUES (1,'fs'); select * from t3 left join t1 on t3.id = t1.uid, t2 where t2.ident in (0, t1.gid, t3.id, 0); drop table t1,t2,t3; + +# Test for BUG#11700 +CREATE TABLE t1 ( + acct_id int(11) NOT NULL default '0', + profile_id smallint(6) default NULL, + UNIQUE KEY t1$acct_id (acct_id), + KEY t1$profile_id (profile_id) +); +INSERT INTO t1 VALUES (132,17),(133,18); + +CREATE TABLE t2 ( + profile_id smallint(6) default NULL, + queue_id int(11) default NULL, + seq int(11) default NULL, + KEY t2$queue_id (queue_id) +); +INSERT INTO t2 VALUES (17,31,4),(17,30,3),(17,36,2),(17,37,1); + +CREATE TABLE t3 ( + id int(11) NOT NULL default '0', + qtype int(11) default NULL, + seq int(11) default NULL, + warn_lvl int(11) default NULL, + crit_lvl int(11) default NULL, + rr1 tinyint(4) NOT NULL default '0', + rr2 int(11) default NULL, + default_queue tinyint(4) NOT NULL default '0', + KEY t3$qtype (qtype), + KEY t3$id (id) +); + +INSERT INTO t3 VALUES (30,1,29,NULL,NULL,0,NULL,0),(31,1,28,NULL,NULL,0,NULL,0), + (36,1,34,NULL,NULL,0,NULL,0),(37,1,35,NULL,NULL,0,121,0); + +SELECT COUNT(*) FROM t1 a STRAIGHT_JOIN t2 pq STRAIGHT_JOIN t3 q +WHERE + (pq.profile_id = a.profile_id) AND (a.acct_id = 132) AND + (pq.queue_id = q.id) AND (q.rr1 <> 1); + +drop table t1,t2,t3; + diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 972fb4e0368..75fc189b21f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3539,11 +3539,17 @@ static void add_not_null_conds(JOIN *join) DBUG_ASSERT(item->type() == Item::FIELD_ITEM); Item_field *not_null_item= (Item_field*)item; JOIN_TAB *referred_tab= not_null_item->field->table->reginfo.join_tab; - Item_func_isnotnull *notnull; + Item *notnull; if (!(notnull= new Item_func_isnotnull(not_null_item))) DBUG_VOID_RETURN; - - notnull->quick_fix_field(); + /* + We need to do full fix_fields() call here in order to have correct + notnull->const_item(). This is needed e.g. by test_quick_select + when it is called from make_join_select after this function is + called. + */ + if (notnull->fix_fields(join->thd, join->tables_list, ¬null)) + DBUG_VOID_RETURN; DBUG_EXECUTE("where",print_where(notnull, referred_tab->table->table_name);); add_cond_and_fix(&referred_tab->select_cond, notnull); From 0b3db181bf58e7d7b083eb6c790859d1975aece2 Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Thu, 14 Jul 2005 15:19:26 +0000 Subject: [PATCH 21/42] Fix for BUG#11869: In Item_func_match::fix_index() handle the case when there is no source table present (this happens for ORDER BY after UNION) --- mysql-test/r/fulltext_order_by.result | 74 ++++++++++++++++++++++++ mysql-test/t/fulltext_order_by.test | 81 +++++++++++++++++++++++++++ sql/item_func.cc | 3 + 3 files changed, 158 insertions(+) diff --git a/mysql-test/r/fulltext_order_by.result b/mysql-test/r/fulltext_order_by.result index dc51454f1d5..130d096e00f 100644 --- a/mysql-test/r/fulltext_order_by.result +++ b/mysql-test/r/fulltext_order_by.result @@ -86,3 +86,77 @@ a rel 1 1 2 2 drop table t1; +CREATE TABLE t1 ( +id int(11) NOT NULL auto_increment, +thread int(11) NOT NULL default '0', +beitrag longtext NOT NULL, +PRIMARY KEY (id), +KEY thread (thread), +FULLTEXT KEY beitrag (beitrag) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7923 ; +CREATE TABLE t2 ( +id int(11) NOT NULL auto_increment, +text varchar(100) NOT NULL default '', +PRIMARY KEY (id), +KEY text (text) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ; +CREATE TABLE t3 ( +id int(11) NOT NULL auto_increment, +forum int(11) NOT NULL default '0', +betreff varchar(70) NOT NULL default '', +PRIMARY KEY (id), +KEY forum (forum), +FULLTEXT KEY betreff (betreff) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=996 ; +select a.text, b.id, b.betreff +from +t2 a inner join t3 b on a.id = b.forum inner join +t1 c on b.id = c.thread +where +match(b.betreff) against ('+abc' in boolean mode) +group by a.text, b.id, b.betreff +union +select a.text, b.id, b.betreff +from +t2 a inner join t3 b on a.id = b.forum inner join +t1 c on b.id = c.thread +where +match(c.beitrag) against ('+abc' in boolean mode) +group by +a.text, b.id, b.betreff +order by +match(b.betreff) against ('+abc' in boolean mode) desc; +ERROR 42S02: Unknown table 'b' in order clause +select a.text, b.id, b.betreff +from +t2 a inner join t3 b on a.id = b.forum inner join +t1 c on b.id = c.thread +where +match(b.betreff) against ('+abc' in boolean mode) +union +select a.text, b.id, b.betreff +from +t2 a inner join t3 b on a.id = b.forum inner join +t1 c on b.id = c.thread +where +match(c.beitrag) against ('+abc' in boolean mode) +order by +match(b.betreff) against ('+abc' in boolean mode) desc; +ERROR 42S02: Unknown table 'b' in order clause +select a.text, b.id, b.betreff +from +t2 a inner join t3 b on a.id = b.forum inner join +t1 c on b.id = c.thread +where +match(b.betreff) against ('+abc' in boolean mode) +union +select a.text, b.id, b.betreff +from +t2 a inner join t3 b on a.id = b.forum inner join +t1 c on b.id = c.thread +where +match(c.beitrag) against ('+abc' in boolean mode) +order by +match(betreff) against ('+abc' in boolean mode) desc; +text id betreff +drop table t1,t2,t3; diff --git a/mysql-test/t/fulltext_order_by.test b/mysql-test/t/fulltext_order_by.test index 5c1b4127d8c..6894f63fa77 100644 --- a/mysql-test/t/fulltext_order_by.test +++ b/mysql-test/t/fulltext_order_by.test @@ -54,3 +54,84 @@ SELECT a, MATCH (message) AGAINST ('t* f*' IN BOOLEAN MODE) as rel FROM t1; SELECT a, MATCH (message) AGAINST ('t* f*' IN BOOLEAN MODE) as rel FROM t1 ORDER BY rel,a; drop table t1; +# BUG#11869 +CREATE TABLE t1 ( + id int(11) NOT NULL auto_increment, + thread int(11) NOT NULL default '0', + beitrag longtext NOT NULL, + PRIMARY KEY (id), + KEY thread (thread), + FULLTEXT KEY beitrag (beitrag) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=7923 ; + +CREATE TABLE t2 ( + id int(11) NOT NULL auto_increment, + text varchar(100) NOT NULL default '', + PRIMARY KEY (id), + KEY text (text) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=63 ; + +CREATE TABLE t3 ( + id int(11) NOT NULL auto_increment, + forum int(11) NOT NULL default '0', + betreff varchar(70) NOT NULL default '', + PRIMARY KEY (id), + KEY forum (forum), + FULLTEXT KEY betreff (betreff) +) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=996 ; + +--error 1109 +select a.text, b.id, b.betreff +from + t2 a inner join t3 b on a.id = b.forum inner join + t1 c on b.id = c.thread +where + match(b.betreff) against ('+abc' in boolean mode) +group by a.text, b.id, b.betreff +union +select a.text, b.id, b.betreff +from + t2 a inner join t3 b on a.id = b.forum inner join + t1 c on b.id = c.thread +where + match(c.beitrag) against ('+abc' in boolean mode) +group by + a.text, b.id, b.betreff +order by + match(b.betreff) against ('+abc' in boolean mode) desc; + +--error 1109 +select a.text, b.id, b.betreff +from + t2 a inner join t3 b on a.id = b.forum inner join + t1 c on b.id = c.thread +where + match(b.betreff) against ('+abc' in boolean mode) +union +select a.text, b.id, b.betreff +from + t2 a inner join t3 b on a.id = b.forum inner join + t1 c on b.id = c.thread +where + match(c.beitrag) against ('+abc' in boolean mode) +order by + match(b.betreff) against ('+abc' in boolean mode) desc; + +select a.text, b.id, b.betreff +from + t2 a inner join t3 b on a.id = b.forum inner join + t1 c on b.id = c.thread +where + match(b.betreff) against ('+abc' in boolean mode) +union +select a.text, b.id, b.betreff +from + t2 a inner join t3 b on a.id = b.forum inner join + t1 c on b.id = c.thread +where + match(c.beitrag) against ('+abc' in boolean mode) +order by + match(betreff) against ('+abc' in boolean mode) desc; + +drop table t1,t2,t3; + diff --git a/sql/item_func.cc b/sql/item_func.cc index 442ef15bba8..fd45323aae2 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3196,6 +3196,9 @@ bool Item_func_match::fix_index() if (key == NO_SUCH_KEY) return 0; + + if (!table) + goto err; for (keynr=0 ; keynr < table->keys ; keynr++) { From be233935cc16ebc22b317e6da41f3f609c1d3874 Mon Sep 17 00:00:00 2001 From: "ramil@mysql.com" <> Date: Thu, 14 Jul 2005 20:19:27 +0500 Subject: [PATCH 22/42] fix for #11808 backported. --- tests/mysql_client_test.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index dbee6e77e4f..94295eeb38a 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -166,6 +166,14 @@ DIE_UNLESS(stmt == 0);\ #define mytest_r(x) if (x) {myerror(NULL);DIE_UNLESS(FALSE);} +/* A workaround for Sun Forte 5.6 on Solaris x86 */ + +static int cmp_double(double *a, double *b) +{ + return *a == *b; +} + + /* Print the error message */ static void print_error(const char *msg) @@ -1396,7 +1404,7 @@ static void test_prepare() DIE_UNLESS(real_data == o_real_data); DIE_UNLESS(length[5] == 4); - DIE_UNLESS(double_data == o_double_data); + DIE_UNLESS(cmp_double(&double_data, &o_double_data)); DIE_UNLESS(length[6] == 8); DIE_UNLESS(strcmp(data, str_data) == 0); @@ -9583,7 +9591,7 @@ static void test_bug3035() uint32 uint32_val; longlong int64_val; ulonglong uint64_val; - double double_val, udouble_val; + double double_val, udouble_val, double_tmp; char longlong_as_string[22], ulonglong_as_string[22]; /* mins and maxes */ @@ -9727,7 +9735,8 @@ static void test_bug3035() DIE_UNLESS(int64_val == int64_min); DIE_UNLESS(uint64_val == uint64_min); DIE_UNLESS(double_val == (longlong) uint64_min); - DIE_UNLESS(udouble_val == ulonglong2double(uint64_val)); + double_tmp= ulonglong2double(uint64_val); + DIE_UNLESS(cmp_double(&udouble_val, &double_tmp)); DIE_UNLESS(!strcmp(longlong_as_string, "0")); DIE_UNLESS(!strcmp(ulonglong_as_string, "0")); @@ -9743,7 +9752,8 @@ static void test_bug3035() DIE_UNLESS(int64_val == int64_max); DIE_UNLESS(uint64_val == uint64_max); DIE_UNLESS(double_val == (longlong) uint64_val); - DIE_UNLESS(udouble_val == ulonglong2double(uint64_val)); + double_tmp= ulonglong2double(uint64_val); + DIE_UNLESS(cmp_double(&udouble_val, &double_tmp)); DIE_UNLESS(!strcmp(longlong_as_string, "-1")); DIE_UNLESS(!strcmp(ulonglong_as_string, "18446744073709551615")); From 63ffc745326b0205b6b994098f6db230671576f1 Mon Sep 17 00:00:00 2001 From: "lenz@mysql.com" <> Date: Thu, 14 Jul 2005 17:50:33 +0200 Subject: [PATCH 23/42] - suppress warning when running this test with a "classic" build (which does not include InnoDB) --- mysql-test/t/ctype_utf8.test | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 737dcbcf1ed..dee41d0aa6e 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -776,12 +776,14 @@ INSERT INTO t1 VALUES (1,'blah','464','aaa','fkc1c9ilc20x0hgae7lx6j09','ERR','ERR Имри.Ðфимим.Ðеимимримдмримрмрирор имримримримр имридм ирбднримрфмририримрфмфмим.Ðд.Д имдимримрад.Ðдимримримрмдиримримримр м.Дадимфшьмримд им.Ðдимимрн имадми','ИМРИ.ÐФИМИМ.ÐЕИМИМРИМДМРИМРМРИРОР',3,'2005-06-01 17:30:43','1234567890'), (2,'blah','464','aaa','haxpl2ilc20x00bj4tt2m5ti','11','11 g','G',3,'2005-06-02 22:43:10','1234567890'); +--disable_warnings CREATE TABLE t2 ( `msisdn` varchar(15) NOT NULL default '', `operator_id` int(11) NOT NULL default '0', `created` datetime NOT NULL default '0000-00-00 00:00:00', UNIQUE KEY `PK_user` (`msisdn`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +--enable_warnings INSERT INTO t2 VALUES ('1234567890',2,'2005-05-24 13:53:25'); From 96a80fd2206df3df0df4a713e0a0c6cbf55fc61d Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 14 Jul 2005 18:02:32 +0200 Subject: [PATCH 24/42] added debug prints --- ndb/include/portlib/NdbTCP.h | 12 ++++++++--- ndb/include/util/SocketServer.hpp | 8 ++++++- ndb/src/common/mgmcommon/ConfigRetriever.cpp | 9 ++++++-- ndb/src/common/mgmcommon/IPCConfig.cpp | 7 +++++-- ndb/src/common/portlib/NdbMutex.c | 16 ++++++++------ ndb/src/common/portlib/NdbTCP.cpp | 9 ++++++++ ndb/src/common/portlib/NdbThread.c | 16 ++++++++++---- .../transporter/TransporterRegistry.cpp | 12 +++++++++-- ndb/src/common/util/Parser.cpp | 21 +++++++++++-------- ndb/src/common/util/SocketClient.cpp | 2 ++ ndb/src/common/util/SocketServer.cpp | 4 ++++ 11 files changed, 87 insertions(+), 29 deletions(-) diff --git a/ndb/include/portlib/NdbTCP.h b/ndb/include/portlib/NdbTCP.h index 8138a2ef354..308a3833ffd 100644 --- a/ndb/include/portlib/NdbTCP.h +++ b/ndb/include/portlib/NdbTCP.h @@ -31,7 +31,7 @@ #define NDB_NONBLOCK FNDELAY #define NDB_SOCKET_TYPE int #define NDB_INVALID_SOCKET -1 -#define NDB_CLOSE_SOCKET(x) close(x) +#define _NDB_CLOSE_SOCKET(x) close(x) /** * socklen_t not defined in the header files of OSE @@ -52,7 +52,7 @@ typedef int socklen_t; #define EWOULDBLOCK WSAEWOULDBLOCK #define NDB_SOCKET_TYPE SOCKET #define NDB_INVALID_SOCKET INVALID_SOCKET -#define NDB_CLOSE_SOCKET(x) closesocket(x) +#define _NDB_CLOSE_SOCKET(x) closesocket(x) #else @@ -64,7 +64,7 @@ typedef int socklen_t; #define NDB_NONBLOCK O_NONBLOCK #define NDB_SOCKET_TYPE int #define NDB_INVALID_SOCKET -1 -#define NDB_CLOSE_SOCKET(x) ::close(x) +#define _NDB_CLOSE_SOCKET(x) ::close(x) #define InetErrno errno @@ -89,6 +89,12 @@ extern "C" { */ int Ndb_getInAddr(struct in_addr * dst, const char *address); +#ifdef DBUG_OFF +#define NDB_CLOSE_SOCKET(fd) _NDB_CLOSE_SOCKET(fd) +#else +int NDB_CLOSE_SOCKET(int fd); +#endif + #ifdef __cplusplus } #endif diff --git a/ndb/include/util/SocketServer.hpp b/ndb/include/util/SocketServer.hpp index 9d8af204391..ee2dd31c41f 100644 --- a/ndb/include/util/SocketServer.hpp +++ b/ndb/include/util/SocketServer.hpp @@ -41,7 +41,13 @@ public: protected: friend class SocketServer; friend void* sessionThread_C(void*); - Session(NDB_SOCKET_TYPE sock): m_socket(sock){ m_stop = m_stopped = false;} + Session(NDB_SOCKET_TYPE sock): m_socket(sock) + { + DBUG_ENTER("SocketServer::Session"); + DBUG_PRINT("enter",("NDB_SOCKET: %d", m_socket)); + m_stop = m_stopped = false; + DBUG_VOID_RETURN; + } bool m_stop; // Has the session been ordered to stop? bool m_stopped; // Has the session stopped? diff --git a/ndb/src/common/mgmcommon/ConfigRetriever.cpp b/ndb/src/common/mgmcommon/ConfigRetriever.cpp index 648f3b4a52c..f77f823f2a4 100644 --- a/ndb/src/common/mgmcommon/ConfigRetriever.cpp +++ b/ndb/src/common/mgmcommon/ConfigRetriever.cpp @@ -47,6 +47,8 @@ ConfigRetriever::ConfigRetriever(const char * _connect_string, Uint32 version, Uint32 node_type) { + DBUG_ENTER("ConfigRetriever::ConfigRetriever"); + m_version = version; m_node_type = node_type; _ownNodeId= 0; @@ -55,23 +57,26 @@ ConfigRetriever::ConfigRetriever(const char * _connect_string, if (m_handle == 0) { setError(CR_ERROR, "Unable to allocate mgm handle"); - return; + DBUG_VOID_RETURN; } if (ndb_mgm_set_connectstring(m_handle, _connect_string)) { setError(CR_ERROR, ndb_mgm_get_latest_error_desc(m_handle)); - return; + DBUG_VOID_RETURN; } resetError(); + DBUG_VOID_RETURN; } ConfigRetriever::~ConfigRetriever() { + DBUG_ENTER("ConfigRetriever::~ConfigRetriever"); if (m_handle) { ndb_mgm_disconnect(m_handle); ndb_mgm_destroy_handle(&m_handle); } + DBUG_VOID_RETURN; } Uint32 diff --git a/ndb/src/common/mgmcommon/IPCConfig.cpp b/ndb/src/common/mgmcommon/IPCConfig.cpp index 86791490863..8cf5e6e8d45 100644 --- a/ndb/src/common/mgmcommon/IPCConfig.cpp +++ b/ndb/src/common/mgmcommon/IPCConfig.cpp @@ -114,7 +114,10 @@ IPCConfig::addRemoteNodeId(NodeId nodeId){ * Returns no of transporters configured */ int -IPCConfig::configureTransporters(TransporterRegistry * theTransporterRegistry){ +IPCConfig::configureTransporters(TransporterRegistry * theTransporterRegistry) +{ + DBUG_ENTER("IPCConfig::configureTransporters"); + int noOfTransportersCreated = 0; Uint32 noOfConnections; @@ -276,7 +279,7 @@ IPCConfig::configureTransporters(TransporterRegistry * theTransporterRegistry){ continue; } } - return noOfTransportersCreated; + DBUG_RETURN(noOfTransportersCreated); } /** diff --git a/ndb/src/common/portlib/NdbMutex.c b/ndb/src/common/portlib/NdbMutex.c index d3d39ea8cf7..18f8548e4e6 100644 --- a/ndb/src/common/portlib/NdbMutex.c +++ b/ndb/src/common/portlib/NdbMutex.c @@ -23,33 +23,37 @@ NdbMutex* NdbMutex_Create(void) { + DBUG_ENTER("NdbMutex_Create"); NdbMutex* pNdbMutex; int result; pNdbMutex = (NdbMutex*)NdbMem_Allocate(sizeof(NdbMutex)); + DBUG_PRINT("info",("NdbMem_Allocate 0x%lx",pNdbMutex)); if (pNdbMutex == NULL) - return NULL; + DBUG_RETURN(NULL); result = pthread_mutex_init(pNdbMutex, NULL); assert(result == 0); - return pNdbMutex; - + DBUG_RETURN(pNdbMutex); } int NdbMutex_Destroy(NdbMutex* p_mutex) { + DBUG_ENTER("NdbMutex_Destroy"); int result; if (p_mutex == NULL) - return -1; + DBUG_RETURN(-1); result = pthread_mutex_destroy(p_mutex); - free(p_mutex); + + DBUG_PRINT("info",("NdbMem_Free 0x%lx",p_mutex)); + NdbMem_Free(p_mutex); - return result; + DBUG_RETURN(result); } diff --git a/ndb/src/common/portlib/NdbTCP.cpp b/ndb/src/common/portlib/NdbTCP.cpp index a63f5a7ba27..c7b9d33c5f6 100644 --- a/ndb/src/common/portlib/NdbTCP.cpp +++ b/ndb/src/common/portlib/NdbTCP.cpp @@ -54,6 +54,15 @@ Ndb_getInAddr(struct in_addr * dst, const char *address) { return -1; //DBUG_RETURN(-1); } +#ifndef DBUG_OFF +extern "C" +int NDB_CLOSE_SOCKET(int fd) +{ + DBUG_PRINT("info", ("NDB_CLOSE_SOCKET(%d)", fd)); + return _NDB_CLOSE_SOCKET(fd); +} +#endif + #if 0 int Ndb_getInAddr(struct in_addr * dst, const char *address) { diff --git a/ndb/src/common/portlib/NdbThread.c b/ndb/src/common/portlib/NdbThread.c index aaee9b45069..cee4ec018a0 100644 --- a/ndb/src/common/portlib/NdbThread.c +++ b/ndb/src/common/portlib/NdbThread.c @@ -56,6 +56,7 @@ ndb_thread_wrapper(void* _ss){ void *ret; struct NdbThread * ss = (struct NdbThread *)_ss; ret= (* ss->func)(ss->object); + DBUG_POP(); NdbThread_Exit(ret); } /* will never be reached */ @@ -70,6 +71,7 @@ struct NdbThread* NdbThread_Create(NDB_THREAD_FUNC *p_thread_func, const char* p_thread_name, NDB_THREAD_PRIO thread_prio) { + DBUG_ENTER("NdbThread_Create"); struct NdbThread* tmpThread; int result; pthread_attr_t thread_attr; @@ -77,11 +79,13 @@ struct NdbThread* NdbThread_Create(NDB_THREAD_FUNC *p_thread_func, (void)thread_prio; /* remove warning for unused parameter */ if (p_thread_func == NULL) - return 0; + DBUG_RETURN(NULL); tmpThread = (struct NdbThread*)NdbMem_Allocate(sizeof(struct NdbThread)); if (tmpThread == NULL) - return NULL; + DBUG_RETURN(NULL); + + DBUG_PRINT("info",("thread_name: %s", p_thread_name)); strnmov(tmpThread->thread_name,p_thread_name,sizeof(tmpThread->thread_name)); @@ -108,16 +112,20 @@ struct NdbThread* NdbThread_Create(NDB_THREAD_FUNC *p_thread_func, assert(result==0); pthread_attr_destroy(&thread_attr); - return tmpThread; + DBUG_PRINT("exit",("ret: %lx", tmpThread)); + DBUG_RETURN(tmpThread); } void NdbThread_Destroy(struct NdbThread** p_thread) { - if (*p_thread != NULL){ + DBUG_ENTER("NdbThread_Destroy"); + if (*p_thread != NULL){ + DBUG_PRINT("enter",("*p_thread: %lx", * p_thread)); free(* p_thread); * p_thread = 0; } + DBUG_VOID_RETURN; } diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp index ac6161b314e..3e2c105fa2e 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -70,7 +70,9 @@ SocketServer::Session * TransporterService::newSession(NDB_SOCKET_TYPE sockfd) TransporterRegistry::TransporterRegistry(void * callback, unsigned _maxTransporters, - unsigned sizeOfLongSignalMemory) { + unsigned sizeOfLongSignalMemory) +{ + DBUG_ENTER("TransporterRegistry::TransporterRegistry"); nodeIdSpecified = false; maxTransporters = _maxTransporters; @@ -107,9 +109,13 @@ TransporterRegistry::TransporterRegistry(void * callback, theOSEReceiver = 0; theOSEJunkSocketSend = 0; theOSEJunkSocketRecv = 0; + + DBUG_VOID_RETURN; } -TransporterRegistry::~TransporterRegistry() { +TransporterRegistry::~TransporterRegistry() +{ + DBUG_ENTER("TransporterRegistry::~TransporterRegistry"); removeAll(); @@ -129,6 +135,8 @@ TransporterRegistry::~TransporterRegistry() { theOSEReceiver = 0; } #endif + + DBUG_VOID_RETURN; } void diff --git a/ndb/src/common/util/Parser.cpp b/ndb/src/common/util/Parser.cpp index dea128ccf66..d692aa18392 100644 --- a/ndb/src/common/util/Parser.cpp +++ b/ndb/src/common/util/Parser.cpp @@ -141,7 +141,10 @@ split(char * buf, char ** name, char ** value){ bool ParserImpl::run(Context * ctx, const class Properties ** pDst, - volatile bool * stop) const { + volatile bool * stop) const +{ + DBUG_ENTER("ParserImpl::run"); + * pDst = 0; bool ownStop = false; if(stop == 0) @@ -153,24 +156,24 @@ ParserImpl::run(Context * ctx, const class Properties ** pDst, ctx->m_currentToken = input.gets(ctx->m_tokenBuffer, sz); if(Eof(ctx->m_currentToken)){ ctx->m_status = Parser::Eof; - return false; + DBUG_RETURN(false); } if(ctx->m_currentToken[0] == 0){ ctx->m_status = Parser::NoLine; - return false; + DBUG_RETURN(false); } if(Empty(ctx->m_currentToken)){ ctx->m_status = Parser::EmptyLine; - return false; + DBUG_RETURN(false); } trim(ctx->m_currentToken); ctx->m_currentCmd = matchCommand(ctx, ctx->m_currentToken, m_rows); if(ctx->m_currentCmd == 0){ ctx->m_status = Parser::UnknownCommand; - return false; + DBUG_RETURN(false); } Properties * p = new Properties(); @@ -200,19 +203,19 @@ ParserImpl::run(Context * ctx, const class Properties ** pDst, tmp = input.gets(buf, sz); } while((! * stop) && !Eof(tmp) && !Empty(tmp)); } - return false; + DBUG_RETURN(false); } if(* stop){ delete p; ctx->m_status = Parser::ExternalStop; - return false; + DBUG_RETURN(false); } if(!checkMandatory(ctx, p)){ ctx->m_status = Parser::MissingMandatoryArgument; delete p; - return false; + DBUG_RETURN(false); } /** @@ -229,7 +232,7 @@ ParserImpl::run(Context * ctx, const class Properties ** pDst, ctx->m_status = Parser::Ok; * pDst = p; - return true; + DBUG_RETURN(true); } const ParserImpl::DummyRow* diff --git a/ndb/src/common/util/SocketClient.cpp b/ndb/src/common/util/SocketClient.cpp index 38df1417eb8..821624eb5c4 100644 --- a/ndb/src/common/util/SocketClient.cpp +++ b/ndb/src/common/util/SocketClient.cpp @@ -57,6 +57,8 @@ SocketClient::init() return false; } + DBUG_PRINT("info",("NDB_SOCKET: %d", m_sockfd)); + return true; } diff --git a/ndb/src/common/util/SocketServer.cpp b/ndb/src/common/util/SocketServer.cpp index da06389b5df..db5c03f925a 100644 --- a/ndb/src/common/util/SocketServer.cpp +++ b/ndb/src/common/util/SocketServer.cpp @@ -64,6 +64,8 @@ SocketServer::tryBind(unsigned short port, const char * intface) { return false; } + DBUG_PRINT("info",("NDB_SOCKET: %d", sock)); + const int on = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)) == -1) { @@ -104,6 +106,8 @@ SocketServer::setup(SocketServer::Service * service, DBUG_RETURN(false); } + DBUG_PRINT("info",("NDB_SOCKET: %d", sock)); + const int on = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on)) == -1) { From 9be420ee105609aade80f1c84767605ba4306e0f Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 14 Jul 2005 18:02:33 +0200 Subject: [PATCH 25/42] stilled mem leak in usage on getVersionString added __LINE__ so systemErrorLab for better error printout --- ndb/include/ndb_version.h.in | 12 +++++- ndb/include/util/version.h | 3 +- ndb/src/common/util/version.c | 12 +++--- ndb/src/kernel/blocks/qmgr/Qmgr.hpp | 4 +- ndb/src/kernel/blocks/qmgr/QmgrMain.cpp | 51 ++++++++++++------------- ndb/tools/restore/restore_main.cpp | 3 +- 6 files changed, 48 insertions(+), 37 deletions(-) diff --git a/ndb/include/ndb_version.h.in b/ndb/include/ndb_version.h.in index d7f43eae40a..826f5124407 100644 --- a/ndb/include/ndb_version.h.in +++ b/ndb/include/ndb_version.h.in @@ -36,8 +36,16 @@ #define MAKE_VERSION(A,B,C) (((A) << 16) | ((B) << 8) | ((C) << 0)) #define NDB_VERSION_D MAKE_VERSION(NDB_VERSION_MAJOR, NDB_VERSION_MINOR, NDB_VERSION_BUILD) - -#define NDB_VERSION_STRING (getVersionString(NDB_VERSION, NDB_VERSION_STATUS)) +#define NDB_VERSION_STRING_BUF_SZ 100 +#ifdef __cplusplus +extern "C" +#else +extern +#endif +char ndb_version_string_buf[NDB_VERSION_STRING_BUF_SZ]; +#define NDB_VERSION_STRING (getVersionString(NDB_VERSION, NDB_VERSION_STATUS, \ + ndb_version_string_buf, \ + sizeof(ndb_version_string_buf))) #define NDB_VERSION ndbGetOwnVersion() diff --git a/ndb/include/util/version.h b/ndb/include/util/version.h index 5459e44b818..62dc07d905a 100644 --- a/ndb/include/util/version.h +++ b/ndb/include/util/version.h @@ -30,7 +30,8 @@ extern "C" { Uint32 makeVersion(Uint32 major, Uint32 minor, Uint32 build); - const char* getVersionString(Uint32 version, const char * status); + const char* getVersionString(Uint32 version, const char * status, + char *buf, unsigned sz); void ndbPrintVersion(); Uint32 ndbGetOwnVersion(); diff --git a/ndb/src/common/util/version.c b/ndb/src/common/util/version.c index 7221dc48fa4..ba4bcf30516 100644 --- a/ndb/src/common/util/version.c +++ b/ndb/src/common/util/version.c @@ -38,22 +38,24 @@ Uint32 makeVersion(Uint32 major, Uint32 minor, Uint32 build) { } -const char * getVersionString(Uint32 version, const char * status) { - char buff[100]; +char ndb_version_string_buf[NDB_VERSION_STRING_BUF_SZ]; +const char * getVersionString(Uint32 version, const char * status, + char *buf, unsigned sz) +{ if (status && status[0] != 0) - basestring_snprintf(buff, sizeof(buff), + basestring_snprintf(buf, sz, "Version %d.%d.%d (%s)", getMajor(version), getMinor(version), getBuild(version), status); else - basestring_snprintf(buff, sizeof(buff), + basestring_snprintf(buf, sz, "Version %d.%d.%d", getMajor(version), getMinor(version), getBuild(version)); - return strdup(buff); + return buf; } typedef enum { diff --git a/ndb/src/kernel/blocks/qmgr/Qmgr.hpp b/ndb/src/kernel/blocks/qmgr/Qmgr.hpp index 0ff7cea6d9f..6d22ed0e509 100644 --- a/ndb/src/kernel/blocks/qmgr/Qmgr.hpp +++ b/ndb/src/kernel/blocks/qmgr/Qmgr.hpp @@ -257,8 +257,8 @@ private: void hbReceivedLab(Signal* signal); void sendCmRegrefLab(Signal* signal, BlockReference ref, CmRegRef::ErrorCode); - void systemErrorBecauseOtherNodeFailed(Signal* signal, NodeId); - void systemErrorLab(Signal* signal, + void systemErrorBecauseOtherNodeFailed(Signal* signal, Uint32 line, NodeId); + void systemErrorLab(Signal* signal, Uint32 line, const char* message = NULL); void prepFailReqLab(Signal* signal); void prepFailConfLab(Signal* signal); diff --git a/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp b/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp index da8596076ec..0337640d229 100644 --- a/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp +++ b/ndb/src/kernel/blocks/qmgr/QmgrMain.cpp @@ -76,7 +76,7 @@ void Qmgr::execCM_HEARTBEAT(Signal* signal) void Qmgr::execCM_NODEINFOREF(Signal* signal) { jamEntry(); - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); return; }//Qmgr::execCM_NODEINFOREF() @@ -121,7 +121,7 @@ void Qmgr::execCONTINUEB(Signal* signal) default: jam(); // ZCOULD_NOT_OCCUR_ERROR; - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); return; break; }//switch @@ -593,7 +593,7 @@ void Qmgr::execCM_REGCONF(Signal* signal) jam(); char buf[128]; BaseString::snprintf(buf,sizeof(buf),"incompatible version own=0x%x other=0x%x, shutting down", NDB_VERSION, cmRegConf->presidentVersion); - systemErrorLab(signal, buf); + systemErrorLab(signal, __LINE__, buf); return; } @@ -688,7 +688,7 @@ void Qmgr::execCM_REGREF(Signal* signal) switch (TrefuseReason) { case CmRegRef::ZINCOMPATIBLE_VERSION: jam(); - systemErrorLab(signal, "incompatible version, connection refused by running ndb node"); + systemErrorLab(signal, __LINE__, "incompatible version, connection refused by running ndb node"); break; case CmRegRef::ZBUSY: case CmRegRef::ZBUSY_TO_PRES: @@ -1751,7 +1751,7 @@ void Qmgr::execAPI_FAILCONF(Signal* signal) if (failedNodePtr.p->rcv[0] == failedNodePtr.p->rcv[1]) { jam(); - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); } else { jam(); failedNodePtr.p->rcv[0] = 0; @@ -1763,7 +1763,7 @@ void Qmgr::execAPI_FAILCONF(Signal* signal) ndbout << "failedNodePtr.p->failState = " << (Uint32)(failedNodePtr.p->failState) << endl; #endif - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); }//if return; }//Qmgr::execAPI_FAILCONF() @@ -1780,7 +1780,7 @@ void Qmgr::execNDB_FAILCONF(Signal* signal) failedNodePtr.p->failState = NORMAL; } else { jam(); - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); }//if if (cpresident == getOwnNodeId()) { jam(); @@ -1931,20 +1931,13 @@ void Qmgr::execAPI_REGREQ(Signal* signal) #endif bool compatability_check; - switch(getNodeInfo(apiNodePtr.i).getType()){ + NodeInfo::NodeType type= getNodeInfo(apiNodePtr.i).getType(); + switch(type){ case NodeInfo::API: compatability_check = ndbCompatible_ndb_api(NDB_VERSION, version); - if (!compatability_check) - infoEvent("Connection attempt from api or mysqld id=%d with %s " - "incompatible with %s", apiNodePtr.i, - getVersionString(version,""), NDB_VERSION_STRING); break; case NodeInfo::MGM: compatability_check = ndbCompatible_ndb_mgmt(NDB_VERSION, version); - if (!compatability_check) - infoEvent("Connection attempt from management server id=%d with %s " - "incompatible with %s", apiNodePtr.i, - getVersionString(version,""), NDB_VERSION_STRING); break; case NodeInfo::REP: // compatability_check = ndbCompatible_ndb_api(NDB_VERSION, version); @@ -1953,13 +1946,19 @@ void Qmgr::execAPI_REGREQ(Signal* signal) case NodeInfo::INVALID: default: sendApiRegRef(signal, ref, ApiRegRef::WrongType); - infoEvent("Invalid connection attempt with type %d", - getNodeInfo(apiNodePtr.i).getType()); + infoEvent("Invalid connection attempt with type %d", type); return; } if (!compatability_check) { jam(); + char buf[NDB_VERSION_STRING_BUF_SZ]; + infoEvent("Connection attempt from %s id=%d with %s " + "incompatible with %s", + type == NodeInfo::API ? "api or mysqld" : "management server", + apiNodePtr.i, + getVersionString(version,"",buf,sizeof(buf)), + NDB_VERSION_STRING); apiNodePtr.p->phase = ZAPI_INACTIVE; sendApiRegRef(signal, ref, ApiRegRef::UnsupportedVersion); return; @@ -2085,7 +2084,7 @@ void Qmgr::failReportLab(Signal* signal, Uint16 aFailedNode, ptrCheckGuard(failedNodePtr, MAX_NODES, nodeRec); if (failedNodePtr.i == getOwnNodeId()) { jam(); - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); return; }//if @@ -2093,7 +2092,7 @@ void Qmgr::failReportLab(Signal* signal, Uint16 aFailedNode, ptrCheckGuard(myNodePtr, MAX_NDB_NODES, nodeRec); if (myNodePtr.p->phase != ZRUNNING) { jam(); - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); return; }//if TnoFailedNodes = cnoFailedNodes; @@ -2172,7 +2171,7 @@ void Qmgr::execPREP_FAILREQ(Signal* signal) ptrCheckGuard(myNodePtr, MAX_NDB_NODES, nodeRec); if (myNodePtr.p->phase != ZRUNNING) { jam(); - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); return; }//if @@ -2675,7 +2674,7 @@ void Qmgr::execREAD_NODESREQ(Signal* signal) ReadNodesConf::SignalLength, JBB); }//Qmgr::execREAD_NODESREQ() -void Qmgr::systemErrorBecauseOtherNodeFailed(Signal* signal, +void Qmgr::systemErrorBecauseOtherNodeFailed(Signal* signal, Uint32 line, NodeId failedNodeId) { jam(); @@ -2687,11 +2686,11 @@ void Qmgr::systemErrorBecauseOtherNodeFailed(Signal* signal, "Node was shutdown during startup because node %d failed", failedNodeId); - progError(__LINE__, ERR_SR_OTHERNODEFAILED, buf); + progError(line, ERR_SR_OTHERNODEFAILED, buf); } -void Qmgr::systemErrorLab(Signal* signal, const char * message) +void Qmgr::systemErrorLab(Signal* signal, Uint32 line, const char * message) { jam(); // Broadcast that this node is failing to other nodes @@ -2699,7 +2698,7 @@ void Qmgr::systemErrorLab(Signal* signal, const char * message) // If it's known why shutdown occured // an error message has been passed to this function - progError(__LINE__, 0, message); + progError(line, 0, message); return; }//Qmgr::systemErrorLab() @@ -2867,7 +2866,7 @@ Uint16 Qmgr::translateDynamicIdToNodeId(Signal* signal, UintR TdynamicId) }//for if (TtdiNodeId == ZNIL) { jam(); - systemErrorLab(signal); + systemErrorLab(signal, __LINE__); }//if return TtdiNodeId; }//Qmgr::translateDynamicIdToNodeId() diff --git a/ndb/tools/restore/restore_main.cpp b/ndb/tools/restore/restore_main.cpp index 84f9511fe2f..0c4419bb072 100644 --- a/ndb/tools/restore/restore_main.cpp +++ b/ndb/tools/restore/restore_main.cpp @@ -251,8 +251,9 @@ main(int argc, char** argv) const BackupFormat::FileHeader & tmp = metaData.getFileHeader(); const Uint32 version = tmp.NdbVersion; + char buf[NDB_VERSION_STRING_BUF_SZ]; ndbout << "Ndb version in backup files: " - << getVersionString(version, 0) << endl; + << getVersionString(version, 0, buf, sizeof(buf)) << endl; /** * check wheater we can restore the backup (right version). From a1270b65db4e017ca512fab9554e0d4961062c05 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Thu, 14 Jul 2005 20:02:33 +0400 Subject: [PATCH 26/42] A fix and a test case for Bug#11183 "mysql_stmt_reset() doesn't reset information about error". --- libmysql/libmysql.c | 12 +++++++++++ tests/mysql_client_test.c | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 4d92db26406..d80b2ef0e39 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1834,6 +1834,17 @@ static void net_clear_error(NET *net) } } + +static void stmt_clear_error(MYSQL_STMT *stmt) +{ + if (stmt->last_errno) + { + stmt->last_errno= 0; + stmt->last_error[0]= '\0'; + strmov(stmt->sqlstate, not_error_sqlstate); + } +} + /* Set statement error code, sqlstate, and error message from given errcode and sqlstate. @@ -4625,6 +4636,7 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) param < param_end; param++) param->long_data_used= 0; + stmt_clear_error(stmt); DBUG_RETURN(0); } diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index f874276a656..b7398494deb 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -11697,6 +11697,50 @@ static void test_bug9735() myquery(rc); } +/* Bug#11183 "mysql_stmt_reset() doesn't reset information about error" */ + +static void test_bug11183() +{ + int rc; + MYSQL_STMT *stmt; + char bug_statement[]= "insert into t1 values (1)"; + + myheader("test_bug11183"); + + mysql_query(mysql, "drop table t1 if exists"); + mysql_query(mysql, "create table t1 (a int)"); + + stmt= mysql_stmt_init(mysql); + DIE_UNLESS(stmt != 0); + + rc= mysql_stmt_prepare(stmt, bug_statement, strlen(bug_statement)); + check_execute(stmt, rc); + + rc= mysql_query(mysql, "drop table t1"); + myquery(rc); + + /* Trying to execute statement that should fail on execute stage */ + rc= mysql_stmt_execute(stmt); + DIE_UNLESS(rc); + + mysql_stmt_reset(stmt); + DIE_UNLESS(mysql_stmt_errno(stmt) == 0); + + mysql_query(mysql, "create table t1 (a int)"); + + /* Trying to execute statement that should pass ok */ + if (mysql_stmt_execute(stmt)) + { + mysql_stmt_reset(stmt); + DIE_UNLESS(mysql_stmt_errno(stmt) == 0); + } + + mysql_stmt_close(stmt); + + rc= mysql_query(mysql, "drop table t1"); + myquery(rc); +} + /* Read and parse arguments and MySQL options from my.cnf @@ -11913,6 +11957,7 @@ static struct my_tests_st my_tests[]= { { "test_bug7990", test_bug7990 }, { "test_bug8378", test_bug8378 }, { "test_bug9735", test_bug9735 }, + { "test_bug11183", test_bug11183 }, { 0, 0 } }; From 8afeb337f04b2f50687c7b364b2884a331ea17a9 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 14 Jul 2005 18:04:44 +0200 Subject: [PATCH 27/42] BUG#11898 ndb_mgmd not releasing resources, added "ping" on add_listener + added close of some fd's + debug prints --- ndb/src/mgmclient/CommandInterpreter.cpp | 34 +++++++-- ndb/src/mgmsrv/MgmtSrvr.hpp | 11 +-- ndb/src/mgmsrv/Services.cpp | 93 +++++++++++++++++++----- 3 files changed, 105 insertions(+), 33 deletions(-) diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp index 34fe57d1fca..e1619917de5 100644 --- a/ndb/src/mgmclient/CommandInterpreter.cpp +++ b/ndb/src/mgmclient/CommandInterpreter.cpp @@ -455,11 +455,13 @@ static int do_event_thread; static void* event_thread_run(void* m) { + DBUG_ENTER("event_thread_run"); + NdbMgmHandle handle= *(NdbMgmHandle*)m; int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 }; int fd = ndb_mgm_listen_event(handle, filter); - if (fd > 0) + if (fd != NDB_INVALID_SOCKET) { do_event_thread= 1; char *tmp= 0; @@ -468,20 +470,26 @@ event_thread_run(void* m) do { if (tmp == 0) NdbSleep_MilliSleep(10); if((tmp = in.gets(buf, 1024))) - ndbout << tmp; + { + const char ping_token[]= ""; + if (memcmp(ping_token,tmp,sizeof(ping_token)-1)) + ndbout << tmp; + } } while(do_event_thread); + NDB_CLOSE_SOCKET(fd); } else { do_event_thread= -1; } - return NULL; + DBUG_RETURN(NULL); } bool CommandInterpreter::connect() { + DBUG_ENTER("CommandInterpreter::connect"); if(!m_connected) { if(!ndb_mgm_connect(m_mgmsrv, try_reconnect-1, 5, 1)) @@ -512,8 +520,19 @@ CommandInterpreter::connect() do_event_thread == 0 || do_event_thread == -1) { - printf("Warning, event thread startup failed, degraded printouts as result\n"); + DBUG_PRINT("info",("Warning, event thread startup failed, " + "degraded printouts as result, errno=%d", + errno)); + printf("Warning, event thread startup failed, " + "degraded printouts as result, errno=%d\n", errno); do_event_thread= 0; + if (m_event_thread) + { + void *res; + NdbThread_WaitFor(m_event_thread, &res); + NdbThread_Destroy(&m_event_thread); + } + ndb_mgm_disconnect(m_mgmsrv2); } } else @@ -521,6 +540,8 @@ CommandInterpreter::connect() printf("Warning, event connect failed, degraded printouts as result\n"); } m_connected= true; + DBUG_PRINT("info",("Connected to Management Server at: %s:%d", + host,port)); if (m_verbose) { printf("Connected to Management Server at: %s:%d\n", @@ -528,12 +549,13 @@ CommandInterpreter::connect() } } } - return m_connected; + DBUG_RETURN(m_connected); } bool CommandInterpreter::disconnect() { + DBUG_ENTER("CommandInterpreter::disconnect"); if (m_event_thread) { void *res; do_event_thread= 0; @@ -550,7 +572,7 @@ CommandInterpreter::disconnect() } m_connected= false; } - return true; + DBUG_RETURN(true); } //***************************************************************************** diff --git a/ndb/src/mgmsrv/MgmtSrvr.hpp b/ndb/src/mgmsrv/MgmtSrvr.hpp index ce78983b3c3..423668fbd0e 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.hpp +++ b/ndb/src/mgmsrv/MgmtSrvr.hpp @@ -60,6 +60,7 @@ public: } void add_listener(const Event_listener&); + void check_listeners(); void update_max_log_level(const LogLevel&); void update_log_level(const LogLevel&); @@ -764,16 +765,6 @@ private: int send(class NdbApiSignal* signal, Uint32 node, Uint32 node_type); ConfigRetriever *m_config_retriever; - -public: - /** - * This method does not exist - */ - struct Area51 { - class TransporterFacade * theFacade; - class TransporterRegistry * theRegistry; - }; - Area51 getStuff(); }; inline diff --git a/ndb/src/mgmsrv/Services.cpp b/ndb/src/mgmsrv/Services.cpp index 8ba8c2fe87e..00cf6390c73 100644 --- a/ndb/src/mgmsrv/Services.cpp +++ b/ndb/src/mgmsrv/Services.cpp @@ -253,15 +253,19 @@ ParserRow commands[] = { }; MgmApiSession::MgmApiSession(class MgmtSrvr & mgm, NDB_SOCKET_TYPE sock) - : SocketServer::Session(sock), m_mgmsrv(mgm) { + : SocketServer::Session(sock), m_mgmsrv(mgm) +{ + DBUG_ENTER("MgmApiSession::MgmApiSession"); m_input = new SocketInputStream(sock); m_output = new SocketOutputStream(sock); m_parser = new Parser_t(commands, *m_input, true, true, true); m_allocated_resources= new MgmtSrvr::Allocated_resources(m_mgmsrv); + DBUG_VOID_RETURN; } MgmApiSession::~MgmApiSession() { + DBUG_ENTER("MgmApiSession::~MgmApiSession"); if (m_input) delete m_input; if (m_output) @@ -270,10 +274,19 @@ MgmApiSession::~MgmApiSession() delete m_parser; if (m_allocated_resources) delete m_allocated_resources; + if(m_socket != NDB_INVALID_SOCKET) + { + NDB_CLOSE_SOCKET(m_socket); + m_socket= NDB_INVALID_SOCKET; + } + DBUG_VOID_RETURN; } void -MgmApiSession::runSession() { +MgmApiSession::runSession() +{ + DBUG_ENTER("MgmApiSession::runSession"); + Parser_t::Context ctx; while(!m_stop) { m_parser->run(ctx, *this); @@ -301,8 +314,13 @@ MgmApiSession::runSession() { break; } } - if(m_socket >= 0) + if(m_socket != NDB_INVALID_SOCKET) + { NDB_CLOSE_SOCKET(m_socket); + m_socket= NDB_INVALID_SOCKET; + } + + DBUG_VOID_RETURN; } #ifdef MGM_GET_CONFIG_BACKWARDS_COMPAT @@ -1236,7 +1254,7 @@ Ndb_mgmd_event_service::log(int eventType, const Uint32* theData, NodeId nodeId) Uint32 threshold; LogLevel::EventCategory cat; Logger::LoggerLevel severity; - int i; + int i, n; DBUG_ENTER("Ndb_mgmd_event_service::log"); DBUG_PRINT("enter",("eventType=%d, nodeid=%d", eventType, nodeId)); @@ -1248,28 +1266,30 @@ Ndb_mgmd_event_service::log(int eventType, const Uint32* theData, NodeId nodeId) Vector copy; m_clients.lock(); - for(i = m_clients.size() - 1; i >= 0; i--){ - if(threshold <= m_clients[i].m_logLevel.getLogLevel(cat)){ - if(m_clients[i].m_socket != NDB_INVALID_SOCKET && - println_socket(m_clients[i].m_socket, - MAX_WRITE_TIMEOUT, m_text) == -1){ - copy.push_back(m_clients[i].m_socket); + for(i = m_clients.size() - 1; i >= 0; i--) + { + if(threshold <= m_clients[i].m_logLevel.getLogLevel(cat)) + { + int fd= m_clients[i].m_socket; + if(fd != NDB_INVALID_SOCKET && + println_socket(fd, MAX_WRITE_TIMEOUT, m_text) == -1) + { + copy.push_back(fd); m_clients.erase(i, false); } } } m_clients.unlock(); - for(i = 0; (unsigned)i < copy.size(); i++){ - NDB_CLOSE_SOCKET(copy[i]); - } + if ((n= (int)copy.size())) + { + for(i= 0; i < n; i++) + NDB_CLOSE_SOCKET(copy[i]); - if(copy.size()){ LogLevel tmp; tmp.clear(); m_clients.lock(); - for(i = 0; (unsigned)i < m_clients.size(); i++){ + for(i= m_clients.size() - 1; i >= 0; i--) tmp.set_max(m_clients[i].m_logLevel); - } m_clients.unlock(); update_log_level(tmp); } @@ -1297,9 +1317,48 @@ Ndb_mgmd_event_service::update_log_level(const LogLevel &tmp) } void -Ndb_mgmd_event_service::add_listener(const Event_listener& client){ +Ndb_mgmd_event_service::check_listeners() +{ + int i, n= 0; + DBUG_ENTER("Ndb_mgmd_event_service::check_listeners"); + m_clients.lock(); + for(i= m_clients.size() - 1; i >= 0; i--) + { + int fd= m_clients[i].m_socket; + DBUG_PRINT("info",("%d %d",i,fd)); + char buf[1]; + buf[0]=0; + if (fd != NDB_INVALID_SOCKET && + println_socket(fd,MAX_WRITE_TIMEOUT,"") == -1) + { + NDB_CLOSE_SOCKET(fd); + m_clients.erase(i, false); + n=1; + } + } + if (n) + { + LogLevel tmp; tmp.clear(); + for(i= m_clients.size() - 1; i >= 0; i--) + tmp.set_max(m_clients[i].m_logLevel); + update_log_level(tmp); + } + m_clients.unlock(); + DBUG_VOID_RETURN; +} + +void +Ndb_mgmd_event_service::add_listener(const Event_listener& client) +{ + DBUG_ENTER("Ndb_mgmd_event_service::add_listener"); + DBUG_PRINT("enter",("client.m_socket: %d", client.m_socket)); + + check_listeners(); + m_clients.push_back(client); update_max_log_level(client.m_logLevel); + + DBUG_VOID_RETURN; } void From ec52d680d23ed13a1f1799301f77dc0da2eeae72 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Thu, 14 Jul 2005 18:08:01 +0200 Subject: [PATCH 28/42] misc (memleak) fixes: added using ndb_end and showing mem allocation stat at exit added init of variable added destruction of LocalConfig to still memleak added delete of theFacade on exit stopSessions(true) on socket server to ensure destuction of threads added destruction of arbit manager thread added true option to stopSessions in transporter facade to ensure destructions of threads --- ndb/include/util/ndb_opts.h | 2 + ndb/src/common/logger/LogHandler.cpp | 1 + ndb/src/mgmapi/mgmapi.cpp | 19 +++++- ndb/src/mgmclient/main.cpp | 8 ++- ndb/src/mgmsrv/MgmtSrvr.cpp | 25 ++----- ndb/src/mgmsrv/main.cpp | 99 ++++++++++++++-------------- ndb/src/ndbapi/ClusterMgr.cpp | 18 +++-- ndb/src/ndbapi/TransporterFacade.cpp | 25 ++++--- 8 files changed, 112 insertions(+), 85 deletions(-) diff --git a/ndb/include/util/ndb_opts.h b/ndb/include/util/ndb_opts.h index aa7a02f58ae..ca4ca5eac83 100644 --- a/ndb/include/util/ndb_opts.h +++ b/ndb/include/util/ndb_opts.h @@ -28,6 +28,7 @@ const char *opt_connect_str= 0;\ my_bool opt_ndb_optimized_node_selection +bool opt_endinfo= 0; my_bool opt_ndb_shm; #define OPT_NDB_CONNECTSTRING 'c' @@ -93,6 +94,7 @@ ndb_std_get_one_option(int optid, { DBUG_PUSH(argument); } + opt_endinfo= 1; break; case 'V': ndb_std_print_version(); diff --git a/ndb/src/common/logger/LogHandler.cpp b/ndb/src/common/logger/LogHandler.cpp index ec4137297f1..a9d4512112f 100644 --- a/ndb/src/common/logger/LogHandler.cpp +++ b/ndb/src/common/logger/LogHandler.cpp @@ -31,6 +31,7 @@ LogHandler::LogHandler() : m_last_message[0]= 0; m_last_log_time= 0; m_now= 0; + m_last_level= (Logger::LoggerLevel)-1; } LogHandler::~LogHandler() diff --git a/ndb/src/mgmapi/mgmapi.cpp b/ndb/src/mgmapi/mgmapi.cpp index 863f54ce51a..6a949c6006d 100644 --- a/ndb/src/mgmapi/mgmapi.cpp +++ b/ndb/src/mgmapi/mgmapi.cpp @@ -143,6 +143,7 @@ extern "C" NdbMgmHandle ndb_mgm_create_handle() { + DBUG_ENTER("ndb_mgm_create_handle"); NdbMgmHandle h = (NdbMgmHandle)my_malloc(sizeof(ndb_mgm_handle),MYF(MY_WME)); h->connected = 0; @@ -162,17 +163,20 @@ ndb_mgm_create_handle() h->logfile = 0; #endif - return h; + DBUG_PRINT("exit",("ret: %lx", h)); + DBUG_RETURN(h); } extern "C" int ndb_mgm_set_connectstring(NdbMgmHandle handle, const char * mgmsrv) { + handle->cfg.~LocalConfig(); new (&(handle->cfg)) LocalConfig; if (!handle->cfg.init(mgmsrv, 0) || handle->cfg.ids.size() == 0) { + handle->cfg.~LocalConfig(); new (&(handle->cfg)) LocalConfig; handle->cfg.init(0, 0); /* reset the LocalCongig */ SET_ERROR(handle, NDB_MGM_ILLEGAL_CONNECT_STRING, ""); @@ -189,8 +193,11 @@ extern "C" void ndb_mgm_destroy_handle(NdbMgmHandle * handle) { + DBUG_ENTER("ndb_mgm_destroy_handle"); if(!handle) return; + DBUG_PRINT("enter",("*handle: %lx", *handle)); + if((* handle)->connected){ ndb_mgm_disconnect(* handle); } @@ -203,6 +210,7 @@ ndb_mgm_destroy_handle(NdbMgmHandle * handle) (*handle)->cfg.~LocalConfig(); my_free((char*)* handle,MYF(MY_ALLOW_ZERO_PTR)); * handle = 0; + DBUG_VOID_RETURN; } /***************************************************************************** @@ -251,6 +259,9 @@ static const Properties * ndb_mgm_call(NdbMgmHandle handle, const ParserRow *command_reply, const char *cmd, const Properties *cmd_args) { + DBUG_ENTER("ndb_mgm_call"); + DBUG_PRINT("enter",("handle->socket: %d, cmd: %s", + handle->socket, cmd)); SocketOutputStream out(handle->socket); SocketInputStream in(handle->socket, handle->read_timeout); @@ -310,6 +321,8 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow *command_reply, /** * Print some info about why the parser returns NULL */ + DBUG_PRINT("info",("ctx.status: %d, ctx.m_currentToken: %s", + ctx.m_status, ctx.m_currentToken)); //ndbout << " status=" << ctx.m_status << ", curr=" //<< ctx.m_currentToken << endl; } @@ -321,9 +334,9 @@ ndb_mgm_call(NdbMgmHandle handle, const ParserRow *command_reply, p->print(handle->logfile, "IN: "); } #endif - return p; + DBUG_RETURN(p); #else - return parser.parse(ctx, session); + DBUG_RETURN(parser.parse(ctx, session)); #endif } diff --git a/ndb/src/mgmclient/main.cpp b/ndb/src/mgmclient/main.cpp index 73f0bad86c0..9128df4f978 100644 --- a/ndb/src/mgmclient/main.cpp +++ b/ndb/src/mgmclient/main.cpp @@ -44,7 +44,9 @@ static Ndb_mgmclient* com; extern "C" void -handler(int sig){ +handler(int sig) +{ + DBUG_ENTER("handler"); switch(sig){ case SIGPIPE: /** @@ -54,6 +56,7 @@ handler(int sig){ com->disconnect(); break; } + DBUG_VOID_RETURN; } NDB_STD_OPTS_VARS; @@ -166,7 +169,8 @@ int main(int argc, char** argv){ com->execute(opt_execute_str,_try_reconnect, &ret); } delete com; - + + ndb_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); return ret; } diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp index ceaedc9955b..34bc8d433cc 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.cpp +++ b/ndb/src/mgmsrv/MgmtSrvr.cpp @@ -571,10 +571,11 @@ MgmtSrvr::check_start() bool MgmtSrvr::start(BaseString &error_string) { + DBUG_ENTER("MgmtSrvr::start"); if (_props == NULL) { if (!check_start()) { error_string.append("MgmtSrvr.cpp: check_start() failed."); - return false; + DBUG_RETURN(false); } } theFacade= TransporterFacade::theFacadeInstance= new TransporterFacade(); @@ -582,12 +583,12 @@ MgmtSrvr::start(BaseString &error_string) if(theFacade == 0) { DEBUG("MgmtSrvr.cpp: theFacade is NULL."); error_string.append("MgmtSrvr.cpp: theFacade is NULL."); - return false; + DBUG_RETURN(false); } if ( theFacade->start_instance (_ownNodeId, (ndb_mgm_configuration*)_config->m_configValues) < 0) { DEBUG("MgmtSrvr.cpp: TransporterFacade::start_instance < 0."); - return false; + DBUG_RETURN(false); } MGM_REQUIRE(_blockNumber == 1); @@ -603,7 +604,7 @@ MgmtSrvr::start(BaseString &error_string) error_string.append("MgmtSrvr.cpp: _blockNumber is -1."); theFacade->stop_instance(); theFacade = 0; - return false; + DBUG_RETURN(false); } _ownReference = numberToRef(_blockNumber, _ownNodeId); @@ -625,7 +626,7 @@ MgmtSrvr::start(BaseString &error_string) "MgmtSrvr_Service", NDB_THREAD_PRIO_LOW); - return true; + DBUG_RETURN(true); } @@ -639,6 +640,7 @@ MgmtSrvr::~MgmtSrvr() if(theFacade != 0){ theFacade->stop_instance(); + delete theFacade; theFacade = 0; } @@ -2583,19 +2585,6 @@ MgmtSrvr::repCommand(Uint32* repReqId, Uint32 request, bool waitCompleted) } -/***************************************************************************** - * Area 51 ??? - *****************************************************************************/ - -MgmtSrvr::Area51 -MgmtSrvr::getStuff() -{ - Area51 ret; - ret.theFacade = theFacade; - ret.theRegistry = theFacade->theTransporterRegistry; - return ret; -} - NodeId MgmtSrvr::getPrimaryNode() const { #if 0 diff --git a/ndb/src/mgmsrv/main.cpp b/ndb/src/mgmsrv/main.cpp index 61b83b86538..ffe58231eb3 100644 --- a/ndb/src/mgmsrv/main.cpp +++ b/ndb/src/mgmsrv/main.cpp @@ -53,16 +53,16 @@ const char progname[] = "mgmtsrvr"; * @struct MgmGlobals * @brief Global Variables used in the management server ******************************************************************************/ +/** Command line arguments */ +static int opt_daemon; // NOT bool, bool need not be int +static int opt_non_interactive; +static int opt_interactive; +static const char * opt_config_filename= 0; + struct MgmGlobals { MgmGlobals(); ~MgmGlobals(); - /** Command line arguments */ - int daemon; // NOT bool, bool need not be int - int non_interactive; - int interactive; - const char * config_filename; - /** Stuff found in environment or in local config */ NodeId localNodeId; bool use_specific_ip; @@ -77,7 +77,7 @@ struct MgmGlobals { }; int g_no_nodeid_checks= 0; -static MgmGlobals glob; +static MgmGlobals *glob= 0; /****************************************************************************** * Function prototypes @@ -108,14 +108,14 @@ static struct my_option my_long_options[] = { NDB_STD_OPTS("ndb_mgmd"), { "config-file", 'f', "Specify cluster configuration file", - (gptr*) &glob.config_filename, (gptr*) &glob.config_filename, 0, + (gptr*) &opt_config_filename, (gptr*) &opt_config_filename, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, { "daemon", 'd', "Run ndb_mgmd in daemon mode (default)", - (gptr*) &glob.daemon, (gptr*) &glob.daemon, 0, + (gptr*) &opt_daemon, (gptr*) &opt_daemon, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0 }, { "interactive", OPT_INTERACTIVE, "Run interactive. Not supported but provided for testing purposes", - (gptr*) &glob.interactive, (gptr*) &glob.interactive, 0, + (gptr*) &opt_interactive, (gptr*) &opt_interactive, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, { "no-nodeid-checks", OPT_NO_NODEID_CHECKS, "Do not provide any node id checks", @@ -123,13 +123,13 @@ static struct my_option my_long_options[] = GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, { "nodaemon", OPT_NO_DAEMON, "Don't run as daemon, but don't read from stdin", - (gptr*) &glob.non_interactive, (gptr*) &glob.non_interactive, 0, + (gptr*) &opt_non_interactive, (gptr*) &opt_non_interactive, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 }, #if NDB_VERSION_MAJOR <= 4 { "config-file", 'c', "-c provided for backwards compatability, will be removed in 5.0." " Use -f instead", - (gptr*) &glob.config_filename, (gptr*) &glob.config_filename, 0, + (gptr*) &opt_config_filename, (gptr*) &opt_config_filename, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, #endif { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} @@ -167,6 +167,7 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), int main(int argc, char** argv) { NDB_INIT(argv[0]); + glob= new MgmGlobals; /** * OSE specific. Enable shared ownership of file system resources. @@ -186,40 +187,40 @@ int main(int argc, char** argv) if ((ho_error=handle_options(&argc, &argv, my_long_options, get_one_option))) exit(ho_error); - if (glob.interactive || - glob.non_interactive) { - glob.daemon= 0; + if (opt_interactive || + opt_non_interactive) { + opt_daemon= 0; } - glob.socketServer = new SocketServer(); + glob->socketServer = new SocketServer(); MgmApiService * mapi = new MgmApiService(); - glob.mgmObject = new MgmtSrvr(glob.socketServer, - glob.config_filename, + glob->mgmObject = new MgmtSrvr(glob->socketServer, + opt_config_filename, opt_connect_str); - if (glob.mgmObject->init()) + if (glob->mgmObject->init()) goto error_end; my_setwd(NdbConfig_get_path(0), MYF(0)); - glob.localNodeId= glob.mgmObject->getOwnNodeId(); - if (glob.localNodeId == 0) { + glob->localNodeId= glob->mgmObject->getOwnNodeId(); + if (glob->localNodeId == 0) { goto error_end; } - glob.port= glob.mgmObject->getPort(); + glob->port= glob->mgmObject->getPort(); - if (glob.port == 0) + if (glob->port == 0) goto error_end; - glob.interface_name = 0; - glob.use_specific_ip = false; + glob->interface_name = 0; + glob->use_specific_ip = false; - if(!glob.use_specific_ip){ + if(!glob->use_specific_ip){ int count= 5; // no of retries for tryBind - while(!glob.socketServer->tryBind(glob.port, glob.interface_name)){ + while(!glob->socketServer->tryBind(glob->port, glob->interface_name)){ if (--count > 0) { NdbSleep_MilliSleep(1000); continue; @@ -228,33 +229,33 @@ int main(int argc, char** argv) "Please check if the port is already used,\n" "(perhaps a ndb_mgmd is already running),\n" "and if you are executing on the correct computer", - (glob.interface_name ? glob.interface_name : "*"), glob.port); + (glob->interface_name ? glob->interface_name : "*"), glob->port); goto error_end; } - free(glob.interface_name); - glob.interface_name = 0; + free(glob->interface_name); + glob->interface_name = 0; } - if(!glob.socketServer->setup(mapi, glob.port, glob.interface_name)){ + if(!glob->socketServer->setup(mapi, glob->port, glob->interface_name)){ ndbout_c("Unable to setup management port: %d!\n" "Please check if the port is already used,\n" "(perhaps a ndb_mgmd is already running),\n" "and if you are executing on the correct computer", - glob.port); + glob->port); delete mapi; goto error_end; } - if(!glob.mgmObject->check_start()){ + if(!glob->mgmObject->check_start()){ ndbout_c("Unable to check start management server."); ndbout_c("Probably caused by illegal initial configuration file."); goto error_end; } - if (glob.daemon) { + if (opt_daemon) { // Become a daemon - char *lockfile= NdbConfig_PidFileName(glob.localNodeId); - char *logfile= NdbConfig_StdoutFileName(glob.localNodeId); + char *lockfile= NdbConfig_PidFileName(glob->localNodeId); + char *logfile= NdbConfig_StdoutFileName(glob->localNodeId); NdbAutoPtr tmp_aptr1(lockfile), tmp_aptr2(logfile); if (NdbDaemon_Make(lockfile, logfile, 0) == -1) { @@ -268,7 +269,7 @@ int main(int argc, char** argv) #endif { BaseString error_string; - if(!glob.mgmObject->start(error_string)){ + if(!glob->mgmObject->start(error_string)){ ndbout_c("Unable to start management server."); ndbout_c("Probably caused by illegal initial configuration file."); ndbout_c(error_string.c_str()); @@ -276,8 +277,8 @@ int main(int argc, char** argv) } } - //glob.mgmObject->saveConfig(); - mapi->setMgm(glob.mgmObject); + //glob->mgmObject->saveConfig(); + mapi->setMgm(glob->mgmObject); char msg[256]; BaseString::snprintf(msg, sizeof(msg), @@ -286,16 +287,16 @@ int main(int argc, char** argv) g_eventLogger.info(msg); BaseString::snprintf(msg, 256, "Id: %d, Command port: %d", - glob.localNodeId, glob.port); + glob->localNodeId, glob->port); ndbout_c(msg); g_eventLogger.info(msg); g_StopServer = false; - glob.socketServer->startServer(); + glob->socketServer->startServer(); #if ! defined NDB_OSE && ! defined NDB_SOFTOSE - if(glob.interactive) { - CommandInterpreter com(* glob.mgmObject); + if(opt_interactive) { + CommandInterpreter com(* glob->mgmObject); while(com.readAndExecute()); } else #endif @@ -305,22 +306,22 @@ int main(int argc, char** argv) } g_eventLogger.info("Shutting down server..."); - glob.socketServer->stopServer(); - glob.socketServer->stopSessions(); + glob->socketServer->stopServer(); + glob->socketServer->stopSessions(true); g_eventLogger.info("Shutdown complete"); + delete glob; + ndb_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); return 0; error_end: + delete glob; + ndb_end(opt_endinfo ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); return 1; } MgmGlobals::MgmGlobals(){ // Default values port = 0; - config_filename = NULL; interface_name = 0; - daemon = 1; - non_interactive = 0; - interactive = 0; socketServer = 0; mgmObject = 0; } diff --git a/ndb/src/ndbapi/ClusterMgr.cpp b/ndb/src/ndbapi/ClusterMgr.cpp index 9603ddf7751..543bdf1155e 100644 --- a/ndb/src/ndbapi/ClusterMgr.cpp +++ b/ndb/src/ndbapi/ClusterMgr.cpp @@ -64,16 +64,21 @@ ClusterMgr::ClusterMgr(TransporterFacade & _facade): theStop(0), theFacade(_facade) { + DBUG_ENTER("ClusterMgr::ClusterMgr"); ndbSetOwnVersion(); clusterMgrThreadMutex = NdbMutex_Create(); noOfAliveNodes= 0; noOfConnectedNodes= 0; theClusterMgrThread= 0; + DBUG_VOID_RETURN; } -ClusterMgr::~ClusterMgr(){ +ClusterMgr::~ClusterMgr() +{ + DBUG_ENTER("ClusterMgr::~ClusterMgr"); doStop(); NdbMutex_Destroy(clusterMgrThreadMutex); + DBUG_VOID_RETURN; } void @@ -152,7 +157,6 @@ ClusterMgr::doStop( ){ if (theClusterMgrThread) { NdbThread_WaitFor(theClusterMgrThread, &status); NdbThread_Destroy(&theClusterMgrThread); - theClusterMgrThread= 0; } NdbMutex_Unlock(clusterMgrThreadMutex); DBUG_VOID_RETURN; @@ -468,6 +472,8 @@ ClusterMgr::reportNodeFailed(NodeId nodeId){ ArbitMgr::ArbitMgr(TransporterFacade & _fac) : theFacade(_fac) { + DBUG_ENTER("ArbitMgr::ArbitMgr"); + theThreadMutex = NdbMutex_Create(); theInputCond = NdbCondition_Create(); theInputMutex = NdbMutex_Create(); @@ -485,13 +491,17 @@ ArbitMgr::ArbitMgr(TransporterFacade & _fac) memset(&theChooseReq1, 0, sizeof(theChooseReq1)); memset(&theChooseReq2, 0, sizeof(theChooseReq2)); memset(&theStopOrd, 0, sizeof(theStopOrd)); + + DBUG_VOID_RETURN; } ArbitMgr::~ArbitMgr() { + DBUG_ENTER("ArbitMgr::~ArbitMgr"); NdbMutex_Destroy(theThreadMutex); NdbCondition_Destroy(theInputCond); NdbMutex_Destroy(theInputMutex); + DBUG_VOID_RETURN; } // Start arbitrator thread. This is kernel request. @@ -508,7 +518,7 @@ ArbitMgr::doStart(const Uint32* theData) sendSignalToThread(aSignal); void* value; NdbThread_WaitFor(theThread, &value); - theThread = NULL; + NdbThread_Destroy(&theThread); theState = StateInit; theInputFull = false; } @@ -547,7 +557,7 @@ ArbitMgr::doStop(const Uint32* theData) sendSignalToThread(aSignal); void* value; NdbThread_WaitFor(theThread, &value); - theThread = NULL; + NdbThread_Destroy(&theThread); theState = StateInit; } NdbMutex_Unlock(theThreadMutex); diff --git a/ndb/src/ndbapi/TransporterFacade.cpp b/ndb/src/ndbapi/TransporterFacade.cpp index 93cec59ada6..a06a8b588b1 100644 --- a/ndb/src/ndbapi/TransporterFacade.cpp +++ b/ndb/src/ndbapi/TransporterFacade.cpp @@ -395,12 +395,10 @@ TransporterFacade::doStop(){ if (theReceiveThread) { NdbThread_WaitFor(theReceiveThread, &status); NdbThread_Destroy(&theReceiveThread); - theReceiveThread= 0; } if (theSendThread) { NdbThread_WaitFor(theSendThread, &status); NdbThread_Destroy(&theSendThread); - theSendThread= 0; } DBUG_VOID_RETURN; } @@ -435,7 +433,7 @@ void TransporterFacade::threadMainSend(void) theTransporterRegistry->stopSending(); m_socket_server.stopServer(); - m_socket_server.stopSessions(); + m_socket_server.stopSessions(true); theTransporterRegistry->stop_clients(); } @@ -477,6 +475,8 @@ TransporterFacade::TransporterFacade() : theReceiveThread(NULL), m_fragmented_signal_id(0) { + DBUG_ENTER("TransporterFacade::TransporterFacade"); + theOwnId = 0; theMutexPtr = NdbMutex_Create(); @@ -493,11 +493,15 @@ TransporterFacade::TransporterFacade() : m_max_trans_id = 0; theClusterMgr = new ClusterMgr(* this); + + DBUG_VOID_RETURN; } bool TransporterFacade::init(Uint32 nodeId, const ndb_mgm_configuration* props) { + DBUG_ENTER("TransporterFacade::init"); + theOwnId = nodeId; theTransporterRegistry = new TransporterRegistry(this); @@ -506,7 +510,7 @@ TransporterFacade::init(Uint32 nodeId, const ndb_mgm_configuration* props) * theTransporterRegistry); if(res <= 0){ TRP_DEBUG( "configureTransporters returned 0 or less" ); - return false; + DBUG_RETURN(false); } ndb_mgm_configuration_iterator iter(* props, CFG_SECTION_NODE); @@ -524,7 +528,7 @@ TransporterFacade::init(Uint32 nodeId, const ndb_mgm_configuration* props) iter.first(); if(iter.find(CFG_NODE_ID, nodeId)){ TRP_DEBUG( "Node info missing from config." ); - return false; + DBUG_RETURN(false); } Uint32 rank = 0; @@ -553,7 +557,7 @@ TransporterFacade::init(Uint32 nodeId, const ndb_mgm_configuration* props) if (!theTransporterRegistry->start_service(m_socket_server)){ ndbout_c("Unable to start theTransporterRegistry->start_service"); - return false; + DBUG_RETURN(false); } theReceiveThread = NdbThread_Create(runReceiveResponse_C, @@ -573,7 +577,7 @@ TransporterFacade::init(Uint32 nodeId, const ndb_mgm_configuration* props) signalLogger.logOn(true, 0, SignalLoggerManager::LogInOut); #endif - return true; + DBUG_RETURN(true); } @@ -694,8 +698,10 @@ TransporterFacade::open(void* objRef, DBUG_RETURN(r); } -TransporterFacade::~TransporterFacade(){ - +TransporterFacade::~TransporterFacade() +{ + DBUG_ENTER("TransporterFacade::~TransporterFacade"); + NdbMutex_Lock(theMutexPtr); delete theClusterMgr; delete theArbitMgr; @@ -705,6 +711,7 @@ TransporterFacade::~TransporterFacade(){ #ifdef API_TRACE signalLogger.setOutputStream(0); #endif + DBUG_VOID_RETURN; } void From a2b11ff2664cf00fea3aa10bd98c6fbb14ff6fc7 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Fri, 15 Jul 2005 00:01:49 +0400 Subject: [PATCH 29/42] A fix and a test case for Bug#11299 "prepared statement makes wrong SQL syntax in binlog which stops replication": disallow the use of parameter markers which can lead to generation of malformed binlog queries. --- mysql-test/r/ps.result | 16 ++++++++++++++++ mysql-test/t/ps.test | 22 ++++++++++++++++++++++ sql/sql_lex.cc | 9 +++++++++ sql/sql_yacc.yy | 19 ++++++------------- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index ee558e0ea89..6cd32cbe8d0 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -660,3 +660,19 @@ lily river drop table t1; deallocate prepare stmt; +create table t1 (a int); +prepare stmt from "select ??"; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 +prepare stmt from "select ?FROM t1"; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?FROM t1' at line 1 +prepare stmt from "select FROM t1 WHERE?=1"; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM t1 WHERE?=1' at line 1 +prepare stmt from "update t1 set a=a+?WHERE 1"; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?WHERE 1' at line 1 +select ?; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1 +select ??; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '??' at line 1 +select ? from t1; +ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? from t1' at line 1 +drop table t1; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index 01d62a2e198..d08098606a1 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -679,3 +679,25 @@ execute stmt using @param1; select utext from t1 where utext like '%%'; drop table t1; deallocate prepare stmt; +# +# Bug#11299 "prepared statement makes wrong SQL syntax in binlog which stops +# replication": check that errouneous queries with placeholders are not +# allowed +# +create table t1 (a int); +--error 1064 +prepare stmt from "select ??"; +--error 1064 +prepare stmt from "select ?FROM t1"; +--error 1064 +prepare stmt from "select FROM t1 WHERE?=1"; +--error 1064 +prepare stmt from "update t1 set a=a+?WHERE 1"; +--error 1064 +select ?; +--error 1064 +select ??; +--error 1064 +select ? from t1; +drop table t1; +# diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 904b4675c74..42e3b678c09 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -554,6 +554,15 @@ int yylex(void *arg, void *yythd) lex->next_state= MY_LEX_START; // Allow signed numbers if (c == ',') lex->tok_start=lex->ptr; // Let tok_start point at next item + /* + Check for a placeholder: it should not precede a possible identifier + because of binlogging: when a placeholder is replaced with + its value in a query for the binlog, the query must stay + grammatically correct. + */ + else if (c == '?' && ((THD*) yythd)->command == COM_PREPARE && + !ident_map[cs, yyPeek()]) + return(PARAM_MARKER); return((int) c); case MY_LEX_IDENT_OR_NCHAR: diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index bc21649fe54..2587ce7e1a5 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -528,6 +528,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %token NOW_SYM %token OLD_PASSWORD %token PASSWORD +%token PARAM_MARKER %token POINTFROMTEXT %token POINT_SYM %token POLYFROMTEXT @@ -4857,23 +4858,15 @@ text_string: ; param_marker: - '?' + PARAM_MARKER { THD *thd=YYTHD; LEX *lex= thd->lex; - if (thd->command == COM_PREPARE) + Item_param *item= new Item_param((uint) (lex->tok_start - + (uchar *) thd->query)); + if (!($$= item) || lex->param_list.push_back(item)) { - Item_param *item= new Item_param((uint) (lex->tok_start - - (uchar *) thd->query)); - if (!($$= item) || lex->param_list.push_back(item)) - { - send_error(thd, ER_OUT_OF_RESOURCES); - YYABORT; - } - } - else - { - yyerror(ER(ER_SYNTAX_ERROR)); + send_error(thd, ER_OUT_OF_RESOURCES); YYABORT; } } From 7646850173643e84a2b252d4a5a8764403de9fd3 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Fri, 15 Jul 2005 00:26:19 +0400 Subject: [PATCH 30/42] Hastily remove an occasionally checked in symlink :( From a4a5bc42a6886d6865d95e2bb84349da53991348 Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Fri, 15 Jul 2005 02:11:07 +0400 Subject: [PATCH 31/42] Fix ps.test in --ps-protocol --- mysql-test/t/ps.test | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index d08098606a1..beae95d462a 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -693,11 +693,13 @@ prepare stmt from "select ?FROM t1"; prepare stmt from "select FROM t1 WHERE?=1"; --error 1064 prepare stmt from "update t1 set a=a+?WHERE 1"; +--disable_ps_protocol --error 1064 select ?; --error 1064 select ??; --error 1064 select ? from t1; +--enable_ps_protocol drop table t1; # From 07d4f27195efc64cba7af16cf07e54ea545599d2 Mon Sep 17 00:00:00 2001 From: "ramil@mysql.com" <> Date: Fri, 15 Jul 2005 11:17:57 +0500 Subject: [PATCH 32/42] Jim's fix for the #10443. Fix handling of floats and doubles when using prepared statements API in the embedded server. --- sql/sql_prepare.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 9e2612c5661..89f930fa735 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -306,24 +306,28 @@ static void set_param_int64(Item_param *param, uchar **pos, ulong len) static void set_param_float(Item_param *param, uchar **pos, ulong len) { + float data; #ifndef EMBEDDED_LIBRARY if (len < 4) return; -#endif - float data; float4get(data,*pos); +#else + data= *(float*) *pos; +#endif param->set_double((double) data); *pos+= 4; } static void set_param_double(Item_param *param, uchar **pos, ulong len) { + double data; #ifndef EMBEDDED_LIBRARY if (len < 8) return; -#endif - double data; float8get(data,*pos); +#else + data= *(double*) *pos; +#endif param->set_double((double) data); *pos+= 8; } From 0d7a2641b5c05a2e90ca04bb1002be1c7d63ab69 Mon Sep 17 00:00:00 2001 From: "lenz@mysql.com" <> Date: Fri, 15 Jul 2005 08:54:11 +0200 Subject: [PATCH 33/42] RPM spec file improvements: - create a "mysql" user group and assign the mysql user account to that group in the server postinstall section. (BUG 10984) - backported some changes from the 4.1 RPM spec file (cleanups: removed the incomplete Brazilian translations, more consequent use of macros) --- support-files/mysql.spec.sh | 65 +++++++++++++++---------------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh index 2354b44f4fa..ade774fb4e3 100644 --- a/support-files/mysql.spec.sh +++ b/support-files/mysql.spec.sh @@ -1,7 +1,9 @@ %define mysql_version @VERSION@ %define release 0 +%define license GPL %define mysqld_user mysql %define server_suffix -standard +%define mysqldatadir /var/lib/mysql # We don't package all files installed into the build root by intention - # See BUG#998 for details. @@ -12,11 +14,9 @@ Name: MySQL Summary: MySQL: a very fast and reliable SQL database server Group: Applications/Databases -Summary(pt_BR): MySQL: Um servidor SQL rápido e confiável. -Group(pt_BR): Aplicações/Banco_de_Dados Version: @MYSQL_NO_DASH_VERSION@ Release: %{release} -License: GPL +License: %{license} Source: http://www.mysql.com/Downloads/MySQL-@MYSQL_BASE_VERSION@/mysql-%{mysql_version}.tar.gz URL: http://www.mysql.com/ Packager: Lenz Grimmer @@ -50,11 +50,8 @@ news and information about the MySQL software. Also please see the documentation and the manual for more information. %package server -Release: %{release} Summary: MySQL: a very fast and reliable SQL database server Group: Applications/Databases -Summary(pt_BR): MySQL: Um servidor SQL rápido e confiável. -Group(pt_BR): Aplicações/Banco_de_Dados Requires: fileutils sh-utils Provides: msqlormysql mysql-server mysql MySQL Obsoletes: MySQL mysql mysql-server @@ -85,11 +82,8 @@ If you want to access and work with the database, you have to install package "MySQL-client" as well! %package client -Release: %{release} Summary: MySQL - Client Group: Applications/Databases -Summary(pt_BR): MySQL - Cliente -Group(pt_BR): Aplicações/Banco_de_Dados Obsoletes: mysql-client Provides: mysql-client @@ -98,16 +92,11 @@ This package contains the standard MySQL clients and administration tools. %{see_base} -%description client -l pt_BR -Este pacote contém os clientes padrão para o MySQL. %package bench -Release: %{release} Requires: %{name}-client perl-DBI perl Summary: MySQL - Benchmarks and test system Group: Applications/Databases -Summary(pt_BR): MySQL - Medições de desempenho -Group(pt_BR): Aplicações/Banco_de_Dados Provides: mysql-bench Obsoletes: mysql-bench @@ -116,15 +105,9 @@ This package contains MySQL benchmark scripts and data. %{see_base} -%description bench -l pt_BR -Este pacote contém medições de desempenho de scripts e dados do MySQL. - %package devel -Release: %{release} Summary: MySQL - Development header files and libraries Group: Applications/Databases -Summary(pt_BR): MySQL - Medições de desempenho -Group(pt_BR): Aplicações/Banco_de_Dados Provides: mysql-devel Obsoletes: mysql-devel @@ -134,12 +117,7 @@ necessary to develop MySQL client applications. %{see_base} -%description devel -l pt_BR -Este pacote contém os arquivos de cabeçalho (header files) e bibliotecas -necessárias para desenvolver aplicações clientes do MySQL. - %package shared -Release: %{release} Summary: MySQL - Shared libraries Group: Applications/Databases @@ -148,12 +126,11 @@ This package contains the shared libraries (*.so*) which certain languages and applications need to dynamically load and use MySQL. %package Max -Release: %{release} Summary: MySQL - server with Berkeley BD, RAID and UDF support Group: Applications/Databases Provides: mysql-Max Obsoletes: mysql-Max -Requires: MySQL-server >= 4.0 +Requires: MySQL-server >= @MYSQL_BASE_VERSION@ %description Max Optional MySQL server binary that supports additional features like @@ -164,12 +141,9 @@ the standard MySQL package. Please note that this is a dynamically linked binary! %package embedded -Release: %{release} Requires: %{name}-devel Summary: MySQL - embedded library Group: Applications/Databases -Summary(pt_BR): MySQL - Medições de desempenho -Group(pt_BR): Aplicações/Banco_de_Dados Obsoletes: mysql-embedded %description embedded @@ -216,7 +190,7 @@ sh -c "PATH=\"${MYSQL_BUILD_PATH:-$PATH}\" \ --libdir=%{_libdir} \ --sysconfdir=%{_sysconfdir} \ --datadir=%{_datadir} \ - --localstatedir=/var/lib/mysql \ + --localstatedir=%{mysqldatadir} \ --infodir=%{_infodir} \ --includedir=%{_includedir} \ --mandir=%{_mandir} \ @@ -325,7 +299,7 @@ MBD=$RPM_BUILD_DIR/mysql-%{mysql_version} # Ensure that needed directories exists install -d $RBR%{_sysconfdir}/{logrotate.d,init.d} -install -d $RBR/var/lib/mysql/mysql +install -d $RBR%{mysqldatadir}/mysql install -d $RBR%{_datadir}/{sql-bench,mysql-test} install -d $RBR%{_includedir} install -d $RBR%{_libdir} @@ -377,7 +351,7 @@ then fi %post server -mysql_datadir=/var/lib/mysql +mysql_datadir=%{mysqldatadir} # Create data directory if needed if test ! -d $mysql_datadir; then mkdir -m755 $mysql_datadir; fi @@ -395,19 +369,20 @@ then /sbin/chkconfig --add mysql fi -# Create a MySQL user. Do not report any problems if it already -# exists. This is redhat specific and should be handled more portable -useradd -M -r -d $mysql_datadir -s /bin/bash -c "MySQL server" mysql 2> /dev/null || true +# Create a MySQL user and group. Do not report any problems if it already +# exists. +groupadd -r -c "MySQL server" %{mysqld_user} 2> /dev/null || true +useradd -M -r -d $mysql_datadir -s /bin/bash -c "MySQL server" -g %{mysqld_user} %{mysqld_user} 2> /dev/null || true # Change permissions so that the user that will run the MySQL daemon # owns all database files. -chown -R mysql $mysql_datadir +chown -R %{mysqld_user}:%{mysqld_user} $mysql_datadir # Initiate databases -mysql_install_db -IN-RPM --user=mysql +%{_bindir}/mysql_install_db -IN-RPM --user=%{mysqld_user} # Change permissions again to fix any new files. -chown -R mysql $mysql_datadir +chown -R %{mysqld_user}:%{mysqld_user} $mysql_datadir # Fix permissions for the permission database so that only the user # can read them. @@ -587,6 +562,18 @@ fi # itself - note that they must be ordered by date (important when # merging BK trees) %changelog +* Fri Jul 15 2005 Lenz Grimmer + +- create a "mysql" user group and assign the mysql user account to that group + in the server postinstall section. (BUG 10984) + +* Wed Jun 01 2005 Lenz Grimmer + +- use "mysqldatadir" variable instead of hard-coding the path multiple times +- use the "mysqld_user" variable on all occasions a user name is referenced +- removed (incomplete) Brazilian translations +- removed redundant release tags from the subpackage descriptions + * Wed May 25 2005 Joerg Bruehe - Added a "make clean" between separate calls to "BuildMySQL". From da6d1504537795504f4159adb85fe3f9ce618c92 Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Fri, 15 Jul 2005 10:44:54 +0200 Subject: [PATCH 34/42] BUG#11596 (partial fix), IP addresses not shown in ndb_mgm SHOW command on second ndb_mgmd (or on ndb_mgmd restart) --- .../transporter/TransporterRegistry.hpp | 2 ++ ndb/src/common/transporter/Transporter.cpp | 15 +++++++++++++++ ndb/src/common/transporter/Transporter.hpp | 1 + .../common/transporter/TransporterRegistry.cpp | 6 ++++++ ndb/src/mgmsrv/MgmtSrvr.cpp | 18 ++++++++++++++++++ ndb/src/mgmsrv/MgmtSrvr.hpp | 2 +- 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ndb/include/transporter/TransporterRegistry.hpp b/ndb/include/transporter/TransporterRegistry.hpp index 8bd1de39ed5..410f3e1dc12 100644 --- a/ndb/include/transporter/TransporterRegistry.hpp +++ b/ndb/include/transporter/TransporterRegistry.hpp @@ -238,6 +238,8 @@ public: }; Vector m_transporter_interface; void add_transporter_interface(const char *interf, unsigned short port); + + struct in_addr get_connect_address(NodeId node_id) const; protected: private: diff --git a/ndb/src/common/transporter/Transporter.cpp b/ndb/src/common/transporter/Transporter.cpp index b84f8f6fb5e..328ce2816de 100644 --- a/ndb/src/common/transporter/Transporter.cpp +++ b/ndb/src/common/transporter/Transporter.cpp @@ -74,6 +74,7 @@ Transporter::Transporter(TransporterRegistry &t_reg, m_connected = false; m_timeOutMillis = 1000; + m_connect_address.s_addr= 0; if (isServer) m_socket_client= 0; else @@ -98,6 +99,13 @@ Transporter::connect_server(NDB_SOCKET_TYPE sockfd) { DBUG_RETURN(true); // TODO assert(0); } + { + struct sockaddr addr; + SOCKET_SIZE_TYPE addrlen= sizeof(addr); + int r= getpeername(sockfd, &addr, &addrlen); + m_connect_address= ((struct sockaddr_in *)&addr)->sin_addr; + } + bool res = connect_server_impl(sockfd); if(res){ m_connected = true; @@ -164,6 +172,13 @@ Transporter::connect_client() { g_eventLogger.warning("Unable to verify transporter compatability with node %d", nodeId); } + { + struct sockaddr addr; + SOCKET_SIZE_TYPE addrlen= sizeof(addr); + int r= getpeername(sockfd, &addr, &addrlen); + m_connect_address= ((struct sockaddr_in *)&addr)->sin_addr; + } + bool res = connect_client_impl(sockfd); if(res){ m_connected = true; diff --git a/ndb/src/common/transporter/Transporter.hpp b/ndb/src/common/transporter/Transporter.hpp index c3b0d144eaf..5f3f8063723 100644 --- a/ndb/src/common/transporter/Transporter.hpp +++ b/ndb/src/common/transporter/Transporter.hpp @@ -122,6 +122,7 @@ protected: private: SocketClient *m_socket_client; + struct in_addr m_connect_address; protected: Uint32 getErrorCount(); diff --git a/ndb/src/common/transporter/TransporterRegistry.cpp b/ndb/src/common/transporter/TransporterRegistry.cpp index ac6161b314e..0efad6d1a1d 100644 --- a/ndb/src/common/transporter/TransporterRegistry.cpp +++ b/ndb/src/common/transporter/TransporterRegistry.cpp @@ -51,6 +51,12 @@ extern int g_ndb_shm_signum; #include extern EventLogger g_eventLogger; +struct in_addr +TransporterRegistry::get_connect_address(NodeId node_id) const +{ + return theTransporters[node_id]->m_connect_address; +} + SocketServer::Session * TransporterService::newSession(NDB_SOCKET_TYPE sockfd) { DBUG_ENTER("SocketServer::Session * TransporterService::newSession"); diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp index ceaedc9955b..f17d2a41be1 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.cpp +++ b/ndb/src/mgmsrv/MgmtSrvr.cpp @@ -2124,6 +2124,24 @@ MgmtSrvr::getNodeType(NodeId nodeId) const return nodeTypes[nodeId]; } +const char *MgmtSrvr::get_connect_address(Uint32 node_id) +{ + if (m_connect_address[node_id].s_addr == 0 && + theFacade && theFacade->theTransporterRegistry && + theFacade->theClusterMgr && + getNodeType(node_id) == NDB_MGM_NODE_TYPE_NDB) + { + const ClusterMgr::Node &node= + theFacade->theClusterMgr->getNodeInfo(node_id); + if (node.connected) + { + m_connect_address[node_id]= + theFacade->theTransporterRegistry->get_connect_address(node_id); + } + } + return inet_ntoa(m_connect_address[node_id]); +} + void MgmtSrvr::get_connected_nodes(NodeBitmask &connected_nodes) const { diff --git a/ndb/src/mgmsrv/MgmtSrvr.hpp b/ndb/src/mgmsrv/MgmtSrvr.hpp index ce78983b3c3..9ed5c2eb1d4 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.hpp +++ b/ndb/src/mgmsrv/MgmtSrvr.hpp @@ -508,7 +508,7 @@ public: int setDbParameter(int node, int parameter, const char * value, BaseString&); - const char *get_connect_address(Uint32 node_id) { return inet_ntoa(m_connect_address[node_id]); } + const char *get_connect_address(Uint32 node_id); void get_connected_nodes(NodeBitmask &connected_nodes) const; SocketServer *get_socket_server() { return m_socket_server; } From 65a1d74fb149b04c9a536d3efda922202ecb2aff Mon Sep 17 00:00:00 2001 From: "reggie@linux.site" <> Date: Fri, 15 Jul 2005 03:51:55 -0600 Subject: [PATCH 35/42] added a comment referring to the bug report --- sql/mysqld.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 1434775cff3..02a775f64d1 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -657,6 +657,12 @@ static void close_connections(void) { DBUG_PRINT("quit",("Informing thread %ld that it's time to die", tmp->thread_id)); + /* + Re: bug 7403 - close_connection will be called mulitple times + bug a wholesale clean up of our network code is a very large + project. This will wake up the socket on Windows and prevent the + printing of the error message that we are force closing a connection. + */ close_connection(tmp, 0, 1); if (tmp->mysys_var) { From c9e320019b7acec906f12d28abb9b27d9db11cdd Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Fri, 15 Jul 2005 12:35:26 +0200 Subject: [PATCH 36/42] Bug #11132, reverted bug-fix, it introduces another bug. Ndbd's may get the same nodeid In 4.1 the connection to the management server _must_ stay, that is how we ensure that the nodeids are reserved correctly --- ndb/src/common/mgmcommon/ConfigRetriever.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ndb/src/common/mgmcommon/ConfigRetriever.cpp b/ndb/src/common/mgmcommon/ConfigRetriever.cpp index 648f3b4a52c..b73bcea1bcc 100644 --- a/ndb/src/common/mgmcommon/ConfigRetriever.cpp +++ b/ndb/src/common/mgmcommon/ConfigRetriever.cpp @@ -131,16 +131,14 @@ ConfigRetriever::getConfig() { } ndb_mgm_configuration * -ConfigRetriever::getConfig(NdbMgmHandle m_handle){ - +ConfigRetriever::getConfig(NdbMgmHandle m_handle) +{ ndb_mgm_configuration * conf = ndb_mgm_get_configuration(m_handle,m_version); - if(conf == 0){ + if(conf == 0) + { setError(CR_ERROR, ndb_mgm_get_latest_error_desc(m_handle)); return 0; } - - ndb_mgm_disconnect(m_handle); - return conf; } From ca75369663b2b79624b530b25aa519162caffdeb Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Fri, 15 Jul 2005 12:40:20 +0200 Subject: [PATCH 37/42] BUG#11898 ndb_mgmd not releasing resources, added "ping" on add_listener + added close of some fd's + debug prints --- ndb/src/mgmclient/CommandInterpreter.cpp | 34 +++++++-- ndb/src/mgmsrv/MgmtSrvr.hpp | 1 + ndb/src/mgmsrv/Services.cpp | 93 +++++++++++++++++++----- 3 files changed, 105 insertions(+), 23 deletions(-) diff --git a/ndb/src/mgmclient/CommandInterpreter.cpp b/ndb/src/mgmclient/CommandInterpreter.cpp index 34fe57d1fca..e1619917de5 100644 --- a/ndb/src/mgmclient/CommandInterpreter.cpp +++ b/ndb/src/mgmclient/CommandInterpreter.cpp @@ -455,11 +455,13 @@ static int do_event_thread; static void* event_thread_run(void* m) { + DBUG_ENTER("event_thread_run"); + NdbMgmHandle handle= *(NdbMgmHandle*)m; int filter[] = { 15, NDB_MGM_EVENT_CATEGORY_BACKUP, 0 }; int fd = ndb_mgm_listen_event(handle, filter); - if (fd > 0) + if (fd != NDB_INVALID_SOCKET) { do_event_thread= 1; char *tmp= 0; @@ -468,20 +470,26 @@ event_thread_run(void* m) do { if (tmp == 0) NdbSleep_MilliSleep(10); if((tmp = in.gets(buf, 1024))) - ndbout << tmp; + { + const char ping_token[]= ""; + if (memcmp(ping_token,tmp,sizeof(ping_token)-1)) + ndbout << tmp; + } } while(do_event_thread); + NDB_CLOSE_SOCKET(fd); } else { do_event_thread= -1; } - return NULL; + DBUG_RETURN(NULL); } bool CommandInterpreter::connect() { + DBUG_ENTER("CommandInterpreter::connect"); if(!m_connected) { if(!ndb_mgm_connect(m_mgmsrv, try_reconnect-1, 5, 1)) @@ -512,8 +520,19 @@ CommandInterpreter::connect() do_event_thread == 0 || do_event_thread == -1) { - printf("Warning, event thread startup failed, degraded printouts as result\n"); + DBUG_PRINT("info",("Warning, event thread startup failed, " + "degraded printouts as result, errno=%d", + errno)); + printf("Warning, event thread startup failed, " + "degraded printouts as result, errno=%d\n", errno); do_event_thread= 0; + if (m_event_thread) + { + void *res; + NdbThread_WaitFor(m_event_thread, &res); + NdbThread_Destroy(&m_event_thread); + } + ndb_mgm_disconnect(m_mgmsrv2); } } else @@ -521,6 +540,8 @@ CommandInterpreter::connect() printf("Warning, event connect failed, degraded printouts as result\n"); } m_connected= true; + DBUG_PRINT("info",("Connected to Management Server at: %s:%d", + host,port)); if (m_verbose) { printf("Connected to Management Server at: %s:%d\n", @@ -528,12 +549,13 @@ CommandInterpreter::connect() } } } - return m_connected; + DBUG_RETURN(m_connected); } bool CommandInterpreter::disconnect() { + DBUG_ENTER("CommandInterpreter::disconnect"); if (m_event_thread) { void *res; do_event_thread= 0; @@ -550,7 +572,7 @@ CommandInterpreter::disconnect() } m_connected= false; } - return true; + DBUG_RETURN(true); } //***************************************************************************** diff --git a/ndb/src/mgmsrv/MgmtSrvr.hpp b/ndb/src/mgmsrv/MgmtSrvr.hpp index 9ed5c2eb1d4..2b87bb9416a 100644 --- a/ndb/src/mgmsrv/MgmtSrvr.hpp +++ b/ndb/src/mgmsrv/MgmtSrvr.hpp @@ -60,6 +60,7 @@ public: } void add_listener(const Event_listener&); + void check_listeners(); void update_max_log_level(const LogLevel&); void update_log_level(const LogLevel&); diff --git a/ndb/src/mgmsrv/Services.cpp b/ndb/src/mgmsrv/Services.cpp index 8ba8c2fe87e..00cf6390c73 100644 --- a/ndb/src/mgmsrv/Services.cpp +++ b/ndb/src/mgmsrv/Services.cpp @@ -253,15 +253,19 @@ ParserRow commands[] = { }; MgmApiSession::MgmApiSession(class MgmtSrvr & mgm, NDB_SOCKET_TYPE sock) - : SocketServer::Session(sock), m_mgmsrv(mgm) { + : SocketServer::Session(sock), m_mgmsrv(mgm) +{ + DBUG_ENTER("MgmApiSession::MgmApiSession"); m_input = new SocketInputStream(sock); m_output = new SocketOutputStream(sock); m_parser = new Parser_t(commands, *m_input, true, true, true); m_allocated_resources= new MgmtSrvr::Allocated_resources(m_mgmsrv); + DBUG_VOID_RETURN; } MgmApiSession::~MgmApiSession() { + DBUG_ENTER("MgmApiSession::~MgmApiSession"); if (m_input) delete m_input; if (m_output) @@ -270,10 +274,19 @@ MgmApiSession::~MgmApiSession() delete m_parser; if (m_allocated_resources) delete m_allocated_resources; + if(m_socket != NDB_INVALID_SOCKET) + { + NDB_CLOSE_SOCKET(m_socket); + m_socket= NDB_INVALID_SOCKET; + } + DBUG_VOID_RETURN; } void -MgmApiSession::runSession() { +MgmApiSession::runSession() +{ + DBUG_ENTER("MgmApiSession::runSession"); + Parser_t::Context ctx; while(!m_stop) { m_parser->run(ctx, *this); @@ -301,8 +314,13 @@ MgmApiSession::runSession() { break; } } - if(m_socket >= 0) + if(m_socket != NDB_INVALID_SOCKET) + { NDB_CLOSE_SOCKET(m_socket); + m_socket= NDB_INVALID_SOCKET; + } + + DBUG_VOID_RETURN; } #ifdef MGM_GET_CONFIG_BACKWARDS_COMPAT @@ -1236,7 +1254,7 @@ Ndb_mgmd_event_service::log(int eventType, const Uint32* theData, NodeId nodeId) Uint32 threshold; LogLevel::EventCategory cat; Logger::LoggerLevel severity; - int i; + int i, n; DBUG_ENTER("Ndb_mgmd_event_service::log"); DBUG_PRINT("enter",("eventType=%d, nodeid=%d", eventType, nodeId)); @@ -1248,28 +1266,30 @@ Ndb_mgmd_event_service::log(int eventType, const Uint32* theData, NodeId nodeId) Vector copy; m_clients.lock(); - for(i = m_clients.size() - 1; i >= 0; i--){ - if(threshold <= m_clients[i].m_logLevel.getLogLevel(cat)){ - if(m_clients[i].m_socket != NDB_INVALID_SOCKET && - println_socket(m_clients[i].m_socket, - MAX_WRITE_TIMEOUT, m_text) == -1){ - copy.push_back(m_clients[i].m_socket); + for(i = m_clients.size() - 1; i >= 0; i--) + { + if(threshold <= m_clients[i].m_logLevel.getLogLevel(cat)) + { + int fd= m_clients[i].m_socket; + if(fd != NDB_INVALID_SOCKET && + println_socket(fd, MAX_WRITE_TIMEOUT, m_text) == -1) + { + copy.push_back(fd); m_clients.erase(i, false); } } } m_clients.unlock(); - for(i = 0; (unsigned)i < copy.size(); i++){ - NDB_CLOSE_SOCKET(copy[i]); - } + if ((n= (int)copy.size())) + { + for(i= 0; i < n; i++) + NDB_CLOSE_SOCKET(copy[i]); - if(copy.size()){ LogLevel tmp; tmp.clear(); m_clients.lock(); - for(i = 0; (unsigned)i < m_clients.size(); i++){ + for(i= m_clients.size() - 1; i >= 0; i--) tmp.set_max(m_clients[i].m_logLevel); - } m_clients.unlock(); update_log_level(tmp); } @@ -1297,9 +1317,48 @@ Ndb_mgmd_event_service::update_log_level(const LogLevel &tmp) } void -Ndb_mgmd_event_service::add_listener(const Event_listener& client){ +Ndb_mgmd_event_service::check_listeners() +{ + int i, n= 0; + DBUG_ENTER("Ndb_mgmd_event_service::check_listeners"); + m_clients.lock(); + for(i= m_clients.size() - 1; i >= 0; i--) + { + int fd= m_clients[i].m_socket; + DBUG_PRINT("info",("%d %d",i,fd)); + char buf[1]; + buf[0]=0; + if (fd != NDB_INVALID_SOCKET && + println_socket(fd,MAX_WRITE_TIMEOUT,"") == -1) + { + NDB_CLOSE_SOCKET(fd); + m_clients.erase(i, false); + n=1; + } + } + if (n) + { + LogLevel tmp; tmp.clear(); + for(i= m_clients.size() - 1; i >= 0; i--) + tmp.set_max(m_clients[i].m_logLevel); + update_log_level(tmp); + } + m_clients.unlock(); + DBUG_VOID_RETURN; +} + +void +Ndb_mgmd_event_service::add_listener(const Event_listener& client) +{ + DBUG_ENTER("Ndb_mgmd_event_service::add_listener"); + DBUG_PRINT("enter",("client.m_socket: %d", client.m_socket)); + + check_listeners(); + m_clients.push_back(client); update_max_log_level(client.m_logLevel); + + DBUG_VOID_RETURN; } void From eb785d70b8eb7c5792d064461167943f48c5f11f Mon Sep 17 00:00:00 2001 From: "jimw@mysql.com" <> Date: Fri, 15 Jul 2005 12:31:57 -0700 Subject: [PATCH 38/42] Fix error in formatting metadata in mysqltest. --- client/mysqltest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index b7f4ceb9c20..b23b77e9bca 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -3141,10 +3141,10 @@ static void run_query_display_metadata(MYSQL_FIELD *field, uint num_fields, int10_to_str((int) field->type, buff, 10); dynstr_append(ds, buff); dynstr_append_mem(ds, "\t", 1); - int10_to_str((int) field->length, buff, 10); + longlong10_to_str((unsigned int) field->length, buff, 10); dynstr_append(ds, buff); dynstr_append_mem(ds, "\t", 1); - int10_to_str((int) field->max_length, buff, 10); + longlong10_to_str((unsigned int) field->max_length, buff, 10); dynstr_append(ds, buff); dynstr_append_mem(ds, "\t", 1); dynstr_append_mem(ds, (char*) (IS_NOT_NULL(field->flags) ? From 0298bc347aad0ad0ed0083781d84d412a921459d Mon Sep 17 00:00:00 2001 From: "evgen@moonbone.local" <> Date: Sat, 16 Jul 2005 03:29:12 +0400 Subject: [PATCH 39/42] Fix bug#11482 4.1.12 produces different resultset for a complex query than in previous 4.1.x Wrongly applied optimization were adding NOT NULL constraint which results in rejecting valid rows and reduced result set. The problem was that add_notnull_conds() while checking subquery were adding NOT NULL constraint to left joined table, to which, normally, optimization don't have to be applied. --- mysql-test/r/select.result | 11 +++++++++++ mysql-test/t/select.test | 11 +++++++++++ sql/sql_select.cc | 20 +++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 8160c5a2f3d..5c0616f9e54 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2559,3 +2559,14 @@ WHERE COUNT(*) 4 drop table t1,t2,t3; +create table t1 (f1 int); +insert into t1 values (1),(NULL); +create table t2 (f2 int, f3 int, f4 int); +create index idx1 on t2 (f4); +insert into t2 values (1,2,3),(2,4,6); +select A.f2 from t1 left join t2 A on A.f2 = f1 where A.f3=(select min(f3) +from t2 C where A.f4 = C.f4) or A.f3 IS NULL; +f2 +1 +NULL +drop table t1,t2; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 37e4324152b..2e261d0611f 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2116,3 +2116,14 @@ WHERE drop table t1,t2,t3; +# +# Bug #11482 4.1.12 produces different resultset for a complex query +# than in previous 4.1.x +create table t1 (f1 int); +insert into t1 values (1),(NULL); +create table t2 (f2 int, f3 int, f4 int); +create index idx1 on t2 (f4); +insert into t2 values (1,2,3),(2,4,6); +select A.f2 from t1 left join t2 A on A.f2 = f1 where A.f3=(select min(f3) +from t2 C where A.f4 = C.f4) or A.f3 IS NULL; +drop table t1,t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 75fc189b21f..43cf649685e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3508,7 +3508,23 @@ inline void add_cond_and_fix(Item **e1, Item *e2) (where othertbl is a non-const table and othertbl.field may be NULL) and add them to conditions on correspoding tables (othertbl in this example). - + + Exception from that is the case when referred_tab->join != join. + I.e. don't add NOT NULL constraints from any embedded subquery. + Consider this query: + SELECT A.f2 FROM t1 LEFT JOIN t2 A ON A.f2 = f1 + WHERE A.f3=(SELECT MIN(f3) FROM t2 C WHERE A.f4 = C.f4) OR A.f3 IS NULL; + Here condition A.f3 IS NOT NULL is going to be added to the WHERE + condition of the embedding query. + Another example: + SELECT * FROM t10, t11 WHERE (t10.a < 10 OR t10.a IS NULL) + AND t11.b <=> t10.b AND (t11.a = (SELECT MAX(a) FROM t12 + WHERE t12.b = t10.a )); + Here condition t10.a IS NOT NULL is going to be added. + In both cases addition of NOT NULL condition will erroneously reject + some rows of the result set. + referred_tab->join != join constraint would disallow such additions. + This optimization doesn't affect the choices that ref, range, or join optimizer make. This was intentional because this was added after 4.1 was GA. @@ -3539,6 +3555,8 @@ static void add_not_null_conds(JOIN *join) DBUG_ASSERT(item->type() == Item::FIELD_ITEM); Item_field *not_null_item= (Item_field*)item; JOIN_TAB *referred_tab= not_null_item->field->table->reginfo.join_tab; + if (referred_tab->join != join) + continue; Item *notnull; if (!(notnull= new Item_func_isnotnull(not_null_item))) DBUG_VOID_RETURN; From e08caeeee2b6250d4e4adfed34c99de08eaacecc Mon Sep 17 00:00:00 2001 From: "konstantin@mysql.com" <> Date: Sat, 16 Jul 2005 03:29:13 +0400 Subject: [PATCH 40/42] A fix and a test case for Bug#9359 "Prepared statements take snapshot of system vars at PREPARE time": implement a special Item to handle system variables. This item substitutes itself with a basic constant containing variable value at fix_fields. --- mysql-test/r/ps.result | 25 ++++++++++++++++ mysql-test/t/ps.test | 18 ++++++++++- sql/item_func.cc | 68 +++++++++++++++++++++++------------------- sql/item_func.h | 23 ++++++++++++++ sql/mysql_priv.h | 10 ++++--- sql/set_var.cc | 14 ++------- sql/set_var.h | 5 ---- 7 files changed, 112 insertions(+), 51 deletions(-) diff --git a/mysql-test/r/ps.result b/mysql-test/r/ps.result index 6cd32cbe8d0..c17015df757 100644 --- a/mysql-test/r/ps.result +++ b/mysql-test/r/ps.result @@ -676,3 +676,28 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp select ? from t1; ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? from t1' at line 1 drop table t1; +prepare stmt from "select @@time_zone"; +execute stmt; +@@time_zone +SYSTEM +set @@time_zone:='Japan'; +execute stmt; +@@time_zone +Japan +prepare stmt from "select @@tx_isolation"; +execute stmt; +@@tx_isolation +REPEATABLE-READ +set transaction isolation level read committed; +execute stmt; +@@tx_isolation +READ-COMMITTED +set transaction isolation level serializable; +execute stmt; +@@tx_isolation +SERIALIZABLE +set @@tx_isolation=default; +execute stmt; +@@tx_isolation +REPEATABLE-READ +deallocate prepare stmt; diff --git a/mysql-test/t/ps.test b/mysql-test/t/ps.test index beae95d462a..a4911115c9f 100644 --- a/mysql-test/t/ps.test +++ b/mysql-test/t/ps.test @@ -702,4 +702,20 @@ select ??; select ? from t1; --enable_ps_protocol drop table t1; -# +# +# Bug#9359 "Prepared statements take snapshot of system vars at PREPARE +# time" +# +prepare stmt from "select @@time_zone"; +execute stmt; +set @@time_zone:='Japan'; +execute stmt; +prepare stmt from "select @@tx_isolation"; +execute stmt; +set transaction isolation level read committed; +execute stmt; +set transaction isolation level serializable; +execute stmt; +set @@tx_isolation=default; +execute stmt; +deallocate prepare stmt; diff --git a/sql/item_func.cc b/sql/item_func.cc index 0128209cb22..c8f1d209d26 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3031,6 +3031,36 @@ bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const } +Item_func_get_system_var:: +Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg, + LEX_STRING *component_arg, const char *name_arg, + size_t name_len_arg) + :var(var_arg), var_type(var_type_arg), component(*component_arg) +{ + /* set_name() will allocate the name */ + set_name(name_arg, name_len_arg, system_charset_info); +} + + +bool +Item_func_get_system_var::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref) +{ + Item *item= var->item(thd, var_type, &component); + DBUG_ENTER("Item_func_get_system_var::fix_fields"); + /* + Evaluate the system variable and substitute the result (a basic constant) + instead of this item. If the variable can not be evaluated, + the error is reported in sys_var::item(). + */ + if (item == 0) + DBUG_RETURN(1); // Impossible + item->set_name(name, 0, system_charset_info); // don't allocate a new name + thd->change_item_tree(ref, item); + + DBUG_RETURN(0); +} + + longlong Item_func_inet_aton::val_int() { DBUG_ASSERT(fixed == 1); @@ -3375,22 +3405,21 @@ longlong Item_func_bit_xor::val_int() 0 error # constant item */ - + Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, LEX_STRING component) { + sys_var *var; + char buff[MAX_SYS_VAR_LENGTH*2+4+8], *pos; + LEX_STRING *base_name, *component_name; + if (component.str == 0 && !my_strcasecmp(system_charset_info, name.str, "VERSION")) return new Item_string("@@VERSION", server_version, (uint) strlen(server_version), system_charset_info, DERIVATION_SYSCONST); - Item *item; - sys_var *var; - char buff[MAX_SYS_VAR_LENGTH*2+4+8], *pos; - LEX_STRING *base_name, *component_name; - if (component.str) { base_name= &component; @@ -3412,9 +3441,8 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, return 0; } } - if (!(item=var->item(thd, var_type, component_name))) - return 0; // Impossible thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT); + buff[0]='@'; buff[1]='@'; pos=buff+2; @@ -3435,28 +3463,8 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, memcpy(pos, base_name->str, base_name->length); pos+= base_name->length; - // set_name() will allocate the name - item->set_name(buff,(uint) (pos-buff), system_charset_info); - return item; -} - - -Item *get_system_var(THD *thd, enum_var_type var_type, const char *var_name, - uint length, const char *item_name) -{ - Item *item; - sys_var *var; - LEX_STRING null_lex_string; - - null_lex_string.str= 0; - - var= find_sys_var(var_name, length); - DBUG_ASSERT(var != 0); - if (!(item=var->item(thd, var_type, &null_lex_string))) - return 0; // Impossible - thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT); - item->set_name(item_name, 0, system_charset_info); // Will use original name - return item; + return new Item_func_get_system_var(var, var_type, component_name, + buff, pos - buff); } diff --git a/sql/item_func.h b/sql/item_func.h index 6b6e5d4b8ec..5e36f9863bb 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -988,6 +988,29 @@ public: }; +/* A system variable */ + +class Item_func_get_system_var :public Item_func +{ + sys_var *var; + enum_var_type var_type; + LEX_STRING component; +public: + Item_func_get_system_var(sys_var *var_arg, enum_var_type var_type_arg, + LEX_STRING *component_arg, const char *name_arg, + size_t name_len_arg); + bool fix_fields(THD *thd, TABLE_LIST *tables, Item **ref); + /* + Stubs for pure virtual methods. Should never be called: this + item is always substituted with a constant in fix_fields(). + */ + double val() { DBUG_ASSERT(0); return 0.0; } + longlong val_int() { DBUG_ASSERT(0); return 0; } + String* val_str(String*) { DBUG_ASSERT(0); return 0; } + void fix_length_and_dec() { DBUG_ASSERT(0); } +}; + + class Item_func_inet_aton : public Item_int_func { public: diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 722b76796b2..351f12acad2 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -358,6 +358,11 @@ inline THD *_current_thd(void) #include "protocol.h" #include "sql_udf.h" class user_var_entry; +enum enum_var_type +{ + OPT_DEFAULT, OPT_SESSION, OPT_GLOBAL +}; +class sys_var; #include "item.h" typedef Comp_creator* (*chooser_compare_func_creator)(bool invert); /* sql_parse.cc */ @@ -1119,12 +1124,9 @@ extern bool sql_cache_init(); extern void sql_cache_free(); extern int sql_cache_hit(THD *thd, char *inBuf, uint length); -/* item.cc */ +/* item_func.cc */ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, LEX_STRING component); -Item *get_system_var(THD *thd, enum_var_type var_type, const char *var_name, - uint length, const char *item_name); -/* item_func.cc */ int get_var_with_binlog(THD *thd, LEX_STRING &name, user_var_entry **out_entry); /* log.cc */ diff --git a/sql/set_var.cc b/sql/set_var.cc index b0fa61a12bc..f7700d18607 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -1551,15 +1551,7 @@ err: /* Return an Item for a variable. Used with @@[global.]variable_name - If type is not given, return local value if exists, else global - - We have to use netprintf() instead of my_error() here as this is - called on the parsing stage. - - TODO: - With prepared statements/stored procedures this has to be fixed - to create an item that gets the current value at fix_fields() stage. */ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) @@ -1568,8 +1560,8 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) { if (var_type != OPT_DEFAULT) { - net_printf(thd, ER_INCORRECT_GLOBAL_LOCAL_VAR, - name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); + my_error(ER_INCORRECT_GLOBAL_LOCAL_VAR, MYF(0), + name, var_type == OPT_GLOBAL ? "SESSION" : "GLOBAL"); return 0; } /* As there was no local variable, return the global value */ @@ -1613,7 +1605,7 @@ Item *sys_var::item(THD *thd, enum_var_type var_type, LEX_STRING *base) return tmp; } default: - net_printf(thd, ER_VAR_CANT_BE_READ, name); + my_error(ER_VAR_CANT_BE_READ, MYF(0), name); } return 0; } diff --git a/sql/set_var.h b/sql/set_var.h index d452ba03367..2ac4fc2c260 100644 --- a/sql/set_var.h +++ b/sql/set_var.h @@ -30,11 +30,6 @@ class set_var; typedef struct system_variables SV; extern TYPELIB bool_typelib, delay_key_write_typelib, sql_mode_typelib; -enum enum_var_type -{ - OPT_DEFAULT, OPT_SESSION, OPT_GLOBAL -}; - typedef int (*sys_check_func)(THD *, set_var *); typedef bool (*sys_update_func)(THD *, set_var *); typedef void (*sys_after_update_func)(THD *,enum_var_type); From 81d93df1ae8a1aff17345b18188ce0ddecdb9e19 Mon Sep 17 00:00:00 2001 From: "evgen@moonbone.local" <> Date: Sat, 16 Jul 2005 05:31:16 +0400 Subject: [PATCH 41/42] Fix bug#11868 NOT NULL ref optimization in subquery used in update must be disabled if ref is built with a key from the updated table Problem was in add_not_null_conds() optimization function. It contains following code: JOIN_TAB *referred_tab= not_null_item->field->table->reginfo.join_tab; ... add_cond_and_fix(&referred_tab->select_cond, notnull); For UPDATE described in bug report referred_tab is 0 and dereferencing it crashes the server. --- mysql-test/r/update.result | 11 +++++++++++ mysql-test/t/update.test | 13 +++++++++++++ sql/sql_select.cc | 7 ++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/update.result b/mysql-test/r/update.result index d83952e118b..e35d4e29fe4 100644 --- a/mysql-test/r/update.result +++ b/mysql-test/r/update.result @@ -240,3 +240,14 @@ update t1, t2 set t1.a = t2.a where t2.b = t1.b; show warnings; Level Code Message drop table t1, t2; +create table t1(f1 int, f2 int); +create table t2(f3 int, f4 int); +create index idx on t2(f3); +insert into t1 values(1,0),(2,0); +insert into t2 values(1,1),(2,2); +UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1); +select * from t1; +f1 f2 +1 1 +2 2 +drop table t1,t2; diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test index 6a90fb95760..41f7d37e6d0 100644 --- a/mysql-test/t/update.test +++ b/mysql-test/t/update.test @@ -201,3 +201,16 @@ analyze table t1,t2; update t1, t2 set t1.a = t2.a where t2.b = t1.b; show warnings; drop table t1, t2; + +# +# Bug #11868 Update with subquery with ref built with a key from the updated +# table crashes server +# +create table t1(f1 int, f2 int); +create table t2(f3 int, f4 int); +create index idx on t2(f3); +insert into t1 values(1,0),(2,0); +insert into t2 values(1,1),(2,2); +UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1); +select * from t1; +drop table t1,t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 43cf649685e..e56828c3244 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -3555,7 +3555,12 @@ static void add_not_null_conds(JOIN *join) DBUG_ASSERT(item->type() == Item::FIELD_ITEM); Item_field *not_null_item= (Item_field*)item; JOIN_TAB *referred_tab= not_null_item->field->table->reginfo.join_tab; - if (referred_tab->join != join) + /* + For UPDATE queries such as: + UPDATE t1 SET t1.f2=(SELECT MAX(t2.f4) FROM t2 WHERE t2.f3=t1.f1); + not_null_item is the t1.f1, but it's referred_tab is 0. + */ + if (!referred_tab || referred_tab->join != join) continue; Item *notnull; if (!(notnull= new Item_func_isnotnull(not_null_item))) From ff0c7f22cfab033022d4090c7cb324d4b4ace619 Mon Sep 17 00:00:00 2001 From: "timour@mysql.com" <> Date: Sat, 16 Jul 2005 10:30:25 +0300 Subject: [PATCH 42/42] Added test for Bug #11521 "Negative integer keys incorrectly substituted for 0 during range analysis." The problem is that the range optimizer incorrectly replaces any negative constant with '0' for all types except BIGINT because the method save_in_field() casts negative integers to non-negative. This causes incorrect query results where (0 = any_negative_number). The problem caused by this bug is fixed by the patch for BUG#11185. That patch constitutes an optimization due to which the problem code is never called with negative constants. This patch adds a test so we are sure that the problem does not reappear. --- mysql-test/r/select.result | 12 ++++++++++++ mysql-test/t/select.test | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/mysql-test/r/select.result b/mysql-test/r/select.result index 5c0616f9e54..6c9ec9d8297 100644 --- a/mysql-test/r/select.result +++ b/mysql-test/r/select.result @@ -2570,3 +2570,15 @@ f2 1 NULL drop table t1,t2; +create table t2 (a tinyint unsigned); +create index t2i on t2(a); +insert into t2 values (0), (254), (255); +explain select * from t2 where a > -1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t2 index t2i t2i 2 NULL 3 Using where; Using index +select * from t2 where a > -1; +a +0 +254 +255 +drop table t2; diff --git a/mysql-test/t/select.test b/mysql-test/t/select.test index 2e261d0611f..caa9e332e57 100644 --- a/mysql-test/t/select.test +++ b/mysql-test/t/select.test @@ -2127,3 +2127,14 @@ insert into t2 values (1,2,3),(2,4,6); select A.f2 from t1 left join t2 A on A.f2 = f1 where A.f3=(select min(f3) from t2 C where A.f4 = C.f4) or A.f3 IS NULL; drop table t1,t2; + +# +# Bug #11521 Negative integer keys incorrectly substituted for 0 during +# range analysis. + +create table t2 (a tinyint unsigned); +create index t2i on t2(a); +insert into t2 values (0), (254), (255); +explain select * from t2 where a > -1; +select * from t2 where a > -1; +drop table t2;