From 932c7a316c6ce72d48cac239c6256bdaa00da867 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Thu, 4 Jun 2009 12:52:40 +0300 Subject: [PATCH 1/6] Bug #36995: valgrind error in remove_const during subquery executions When copying the Item class one must copy its attributes as well. --- mysql-test/r/innodb_mysql.result | 12 ++++++++++++ mysql-test/t/innodb_mysql.test | 10 ++++++++++ sql/item.cc | 3 +++ 3 files changed, 25 insertions(+) diff --git a/mysql-test/r/innodb_mysql.result b/mysql-test/r/innodb_mysql.result index b6fc58be4c2..a51dc978f3e 100644 --- a/mysql-test/r/innodb_mysql.result +++ b/mysql-test/r/innodb_mysql.result @@ -1303,4 +1303,16 @@ t1 CREATE TABLE `t1` ( CONSTRAINT `f2_ref` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 DROP TABLE t1; +# +# Bug #36995: valgrind error in remove_const during subquery executions +# +create table t1 (a bit(1) not null,b int) engine=myisam; +create table t2 (c int) engine=innodb; +explain +select b from t1 where a not in (select b from t1,t2 group by a) group by a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +2 DEPENDENT SUBQUERY t1 system NULL NULL NULL NULL 0 const row not found +2 DEPENDENT SUBQUERY t2 ALL NULL NULL NULL NULL 1 +DROP TABLE t1,t2; End of 5.0 tests diff --git a/mysql-test/t/innodb_mysql.test b/mysql-test/t/innodb_mysql.test index 05be75fc368..3c81a27e9ac 100644 --- a/mysql-test/t/innodb_mysql.test +++ b/mysql-test/t/innodb_mysql.test @@ -1063,4 +1063,14 @@ CREATE TABLE t1 (f1 INTEGER PRIMARY KEY COMMENT 'My ID#', f2 INTEGER DEFAULT NUL SHOW CREATE TABLE t1; DROP TABLE t1; +--echo # +--echo # Bug #36995: valgrind error in remove_const during subquery executions +--echo # + +create table t1 (a bit(1) not null,b int) engine=myisam; +create table t2 (c int) engine=innodb; +explain +select b from t1 where a not in (select b from t1,t2 group by a) group by a; +DROP TABLE t1,t2; + --echo End of 5.0 tests diff --git a/sql/item.cc b/sql/item.cc index 7c4e86d756f..7a81e48fcee 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -409,6 +409,7 @@ Item::Item(THD *thd, Item *item): name(item->name), orig_name(item->orig_name), max_length(item->max_length), + name_length(item->name_length), marker(item->marker), decimals(item->decimals), maybe_null(item->maybe_null), @@ -416,7 +417,9 @@ Item::Item(THD *thd, Item *item): unsigned_flag(item->unsigned_flag), with_sum_func(item->with_sum_func), fixed(item->fixed), + is_autogenerated_name(item->is_autogenerated_name), collation(item->collation), + with_subselect(item->with_subselect), cmp_context(item->cmp_context) { next= thd->free_list; // Put in free list From 5068840bd85e57862bbc4113b098624c535dc4f5 Mon Sep 17 00:00:00 2001 From: "Bernt M. Johnsen" Date: Thu, 4 Jun 2009 13:38:53 +0200 Subject: [PATCH 2/6] Bug#15866 main.sp-fib split from main.sp --- mysql-test/r/sp-fib.result | 46 +++++++++++++++++++++++++++++ mysql-test/r/sp.result | 46 ----------------------------- mysql-test/t/sp-fib.test | 60 ++++++++++++++++++++++++++++++++++++++ mysql-test/t/sp.test | 55 ---------------------------------- 4 files changed, 106 insertions(+), 101 deletions(-) create mode 100644 mysql-test/r/sp-fib.result create mode 100644 mysql-test/t/sp-fib.test diff --git a/mysql-test/r/sp-fib.result b/mysql-test/r/sp-fib.result new file mode 100644 index 00000000000..c51aa7d7ad1 --- /dev/null +++ b/mysql-test/r/sp-fib.result @@ -0,0 +1,46 @@ +drop table if exists t3; +create table t3 ( f bigint unsigned not null ); +drop procedure if exists fib; +create procedure fib(n int unsigned) +begin +if n > 1 then +begin +declare x, y bigint unsigned; +declare c cursor for select f from t3 order by f desc limit 2; +open c; +fetch c into y; +fetch c into x; +close c; +insert into t3 values (x+y); +call fib(n-1); +end; +end if; +end| +set @@max_sp_recursion_depth= 20| +insert into t3 values (0), (1)| +call fib(3)| +select * from t3 order by f asc| +f +0 +1 +1 +2 +delete from t3| +insert into t3 values (0), (1)| +call fib(10)| +select * from t3 order by f asc| +f +0 +1 +1 +2 +3 +5 +8 +13 +21 +34 +55 +drop table t3| +drop procedure fib| +set @@max_sp_recursion_depth= 0| diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 236fa3d8681..f66d31a3295 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -1337,52 +1337,6 @@ drop procedure opp| drop procedure ip| show procedure status like '%p%'| Db Name Type Definer Modified Created Security_type Comment -drop table if exists t3| -create table t3 ( f bigint unsigned not null )| -drop procedure if exists fib| -create procedure fib(n int unsigned) -begin -if n > 1 then -begin -declare x, y bigint unsigned; -declare c cursor for select f from t3 order by f desc limit 2; -open c; -fetch c into y; -fetch c into x; -close c; -insert into t3 values (x+y); -call fib(n-1); -end; -end if; -end| -set @@max_sp_recursion_depth= 20| -insert into t3 values (0), (1)| -call fib(3)| -select * from t3 order by f asc| -f -0 -1 -1 -2 -delete from t3| -insert into t3 values (0), (1)| -call fib(10)| -select * from t3 order by f asc| -f -0 -1 -1 -2 -3 -5 -8 -13 -21 -34 -55 -drop table t3| -drop procedure fib| -set @@max_sp_recursion_depth= 0| drop procedure if exists bar| create procedure bar(x char(16), y int) comment "111111111111" sql security invoker diff --git a/mysql-test/t/sp-fib.test b/mysql-test/t/sp-fib.test new file mode 100644 index 00000000000..e6682395a2c --- /dev/null +++ b/mysql-test/t/sp-fib.test @@ -0,0 +1,60 @@ +# Fibonacci, for recursion test. (Yet Another Numerical series :) +# Split from main.sp due to problems reported in Bug#15866 + +--disable_warnings +drop table if exists t3; +--enable_warnings +create table t3 ( f bigint unsigned not null ); + +# We deliberately do it the awkward way, fetching the last two +# values from the table, in order to exercise various statements +# and table accesses at each turn. +--disable_warnings +drop procedure if exists fib; +--enable_warnings + +# Now for multiple statements... +delimiter |; + +create procedure fib(n int unsigned) +begin + if n > 1 then + begin + declare x, y bigint unsigned; + declare c cursor for select f from t3 order by f desc limit 2; + + open c; + fetch c into y; + fetch c into x; + close c; + insert into t3 values (x+y); + call fib(n-1); + end; + end if; +end| + +# Enable recursion +set @@max_sp_recursion_depth= 20| + +# Minimum test: recursion of 3 levels + +insert into t3 values (0), (1)| + +call fib(3)| + +select * from t3 order by f asc| + +delete from t3| + +# The original test, 20 levels, ran into memory limits on some machines +# and builds. Try 10 instead... + +insert into t3 values (0), (1)| + +call fib(10)| + +select * from t3 order by f asc| +drop table t3| +drop procedure fib| +set @@max_sp_recursion_depth= 0| + diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index e3d3298cc50..a785aa2334f 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -1560,61 +1560,6 @@ drop procedure ip| show procedure status like '%p%'| -# Fibonacci, for recursion test. (Yet Another Numerical series :) -# ---disable_warnings -drop table if exists t3| ---enable_warnings -create table t3 ( f bigint unsigned not null )| - -# We deliberately do it the awkward way, fetching the last two -# values from the table, in order to exercise various statements -# and table accesses at each turn. ---disable_warnings -drop procedure if exists fib| ---enable_warnings -create procedure fib(n int unsigned) -begin - if n > 1 then - begin - declare x, y bigint unsigned; - declare c cursor for select f from t3 order by f desc limit 2; - - open c; - fetch c into y; - fetch c into x; - close c; - insert into t3 values (x+y); - call fib(n-1); - end; - end if; -end| - -# Enable recursion -set @@max_sp_recursion_depth= 20| - -# Minimum test: recursion of 3 levels - -insert into t3 values (0), (1)| - -call fib(3)| - -select * from t3 order by f asc| - -delete from t3| - -# The original test, 20 levels, ran into memory limits on some machines -# and builds. Try 10 instead... - -insert into t3 values (0), (1)| - -call fib(10)| - -select * from t3 order by f asc| -drop table t3| -drop procedure fib| -set @@max_sp_recursion_depth= 0| - # # Comment & suid # From 5ec61b304c1c7ed03e5df9257f0bc5cb01f6bc36 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 15:05:26 +0300 Subject: [PATCH 3/6] Bug #45286: compilation warnings on mysql-5.0-bugteam on MacOSX Fixed the 5.0-bugteam MacOSX warnings. --- client/mysqldump.c | 4 ++-- cmd-line-utils/readline/bind.c | 4 +++- cmd-line-utils/readline/display.c | 2 +- dbug/user.r | 1 + strings/ctype.c | 5 ++++- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index a9d2788de05..2fd69a3d8c6 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -3122,7 +3122,7 @@ static my_bool dump_all_views_in_db(char *database) for (numrows= 0 ; (table= getTableName(1)); ) { char *end= strmov(afterdot, table); - if (include_table((uchar*) hash_key,end - hash_key)) + if (include_table((byte*) hash_key,end - hash_key)) { numrows++; dynstr_append_checked(&query, quote_name(table, table_buff, 1)); @@ -3143,7 +3143,7 @@ static my_bool dump_all_views_in_db(char *database) while ((table= getTableName(0))) { char *end= strmov(afterdot, table); - if (include_table((uchar*) hash_key, end - hash_key)) + if (include_table((byte*) hash_key, end - hash_key)) get_view_structure(table, database); } if (opt_xml) diff --git a/cmd-line-utils/readline/bind.c b/cmd-line-utils/readline/bind.c index baed1dfad49..9d0a803cc6c 100644 --- a/cmd-line-utils/readline/bind.c +++ b/cmd-line-utils/readline/bind.c @@ -699,8 +699,10 @@ rl_function_of_keyseq (keyseq, map, type) for (i = 0; keyseq && keyseq[i]; i++) { - unsigned char ic = keyseq[i]; + unsigned char uc = keyseq[i]; + int ic; + ic= uc; if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) { if (map[ESC].type == ISKMAP) diff --git a/cmd-line-utils/readline/display.c b/cmd-line-utils/readline/display.c index 6f63faa9738..54c56954f43 100644 --- a/cmd-line-utils/readline/display.c +++ b/cmd-line-utils/readline/display.c @@ -1888,7 +1888,7 @@ rl_character_len (c, pos) uc = (unsigned char)c; - if (META_CHAR (uc)) + if (META_CHAR (c)) return ((_rl_output_meta_chars == 0) ? 4 : 1); if (uc == '\t') diff --git a/dbug/user.r b/dbug/user.r index 19de840d0ad..ef67ef7a7cf 100644 --- a/dbug/user.r +++ b/dbug/user.r @@ -32,6 +32,7 @@ .\" === Set line length .\".ll 6.5i .TL +.warn 0 D B U G .P 0 C Program Debugging Package diff --git a/strings/ctype.c b/strings/ctype.c index 548005f8463..8902cf958a0 100644 --- a/strings/ctype.c +++ b/strings/ctype.c @@ -327,7 +327,10 @@ my_string_repertoire(CHARSET_INFO *cs, const char *str, ulong length) { my_wc_t wc; int chlen; - for (; (chlen= cs->cset->mb_wc(cs, &wc, str, strend)) > 0; str+= chlen) + for (; (chlen= cs->cset->mb_wc(cs, &wc, + (const unsigned char *) str, + (const unsigned char *) strend)) > 0; + str+= chlen) { if (wc > 0x7F) return MY_REPERTOIRE_UNICODE30; From 7787dee76a2ca28f8a1752f3aebb3760c419a3fc Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 17:59:23 +0300 Subject: [PATCH 4/6] Bug #43532 : backport of the 5.1 code to 5.0 mysqltest --- client/mysqltest.c | 101 ++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/client/mysqltest.c b/client/mysqltest.c index 2f19fad9ea9..0bde230cfe2 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -1340,23 +1340,25 @@ static int run_tool(const char *tool_path, DYNAMIC_STRING *ds_res, ...) not present. */ -int diff_check() +int diff_check(const char *diff_name) { - char buf[512]= {0}; - FILE *res_file; - const char *cmd = "diff -v"; - int have_diff = 0; + char buf[512]= {0}; + FILE *res_file; + char cmd[128]; + my_snprintf (cmd, sizeof(cmd), "%s -v", diff_name); + int have_diff = 0; if (!(res_file= popen(cmd, "r"))) die("popen(\"%s\", \"r\") failed", cmd); -/* if diff is not present, nothing will be in stdout to increment have_diff */ + /* if diff is not present, nothing will be in + * stdout to increment have_diff */ if (fgets(buf, sizeof(buf), res_file)) { have_diff += 1; } - pclose(res_file); - return have_diff; + pclose(res_file); + return have_diff; } /* @@ -1377,28 +1379,33 @@ void show_diff(DYNAMIC_STRING* ds, { DYNAMIC_STRING ds_tmp; - int have_diff = 0; + const char *diff_name = 0; if (init_dynamic_string(&ds_tmp, "", 256, 256)) die("Out of memory"); - + /* determine if we have diff on Windows - needs special processing due to return values - on that OS - This test is only done on Windows since it's only needed there - in order to correctly detect non-availibility of 'diff', and - the way it's implemented does not work with default 'diff' on Solaris. - */ + needs special processing due to return values + on that OS + This test is only done on Windows since it's only needed there + in order to correctly detect non-availibility of 'diff', and + the way it's implemented does not work with default 'diff' on Solaris. + */ #ifdef __WIN__ - have_diff = diff_check(); + if (diff_check("diff")) + diff_name = "diff"; + else if (diff_check("mtrdiff")) + diff_name = "mtrdiff"; + else + diff_name = 0; #else - have_diff = 1; + diff_name = "diff"; // Otherwise always assume it's called diff #endif - if (have_diff) + if (diff_name) { /* First try with unified diff */ - if (run_tool("diff", + if (run_tool(diff_name, &ds_tmp, /* Get output from diff in ds_tmp */ "-u", filename1, @@ -1409,7 +1416,7 @@ void show_diff(DYNAMIC_STRING* ds, dynstr_set(&ds_tmp, ""); /* Fallback to context diff with "diff -c" */ - if (run_tool("diff", + if (run_tool(diff_name, &ds_tmp, /* Get output from diff in ds_tmp */ "-c", filename1, @@ -1417,42 +1424,42 @@ void show_diff(DYNAMIC_STRING* ds, "2>&1", NULL) > 1) /* Most "diff" tools return >1 if error */ { - have_diff= 0; - } + diff_name= 0; + } } } -if (!(have_diff)) + if (!(diff_name)) { /* Fallback to dump both files to result file and inform about installing "diff" - */ - - dynstr_set(&ds_tmp, ""); + */ - dynstr_append(&ds_tmp, -"\n" -"The two files differ but it was not possible to execute 'diff' in\n" -"order to show only the difference, tried both 'diff -u' or 'diff -c'.\n" -"Instead the whole content of the two files was shown for you to diff manually. ;)\n\n" -"To get a better report you should install 'diff' on your system, which you\n" -"for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n" + dynstr_set(&ds_tmp, ""); + + dynstr_append(&ds_tmp, + "\n" + "The two files differ but it was not possible to execute 'diff' in\n" + "order to show only the difference, tried both 'diff -u' or 'diff -c'.\n" + "Instead the whole content of the two files was shown for you to diff manually. ;)\n\n" + "To get a better report you should install 'diff' on your system, which you\n" + "for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n" #ifdef __WIN__ -"or http://gnuwin32.sourceforge.net/packages/diffutils.htm\n" + "or http://gnuwin32.sourceforge.net/packages/diffutils.htm\n" #endif -"\n"); + "\n"); - dynstr_append(&ds_tmp, " --- "); - dynstr_append(&ds_tmp, filename1); - dynstr_append(&ds_tmp, " >>>\n"); - cat_file(&ds_tmp, filename1); - dynstr_append(&ds_tmp, "<<<\n --- "); - dynstr_append(&ds_tmp, filename1); - dynstr_append(&ds_tmp, " >>>\n"); - cat_file(&ds_tmp, filename2); - dynstr_append(&ds_tmp, "<<<<\n"); - } + dynstr_append(&ds_tmp, " --- "); + dynstr_append(&ds_tmp, filename1); + dynstr_append(&ds_tmp, " >>>\n"); + cat_file(&ds_tmp, filename1); + dynstr_append(&ds_tmp, "<<<\n --- "); + dynstr_append(&ds_tmp, filename1); + dynstr_append(&ds_tmp, " >>>\n"); + cat_file(&ds_tmp, filename2); + dynstr_append(&ds_tmp, "<<<<\n"); + } if (ds) { @@ -1464,7 +1471,7 @@ if (!(have_diff)) /* Print diff directly to stdout */ fprintf(stderr, "%s\n", ds_tmp.str); } - + dynstr_free(&ds_tmp); } From 5db8276fe325d2528c04535b6ae425972339c1ca Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 18:14:56 +0300 Subject: [PATCH 5/6] Bug #45286: compilation warnings on mysql-5.0-bugteam on MacOSX Implemented a way to circumvent the always true comparison by having nested macros (as suggested on review). --- cmd-line-utils/readline/chardefs.h | 3 ++- cmd-line-utils/readline/display.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd-line-utils/readline/chardefs.h b/cmd-line-utils/readline/chardefs.h index def3a111bd3..36fe7fdd7ac 100644 --- a/cmd-line-utils/readline/chardefs.h +++ b/cmd-line-utils/readline/chardefs.h @@ -59,7 +59,8 @@ #define largest_char 255 /* Largest character value. */ #define CTRL_CHAR(c) ((c) < control_character_threshold && (((c) & 0x80) == 0)) -#define META_CHAR(c) ((c) > meta_character_threshold && (c) <= largest_char) +#define META_BYTE(c) ((c) > meta_character_threshold) +#define META_CHAR(c) (META_BYTE(c) && (c) <= largest_char) #define CTRL(c) ((c) & control_character_mask) #define META(c) ((c) | meta_character_bit) diff --git a/cmd-line-utils/readline/display.c b/cmd-line-utils/readline/display.c index 54c56954f43..842a586b76b 100644 --- a/cmd-line-utils/readline/display.c +++ b/cmd-line-utils/readline/display.c @@ -1888,7 +1888,7 @@ rl_character_len (c, pos) uc = (unsigned char)c; - if (META_CHAR (c)) + if (META_BYTE (uc)) return ((_rl_output_meta_chars == 0) ? 4 : 1); if (uc == '\t') From c6fdeff0c70eb875680de64a066770159c3d7fb1 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 5 Jun 2009 19:23:44 +0300 Subject: [PATCH 6/6] Addendum to Bug #45286 : implement reviewer's remarks. --- client/mysqldump.c | 4 ++-- cmd-line-utils/readline/bind.c | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index 2fd69a3d8c6..fa6c21ed273 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -3122,7 +3122,7 @@ static my_bool dump_all_views_in_db(char *database) for (numrows= 0 ; (table= getTableName(1)); ) { char *end= strmov(afterdot, table); - if (include_table((byte*) hash_key,end - hash_key)) + if (include_table(hash_key,end - hash_key)) { numrows++; dynstr_append_checked(&query, quote_name(table, table_buff, 1)); @@ -3143,7 +3143,7 @@ static my_bool dump_all_views_in_db(char *database) while ((table= getTableName(0))) { char *end= strmov(afterdot, table); - if (include_table((byte*) hash_key, end - hash_key)) + if (include_table(hash_key, end - hash_key)) get_view_structure(table, database); } if (opt_xml) diff --git a/cmd-line-utils/readline/bind.c b/cmd-line-utils/readline/bind.c index 9d0a803cc6c..fc7bebfd813 100644 --- a/cmd-line-utils/readline/bind.c +++ b/cmd-line-utils/readline/bind.c @@ -699,11 +699,9 @@ rl_function_of_keyseq (keyseq, map, type) for (i = 0; keyseq && keyseq[i]; i++) { - unsigned char uc = keyseq[i]; - int ic; + unsigned char ic = keyseq[i]; - ic= uc; - if (META_CHAR (ic) && _rl_convert_meta_chars_to_ascii) + if (META_BYTE (ic) && _rl_convert_meta_chars_to_ascii) { if (map[ESC].type == ISKMAP) {