From 575fea4a981a7fa0ff8a3b8d0978be5928afc8e9 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 27 Jul 2007 16:26:26 -0400 Subject: [PATCH 1/4] Bug #29419 "Specifying a join_buffer > 4GB on 64 bit machines not possible." Use size_t instead of uint when calculating join buffer size, because uint can be overflown on 64-bit platforms and join_buffer_size > 4 GB. The test case for this bug is a part of the test suite for bug #5731. sql/sql_select.cc: Use size_t instead of uint when calculating join buffer size, because uint can be overflown on 64-bit platforms and join_buffer_size > 4G. --- sql/sql_select.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index d8bf8466f58..89bdd22a3de 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13014,7 +13014,8 @@ static int join_init_cache(THD *thd,JOIN_TAB *tables,uint table_count) { reg1 uint i; - uint length,blobs,size; + uint length, blobs; + size_t size; CACHE_FIELD *copy,**blob_ptr; JOIN_CACHE *cache; JOIN_TAB *join_tab; @@ -13130,7 +13131,7 @@ store_record_in_cache(JOIN_CACHE *cache) length=cache->length; if (cache->blobs) length+=used_blob_length(cache->blob_ptr); - if ((last_record=(length+cache->length > (uint) (cache->end - pos)))) + if ((last_record= (length + cache->length > (size_t) (cache->end - pos)))) cache->ptr_record=cache->records; /* @@ -13176,7 +13177,7 @@ store_record_in_cache(JOIN_CACHE *cache) } } cache->pos=pos; - return last_record || (uint) (cache->end -pos) < cache->length; + return last_record || (size_t) (cache->end - pos) < cache->length; } From 0a28cac0b627a0a4990c8cb942ade39261fb1007 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 5 Sep 2007 15:06:10 -0400 Subject: [PATCH 2/4] Bug #29804 UDF parameters don't contain correct string length Previously, UDF *_init functions were passed constant strings with erroneous lengths. The length came from the containing variable's size, not the length of the value itself. Now the *_init functions get the constant as a null terminated string with the correct length supplied too. mysql-test/r/udf.result: Test case to check constants passed UDFs. mysql-test/t/udf.test: Test case to check constants passed UDFs. sql/item_func.cc: UDF _init functions are now passed the length of the constants, rather than the max length of the var containing the constant. sql/udf_example.c: Added check_const_len functions. The check_const_len_init functions checks that the lengths of constants are correctly passed. sql/udf_example.def: Add new example functions to windows dll export list. --- mysql-test/r/udf.result | 24 ++++++++++++++++++++++++ mysql-test/t/udf.test | 36 ++++++++++++++++++++++++++++++++++++ sql/item_func.cc | 3 ++- sql/udf_example.c | 35 +++++++++++++++++++++++++++++++++++ sql/udf_example.def | 2 ++ 5 files changed, 99 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/udf.result b/mysql-test/r/udf.result index 2e9cf217ed6..885f5f8078e 100644 --- a/mysql-test/r/udf.result +++ b/mysql-test/r/udf.result @@ -296,4 +296,28 @@ Qcache_queries_in_cache 0 drop table t1; drop function metaphon; set GLOBAL query_cache_size=default; +CREATE TABLE const_len_bug ( +str_const varchar(4000), +result1 varchar(4000), +result2 varchar(4000) +); +CREATE TRIGGER check_const_len_trigger BEFORE INSERT ON const_len_bug FOR EACH ROW BEGIN +set NEW.str_const = 'bar'; +set NEW.result2 = check_const_len(NEW.str_const); +END | +CREATE PROCEDURE check_const_len_sp (IN str_const VARCHAR(4000)) +BEGIN +DECLARE result VARCHAR(4000); +SET result = check_const_len(str_const); +insert into const_len_bug values(str_const, result, ""); +END | +CREATE FUNCTION check_const_len RETURNS string SONAME "UDF_EXAMPLE_LIB"; +CALL check_const_len_sp("foo"); +SELECT * from const_len_bug; +str_const result1 result2 +bar Correct length Correct length +DROP FUNCTION check_const_len; +DROP PROCEDURE check_const_len_sp; +DROP TRIGGER check_const_len_trigger; +DROP TABLE const_len_bug; End of 5.0 tests. diff --git a/mysql-test/t/udf.test b/mysql-test/t/udf.test index 75af1f4be4b..beb18206a2e 100644 --- a/mysql-test/t/udf.test +++ b/mysql-test/t/udf.test @@ -312,4 +312,40 @@ drop function metaphon; set GLOBAL query_cache_size=default; +# +# Bug #29804 UDF parameters don't contain correct string length +# + +CREATE TABLE const_len_bug ( + str_const varchar(4000), + result1 varchar(4000), + result2 varchar(4000) +); + +DELIMITER |; +CREATE TRIGGER check_const_len_trigger BEFORE INSERT ON const_len_bug FOR EACH ROW BEGIN + set NEW.str_const = 'bar'; + set NEW.result2 = check_const_len(NEW.str_const); +END | + +CREATE PROCEDURE check_const_len_sp (IN str_const VARCHAR(4000)) +BEGIN +DECLARE result VARCHAR(4000); +SET result = check_const_len(str_const); +insert into const_len_bug values(str_const, result, ""); +END | +DELIMITER ;| + +--replace_result $UDF_EXAMPLE_LIB UDF_EXAMPLE_LIB +eval CREATE FUNCTION check_const_len RETURNS string SONAME "$UDF_EXAMPLE_LIB"; + +CALL check_const_len_sp("foo"); + +SELECT * from const_len_bug; + +DROP FUNCTION check_const_len; +DROP PROCEDURE check_const_len_sp; +DROP TRIGGER check_const_len_trigger; +DROP TABLE const_len_bug; + --echo End of 5.0 tests. diff --git a/sql/item_func.cc b/sql/item_func.cc index c70cfa1ce2a..21579763635 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2924,7 +2924,8 @@ udf_handler::fix_fields(THD *thd, Item_result_field *func, String *res= arguments[i]->val_str(&buffers[i]); if (arguments[i]->null_value) continue; - f_args.args[i]= (char*) res->ptr(); + f_args.args[i]= (char*) res->c_ptr(); + f_args.lengths[i]= res->length(); break; } case INT_RESULT: diff --git a/sql/udf_example.c b/sql/udf_example.c index 0f28c2a14b0..df3a69755ad 100644 --- a/sql/udf_example.c +++ b/sql/udf_example.c @@ -1106,4 +1106,39 @@ char * is_const(UDF_INIT *initid, UDF_ARGS *args __attribute__((unused)), } + +my_bool check_const_len_init(UDF_INIT *initid, UDF_ARGS *args, char *message) +{ + if (args->arg_count != 1) + { + strmov(message, "CHECK_CONST_LEN accepts only one argument"); + return 1; + } + if (args->args[0] == 0) + { + initid->ptr= (char*)"Not constant"; + } + else if(strlen(args->args[0]) == args->lengths[0]) + { + initid->ptr= (char*)"Correct length"; + } + else + { + initid->ptr= (char*)"Wrong length"; + } + initid->max_length = 100; + return 0; +} + +char * check_const_len(UDF_INIT *initid, UDF_ARGS *args __attribute__((unused)), + char *result, unsigned long *length, + char *is_null, char *error __attribute__((unused))) +{ + strmov(result, initid->ptr); + *length= strlen(result); + *is_null= 0; + return result; +} + + #endif /* HAVE_DLOPEN */ diff --git a/sql/udf_example.def b/sql/udf_example.def index 7a87147d7b6..3d569941cc8 100644 --- a/sql/udf_example.def +++ b/sql/udf_example.def @@ -23,3 +23,5 @@ EXPORTS avgcost is_const is_const_init + check_const_len + check_const_len_init From 885efe4c7394f42e11a7fe430415dce3d08dc029 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Sep 2007 17:10:45 +0200 Subject: [PATCH 3/4] Bug#28359 Intermitted lost connection at 'reading authorization packet' errors - Increase default 'connect_timeout' value to 10 seconds sql/mysql_priv.h: Increase the default connect_timeout value to 10 seconds --- sql/mysql_priv.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 44eb5590a28..1d944f196ed 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -245,8 +245,13 @@ MY_LOCALE *my_locale_by_number(uint number); #define PRECISION_FOR_DOUBLE 53 #define PRECISION_FOR_FLOAT 24 +/* + Default time to wait before aborting a new client connection + that does not respond to "initial server greeting" timely +*/ +#define CONNECT_TIMEOUT 10 + /* The following can also be changed from the command line */ -#define CONNECT_TIMEOUT 5 // Do not wait long for connect #define DEFAULT_CONCURRENCY 10 #define DELAYED_LIMIT 100 /* pause after xxx inserts */ #define DELAYED_QUEUE_SIZE 1000 From 1c078caa82e254df678dfd5b2cd6152d02e59ee5 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 21 Sep 2007 17:52:02 +0200 Subject: [PATCH 4/4] - Increase default connect_timeout to avoid intermittent disconnects when test servers are put under load --- mysql-test/mysql-test-run.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 06447b9e69d..ad507440bb7 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -3708,6 +3708,11 @@ sub mysqld_arguments ($$$$) { mtr_add_arg($args, "%s--language=%s", $prefix, $path_language); mtr_add_arg($args, "%s--tmpdir=$opt_tmpdir", $prefix); + # Increase default connect_timeout to avoid intermittent + # disconnects when test servers are put under load + # see BUG#28359 + mtr_add_arg($args, "%s--connect-timeout=60", $prefix); + if ( $opt_valgrind_mysqld ) { mtr_add_arg($args, "%s--skip-safemalloc", $prefix);