From 33ac50f0769a01028bdb57a741eb449140ca5504 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Apr 2007 17:53:10 +0500 Subject: [PATCH 01/13] bug#27608 XML output is not well-formed Problem: output was empty if the result is empty. Fix: print XML header and footer, even if the result is empty, to produce well-formed XML output. client/mysql.cc: Print header and footer even on empty set, when --xml mysql-test/r/client_xml.result: Adding test case mysql-test/t/client_xml.test: Adding test case --- client/mysql.cc | 11 +++++++++ mysql-test/r/bdb_notembedded.result | 35 ++++++++++++++++++++++++++ mysql-test/r/client_xml.result | 14 +++++++++++ mysql-test/t/bdb_notembedded.test | 38 +++++++++++++++++++++++++++++ mysql-test/t/client_xml.test | 2 ++ 5 files changed, 100 insertions(+) create mode 100644 mysql-test/r/bdb_notembedded.result create mode 100644 mysql-test/t/bdb_notembedded.test diff --git a/client/mysql.cc b/client/mysql.cc index 510420fdf3d..6b37bb7b6f5 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -2117,6 +2117,17 @@ com_go(String *buffer,char *line __attribute__((unused))) if (!mysql_num_rows(result) && ! quick && !info_flag) { strmov(buff, "Empty set"); + if (opt_xml) + { + /* + We must print XML header and footer + to produce a well-formed XML even if + the result set is empty (Bug#27608). + */ + init_pager(); + print_table_data_xml(result); + end_pager(); + } } else { diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result new file mode 100644 index 00000000000..14cb5fad915 --- /dev/null +++ b/mysql-test/r/bdb_notembedded.result @@ -0,0 +1,35 @@ +set autocommit=1; +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; insert into bug16206 values(2) +drop table bug16206; +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb +f n Query 1 n use `test`; insert into bug16206 values(0) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; BEGIN +f n Query 1 n use `test`; insert into bug16206 values(2) +f n Query 1 n use `test`; COMMIT +f n Query 1 n use `test`; insert into bug16206 values(3) +drop table bug16206; +set autocommit=0; +End of 5.0 tests diff --git a/mysql-test/r/client_xml.result b/mysql-test/r/client_xml.result index 6a148954fcd..ed5e8f2c1b8 100644 --- a/mysql-test/r/client_xml.result +++ b/mysql-test/r/client_xml.result @@ -71,4 +71,18 @@ insert into t1 values (1, 2, 'a&b ab'); + + + +-------------- +select 1 limit 0 +-------------- + + + + +Empty set + +Bye drop table t1; diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test new file mode 100644 index 00000000000..24e64ebbfb2 --- /dev/null +++ b/mysql-test/t/bdb_notembedded.test @@ -0,0 +1,38 @@ +-- source include/not_embedded.inc +-- source include/have_bdb.inc + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/client_xml.test b/mysql-test/t/client_xml.test index 017b7a1569a..8ee63a6131b 100644 --- a/mysql-test/t/client_xml.test +++ b/mysql-test/t/client_xml.test @@ -17,5 +17,7 @@ insert into t1 values (1, 2, 'a&b ab'); --exec $MYSQL --xml test -e "select 1 > 2 from dual" --exec $MYSQL --xml test -e "select 1 & 3 from dual" --exec $MYSQL --xml test -e "select null from dual" +--exec $MYSQL --xml test -e "select 1 limit 0" +--exec $MYSQL --xml test -vv -e "select 1 limit 0" drop table t1; From 8e2b68c3cdf44b899b71829b90f4cb1a3fec53bd Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 9 Apr 2007 17:58:56 +0500 Subject: [PATCH 02/13] Bug#22648 LC_TIME_NAMES: Setting GLOBAL has no effect Problem: setting/displaying @@LC_TIME_NAMES didn't distinguish between GLOBAL and SESSION variable types - always SESSION variable was set/shonw. Fix: set either global or session value. Also, "mysqld --lc-time-names" was added to set "global default" value. mysql-test/r/variables.result: Adding test cases mysql-test/t/variables.test: Adding test cases sql/mysql_priv.h: Declaring variable for global default. sql/mysqld.cc: Adding --lc-time-names sql/set_var.cc: Distinguish between GLOBAL and SESSION variables. sql/sql_class.cc: Don't initialize to en_US, use global_system_variables value instead. --- mysql-test/r/bdb_notembedded.result | 35 ++++++++++++++++++++++++++ mysql-test/r/variables.result | 31 +++++++++++++++++++++++ mysql-test/t/bdb_notembedded.test | 38 +++++++++++++++++++++++++++++ mysql-test/t/variables.test | 24 ++++++++++++++++++ sql/mysql_priv.h | 1 + sql/mysqld.cc | 19 ++++++++++++++- sql/set_var.cc | 14 ++++++++--- sql/sql_class.cc | 1 - 8 files changed, 158 insertions(+), 5 deletions(-) create mode 100644 mysql-test/r/bdb_notembedded.result create mode 100644 mysql-test/t/bdb_notembedded.test diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result new file mode 100644 index 00000000000..14cb5fad915 --- /dev/null +++ b/mysql-test/r/bdb_notembedded.result @@ -0,0 +1,35 @@ +set autocommit=1; +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; insert into bug16206 values(2) +drop table bug16206; +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb +f n Query 1 n use `test`; insert into bug16206 values(0) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; BEGIN +f n Query 1 n use `test`; insert into bug16206 values(2) +f n Query 1 n use `test`; COMMIT +f n Query 1 n use `test`; insert into bug16206 values(3) +drop table bug16206; +set autocommit=0; +End of 5.0 tests diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index 60010183d32..3d76f8e4a90 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -637,6 +637,37 @@ set lc_time_names=0; select @@lc_time_names; @@lc_time_names en_US +select @@global.lc_time_names, @@lc_time_names; +@@global.lc_time_names @@lc_time_names +en_US en_US +set @@global.lc_time_names=fr_FR; +select @@global.lc_time_names, @@lc_time_names; +@@global.lc_time_names @@lc_time_names +fr_FR en_US +New connection +select @@global.lc_time_names, @@lc_time_names; +@@global.lc_time_names @@lc_time_names +fr_FR fr_FR +set @@lc_time_names=ru_RU; +select @@global.lc_time_names, @@lc_time_names; +@@global.lc_time_names @@lc_time_names +fr_FR ru_RU +Returnung to default connection +select @@global.lc_time_names, @@lc_time_names; +@@global.lc_time_names @@lc_time_names +fr_FR en_US +set lc_time_names=default; +select @@global.lc_time_names, @@lc_time_names; +@@global.lc_time_names @@lc_time_names +fr_FR fr_FR +set @@global.lc_time_names=default; +select @@global.lc_time_names, @@lc_time_names; +@@global.lc_time_names @@lc_time_names +en_US fr_FR +set @@lc_time_names=default; +select @@global.lc_time_names, @@lc_time_names; +@@global.lc_time_names @@lc_time_names +en_US en_US set @test = @@query_prealloc_size; set @@query_prealloc_size = @test; select @@query_prealloc_size = @test; diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test new file mode 100644 index 00000000000..24e64ebbfb2 --- /dev/null +++ b/mysql-test/t/bdb_notembedded.test @@ -0,0 +1,38 @@ +-- source include/not_embedded.inc +-- source include/have_bdb.inc + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 697e55945ef..0ad85a32568 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -504,6 +504,30 @@ select @@lc_time_names; set lc_time_names=0; select @@lc_time_names; +# +# Bug #22648 LC_TIME_NAMES: Setting GLOBAL has no effect +# +select @@global.lc_time_names, @@lc_time_names; +set @@global.lc_time_names=fr_FR; +select @@global.lc_time_names, @@lc_time_names; +--echo New connection +connect (con1,localhost,root,,); +connection con1; +select @@global.lc_time_names, @@lc_time_names; +set @@lc_time_names=ru_RU; +select @@global.lc_time_names, @@lc_time_names; +disconnect con1; +connection default; +--echo Returnung to default connection +select @@global.lc_time_names, @@lc_time_names; +set lc_time_names=default; +select @@global.lc_time_names, @@lc_time_names; +set @@global.lc_time_names=default; +select @@global.lc_time_names, @@lc_time_names; +set @@lc_time_names=default; +select @@global.lc_time_names, @@lc_time_names; + + # # Bug #13334: query_prealloc_size default less than minimum # diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index de567eacbeb..f9aa8441a27 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -149,6 +149,7 @@ typedef struct my_locale_st extern MY_LOCALE my_locale_en_US; extern MY_LOCALE *my_locales[]; +extern MY_LOCALE *my_default_lc_time_names; MY_LOCALE *my_locale_by_name(const char *name); MY_LOCALE *my_locale_by_number(uint number); diff --git a/sql/mysqld.cc b/sql/mysqld.cc index b0fc5a30ff5..2a42af8450f 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -315,6 +315,7 @@ static char *mysqld_user, *mysqld_chroot, *log_error_file_ptr; static char *opt_init_slave, *language_ptr, *opt_init_connect; static char *default_character_set_name; static char *character_set_filesystem_name; +static char *lc_time_names_name; static char *my_bind_addr_str; static char *default_collation_name; static char compiled_default_collation_name[]= MYSQL_DEFAULT_COLLATION_NAME; @@ -495,6 +496,8 @@ CHARSET_INFO *system_charset_info, *files_charset_info ; CHARSET_INFO *national_charset_info, *table_alias_charset; CHARSET_INFO *character_set_filesystem; +MY_LOCALE *my_default_lc_time_names; + SHOW_COMP_OPTION have_isam; SHOW_COMP_OPTION have_raid, have_ssl, have_symlink, have_query_cache; SHOW_COMP_OPTION have_geometry, have_rtree_keys, have_dlopen; @@ -2826,6 +2829,14 @@ static int init_common_variables(const char *conf_file_name, int argc, return 1; global_system_variables.character_set_filesystem= character_set_filesystem; + if (!(my_default_lc_time_names= + my_locale_by_name(lc_time_names_name))) + { + sql_print_error("Unknown locale: '%s'", MYF(0), lc_time_names_name); + return 1; + } + global_system_variables.lc_time_names= my_default_lc_time_names; + sys_init_connect.value_length= 0; if ((sys_init_connect.value= opt_init_connect)) sys_init_connect.value_length= strlen(opt_init_connect); @@ -4749,6 +4760,7 @@ enum options_mysqld OPT_DEFAULT_COLLATION, OPT_CHARACTER_SET_CLIENT_HANDSHAKE, OPT_CHARACTER_SET_FILESYSTEM, + OPT_LC_TIME_NAMES, OPT_INIT_CONNECT, OPT_INIT_SLAVE, OPT_SECURE_AUTH, @@ -5078,6 +5090,11 @@ Disable with --skip-innodb-doublewrite.", (gptr*) &innobase_use_doublewrite, "Client error messages in given language. May be given as a full path.", (gptr*) &language_ptr, (gptr*) &language_ptr, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"lc-time-names", OPT_LC_TIME_NAMES, + "Set the language used for the month names and the days of the week.", + (gptr*) &lc_time_names_name, + (gptr*) &lc_time_names_name, + 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 }, {"local-infile", OPT_LOCAL_INFILE, "Enable/disable LOAD DATA LOCAL INFILE (takes values 1|0).", (gptr*) &opt_local_infile, @@ -6552,7 +6569,7 @@ static void mysql_init_variables(void) default_collation_name= compiled_default_collation_name; sys_charset_system.value= (char*) system_charset_info->csname; character_set_filesystem_name= (char*) "binary"; - + lc_time_names_name= (char*) "en_US"; /* Set default values for some option variables */ global_system_variables.table_type= DB_TYPE_MYISAM; diff --git a/sql/set_var.cc b/sql/set_var.cc index 46c2a775d8a..d4dcfafe522 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -2825,7 +2825,10 @@ bool sys_var_thd_lc_time_names::check(THD *thd, set_var *var) bool sys_var_thd_lc_time_names::update(THD *thd, set_var *var) { - thd->variables.lc_time_names= var->save_result.locale_value; + if (var->type == OPT_GLOBAL) + global_system_variables.lc_time_names= var->save_result.locale_value; + else + thd->variables.lc_time_names= var->save_result.locale_value; return 0; } @@ -2833,13 +2836,18 @@ bool sys_var_thd_lc_time_names::update(THD *thd, set_var *var) byte *sys_var_thd_lc_time_names::value_ptr(THD *thd, enum_var_type type, LEX_STRING *base) { - return (byte *)(thd->variables.lc_time_names->name); + return type == OPT_GLOBAL ? + (byte *) global_system_variables.lc_time_names->name : + (byte *) thd->variables.lc_time_names->name; } void sys_var_thd_lc_time_names::set_default(THD *thd, enum_var_type type) { - thd->variables.lc_time_names = &my_locale_en_US; + if (type == OPT_GLOBAL) + global_system_variables.lc_time_names= my_default_lc_time_names; + else + thd->variables.lc_time_names= global_system_variables.lc_time_names; } /* diff --git a/sql/sql_class.cc b/sql/sql_class.cc index a94f903a47b..6f3b7433860 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -343,7 +343,6 @@ void THD::init(void) total_warn_count= 0; update_charset(); bzero((char *) &status_var, sizeof(status_var)); - variables.lc_time_names = &my_locale_en_US; } From 8fe487beba161e6290d9e063efc4c3019c9ed412 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Apr 2007 13:58:16 +0300 Subject: [PATCH 03/13] Bug #27530: The function CRC32() returns unsigned integer. But the metadata (the unsigned flag) for the function was set incorrectly. As a result type arithmetics based on the function's metadata (like finding the concise type of an temporary table column to hold the result) returned incorrect results. Fixed by returning correct type information. This fix is based on code contributed by Martin Friebe (martin@hybyte.com) on 2007-03-30. mysql-test/r/func_str.result: Bug #27530: test case mysql-test/t/func_str.test: Bug #27530: test case sql/item_strfunc.h: Bug #27530: Marked CRC32() as returning unsigned --- mysql-test/r/bdb_notembedded.result | 35 +++++++++++++++ mysql-test/r/func_str.result | 69 +++++++++++++++++++++++++++++ mysql-test/t/bdb_notembedded.test | 38 ++++++++++++++++ mysql-test/t/func_str.test | 18 ++++++++ sql/item_strfunc.h | 2 +- 5 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 mysql-test/r/bdb_notembedded.result create mode 100644 mysql-test/t/bdb_notembedded.test diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result new file mode 100644 index 00000000000..14cb5fad915 --- /dev/null +++ b/mysql-test/r/bdb_notembedded.result @@ -0,0 +1,35 @@ +set autocommit=1; +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; insert into bug16206 values(2) +drop table bug16206; +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb +f n Query 1 n use `test`; insert into bug16206 values(0) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; BEGIN +f n Query 1 n use `test`; insert into bug16206 values(2) +f n Query 1 n use `test`; COMMIT +f n Query 1 n use `test`; insert into bug16206 values(3) +drop table bug16206; +set autocommit=0; +End of 5.0 tests diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index 92265c77984..d8afbe13c76 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -1992,4 +1992,73 @@ abc SELECT INSERT('abc', 6, 3, '1234'); INSERT('abc', 6, 3, '1234') abc +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT CRC32(a) AS C FROM t1; +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1; +CRC32(a) COUNT(*) +450215437 1 +498629140 1 +1790921346 1 +1842515611 1 +2212294583 1 +2226203566 1 +2366072709 1 +2707236321 1 +4088798008 1 +4194326291 1 +SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1 ORDER BY 1; +CRC32(a) COUNT(*) +450215437 1 +498629140 1 +1790921346 1 +1842515611 1 +2212294583 1 +2226203566 1 +2366072709 1 +2707236321 1 +4088798008 1 +4194326291 1 +SELECT * FROM (SELECT CRC32(a) FROM t1) t2; +CRC32(a) +2212294583 +450215437 +1842515611 +4088798008 +2226203566 +498629140 +1790921346 +4194326291 +2366072709 +2707236321 +CREATE TABLE t2 SELECT CRC32(a) FROM t1; +desc t2; +Field Type Null Key Default Extra +CRC32(a) int(10) unsigned YES NULL +SELECT * FROM v1; +C +2212294583 +450215437 +1842515611 +4088798008 +2226203566 +498629140 +1790921346 +4194326291 +2366072709 +2707236321 +SELECT * FROM (SELECT * FROM v1) x; +C +2212294583 +450215437 +1842515611 +4088798008 +2226203566 +498629140 +1790921346 +4194326291 +2366072709 +2707236321 +DROP TABLE t1, t2; +DROP VIEW v1; End of 5.0 tests diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test new file mode 100644 index 00000000000..24e64ebbfb2 --- /dev/null +++ b/mysql-test/t/bdb_notembedded.test @@ -0,0 +1,38 @@ +-- source include/not_embedded.inc +-- source include/have_bdb.inc + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index 0e4b404fe3a..bca977e6df3 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -1058,4 +1058,22 @@ SELECT INSERT('abc', 4, 3, '1234'); SELECT INSERT('abc', 5, 3, '1234'); SELECT INSERT('abc', 6, 3, '1234'); +# +# Bug #27530: Grouping on crc32, or create table select crc32 +# +CREATE TABLE t1 (a INT); +CREATE VIEW v1 AS SELECT CRC32(a) AS C FROM t1; + +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); +SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1; +SELECT CRC32(a), COUNT(*) FROM t1 GROUP BY 1 ORDER BY 1; +SELECT * FROM (SELECT CRC32(a) FROM t1) t2; +CREATE TABLE t2 SELECT CRC32(a) FROM t1; +desc t2; +SELECT * FROM v1; +SELECT * FROM (SELECT * FROM v1) x; + +DROP TABLE t1, t2; +DROP VIEW v1; + --echo End of 5.0 tests diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 778ea6e9496..d7c4a3eddef 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -790,7 +790,7 @@ class Item_func_crc32 :public Item_int_func { String value; public: - Item_func_crc32(Item *a) :Item_int_func(a) {} + Item_func_crc32(Item *a) :Item_int_func(a) { unsigned_flag= 1; } const char *func_name() const { return "crc32"; } void fix_length_and_dec() { max_length=10; } longlong val_int(); From 1992907b451e17078410d32f9218503de7b4972d Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Apr 2007 11:29:43 +0500 Subject: [PATCH 04/13] mysqld.cc: Removing wrong MYF(0) argument. sql/mysqld.cc: Removing wrong MYF(0) argument. --- sql/mysqld.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 2a42af8450f..fe99aa08ada 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -2832,7 +2832,7 @@ static int init_common_variables(const char *conf_file_name, int argc, if (!(my_default_lc_time_names= my_locale_by_name(lc_time_names_name))) { - sql_print_error("Unknown locale: '%s'", MYF(0), lc_time_names_name); + sql_print_error("Unknown locale: '%s'", lc_time_names_name); return 1; } global_system_variables.lc_time_names= my_default_lc_time_names; From d4dfe7664e0ee99ff60a772ee27b458bbe31d0d8 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Apr 2007 14:00:45 +0200 Subject: [PATCH 05/13] BUG#26551 (Aborted query for non-transactional table breaks replication): Added error code ER_QUERY_INTERRUPTED to the list of special errors that prevent the slave from starting to execute a query. sql/slave.cc: Added ER_QUERY_INTERRUPTED to special error code that prevents statement from being executed on slave. mysql-test/r/rpl_critical_errors.result.txt: New BitKeeper file ``mysql-test/r/rpl_critical_errors.result.txt'' mysql-test/t/rpl_critical_errors.test: New BitKeeper file ``mysql-test/t/rpl_critical_errors.test'' --- mysql-test/r/bdb_notembedded.result | 35 +++++++++++ mysql-test/r/rpl_critical_errors.result.txt | 56 +++++++++++++++++ mysql-test/t/bdb_notembedded.test | 38 ++++++++++++ mysql-test/t/rpl_critical_errors.test | 66 +++++++++++++++++++++ sql/slave.cc | 1 + 5 files changed, 196 insertions(+) create mode 100644 mysql-test/r/bdb_notembedded.result create mode 100644 mysql-test/r/rpl_critical_errors.result.txt create mode 100644 mysql-test/t/bdb_notembedded.test create mode 100644 mysql-test/t/rpl_critical_errors.test diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result new file mode 100644 index 00000000000..14cb5fad915 --- /dev/null +++ b/mysql-test/r/bdb_notembedded.result @@ -0,0 +1,35 @@ +set autocommit=1; +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; insert into bug16206 values(2) +drop table bug16206; +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb +f n Query 1 n use `test`; insert into bug16206 values(0) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; BEGIN +f n Query 1 n use `test`; insert into bug16206 values(2) +f n Query 1 n use `test`; COMMIT +f n Query 1 n use `test`; insert into bug16206 values(3) +drop table bug16206; +set autocommit=0; +End of 5.0 tests diff --git a/mysql-test/r/rpl_critical_errors.result.txt b/mysql-test/r/rpl_critical_errors.result.txt new file mode 100644 index 00000000000..0df2e1ef369 --- /dev/null +++ b/mysql-test/r/rpl_critical_errors.result.txt @@ -0,0 +1,56 @@ +stop slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +reset master; +reset slave; +drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; +start slave; +CREATE TABLE t1 (data LONGBLOB) ENGINE=MYISAM; +CREATE TABLE t2 (data LONGBLOB) ENGINE=MYISAM; +INSERT INTO t1 (data) VALUES (repeat('a',1024*1024)); +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t2 SELECT * FROM t1; +KILL QUERY 2; +SELECT COUNT(*) FROM t2; +COUNT(*) +0 +SHOW SLAVE STATUS; +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_PORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos # +Relay_Log_File # +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running Yes +Slave_SQL_Running No +Replicate_Do_DB +Replicate_Ignore_DB +Replicate_Do_Table +Replicate_Ignore_Table +Replicate_Wild_Do_Table +Replicate_Wild_Ignore_Table +Last_Errno 1317 +Last_Error # +Skip_Counter 0 +Exec_Master_Log_Pos # +Relay_Log_Space # +Until_Condition None +Until_Log_File +Until_Log_Pos 0 +Master_SSL_Allowed No +Master_SSL_CA_File +Master_SSL_CA_Path +Master_SSL_Cert +Master_SSL_Cipher +Master_SSL_Key +Seconds_Behind_Master # diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test new file mode 100644 index 00000000000..24e64ebbfb2 --- /dev/null +++ b/mysql-test/t/bdb_notembedded.test @@ -0,0 +1,38 @@ +-- source include/not_embedded.inc +-- source include/have_bdb.inc + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/rpl_critical_errors.test b/mysql-test/t/rpl_critical_errors.test new file mode 100644 index 00000000000..ffe00050b01 --- /dev/null +++ b/mysql-test/t/rpl_critical_errors.test @@ -0,0 +1,66 @@ +# Test for BUG#26551 +# + +# This test is unfortunately very fragile and very dependent on the +# load of the computer. The test is therefore disabled normally. It is +# entered here to demonstrate how to check that the bug is actually +# solved. + +--echo Turn on parsing to run this test + +disable_parsing; + +source include/master-slave.inc; + +connection master; +CREATE TABLE t1 (data LONGBLOB) ENGINE=MYISAM; +CREATE TABLE t2 (data LONGBLOB) ENGINE=MYISAM; + +INSERT INTO t1 (data) VALUES (repeat('a',1024*1024)); +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +INSERT INTO t1 SELECT * FROM t1; +sync_slave_with_master; + +connection master; +send INSERT INTO t2 SELECT * FROM t1; + +connection master1; + +# This sleep is picked so that the query above has started to insert +# some rows into t2. If it hasn't the slave will not stop below. +sleep 4; + +# SHOW PROCESSLIST; + +# Code for the 5.1 server to get the thread id of the thread executing +# the query above. +# +#SET @id = 0; +#SELECT id INTO @id +# FROM information_schema.processlist +# WHERE info LIKE 'INSERT INTO t2%'; + +# This is the connection that is executing the INSERT INTO t2... +KILL QUERY 2; + +connection slave; + +# Here the slave will only stop if the query above actually started +# inserting some rows into t2. Otherwise, it will hang forever. +wait_for_slave_to_stop; + +# The following should be 0 +SELECT COUNT(*) FROM t2; + +# ... and there the error code should be 1317 (ER_QUERY_INTERRUPTED) +--replace_result $MASTER_MYPORT MASTER_PORT +--replace_column 1 # 7 # 8 # 9 # 20 # 22 # 23 # 33 # +query_vertical SHOW SLAVE STATUS; + +enable_parsing; diff --git a/sql/slave.cc b/sql/slave.cc index ba8c3ff902a..97615165803 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -3099,6 +3099,7 @@ int check_expected_error(THD* thd, RELAY_LOG_INFO* rli, int expected_error) switch (expected_error) { case ER_NET_READ_ERROR: case ER_NET_ERROR_ON_WRITE: + case ER_QUERY_INTERRUPTED: case ER_SERVER_SHUTDOWN: case ER_NEW_ABORTING_CONNECTION: return 1; From dc98df13b6a7cacb5dc09a93292c2f3d3c68d986 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 12 Apr 2007 19:42:45 +0400 Subject: [PATCH 06/13] Test case for BUG#5274: Stored procedure crash if length of CHAR variable too great. mysql-test/r/sp.result: Update result file. mysql-test/t/sp.test: Add test case for BUG#5274. --- mysql-test/r/bdb_notembedded.result | 35 ++++++++++++++++++++ mysql-test/r/sp.result | 50 +++++++++++++++++++++++++++++ mysql-test/t/bdb_notembedded.test | 38 ++++++++++++++++++++++ mysql-test/t/sp.test | 38 ++++++++++++++++++++++ 4 files changed, 161 insertions(+) create mode 100644 mysql-test/r/bdb_notembedded.result create mode 100644 mysql-test/t/bdb_notembedded.test diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result new file mode 100644 index 00000000000..14cb5fad915 --- /dev/null +++ b/mysql-test/r/bdb_notembedded.result @@ -0,0 +1,35 @@ +set autocommit=1; +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; insert into bug16206 values(2) +drop table bug16206; +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb +f n Query 1 n use `test`; insert into bug16206 values(0) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; BEGIN +f n Query 1 n use `test`; insert into bug16206 values(2) +f n Query 1 n use `test`; COMMIT +f n Query 1 n use `test`; insert into bug16206 values(3) +drop table bug16206; +set autocommit=0; +End of 5.0 tests diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index c75697b93a2..ad2cb443f25 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -6053,5 +6053,55 @@ select bug20777(18446744073709551613)+1; bug20777(18446744073709551613)+1 18446744073709551614 drop function bug20777; +DROP FUNCTION IF EXISTS bug5274_f1| +DROP FUNCTION IF EXISTS bug5274_f2| +CREATE FUNCTION bug5274_f1(p1 CHAR) RETURNS CHAR +RETURN CONCAT(p1, p1)| +CREATE FUNCTION bug5274_f2() RETURNS CHAR +BEGIN +DECLARE v1 INT DEFAULT 0; +DECLARE v2 CHAR DEFAULT 'x'; +WHILE v1 < 30 DO +SET v1 = v1 + 1; +SET v2 = bug5274_f1(v2); +END WHILE; +RETURN v2; +END| +SELECT bug5274_f2()| +bug5274_f2() +x +Warnings: +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +Warning 1265 Data truncated for column 'bug5274_f1' at row 1 +DROP FUNCTION bug5274_f1| +DROP FUNCTION bug5274_f2| End of 5.0 tests. drop table t1,t2; diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test new file mode 100644 index 00000000000..24e64ebbfb2 --- /dev/null +++ b/mysql-test/t/bdb_notembedded.test @@ -0,0 +1,38 @@ +-- source include/not_embedded.inc +-- source include/have_bdb.inc + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 8403c8589ef..9510588429b 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -6976,6 +6976,44 @@ select bug20777(18446744073709551613)+1; drop function bug20777; delimiter |; + +# +# BUG#5274: Stored procedure crash if length of CHAR variable too great. +# + +# Prepare. + +--disable_warnings +DROP FUNCTION IF EXISTS bug5274_f1| +DROP FUNCTION IF EXISTS bug5274_f2| +--enable_warnings + +# Test. + +CREATE FUNCTION bug5274_f1(p1 CHAR) RETURNS CHAR + RETURN CONCAT(p1, p1)| + +CREATE FUNCTION bug5274_f2() RETURNS CHAR +BEGIN + DECLARE v1 INT DEFAULT 0; + DECLARE v2 CHAR DEFAULT 'x'; + + WHILE v1 < 30 DO + SET v1 = v1 + 1; + SET v2 = bug5274_f1(v2); + END WHILE; + + RETURN v2; +END| + +SELECT bug5274_f2()| + +# Cleanup. + +DROP FUNCTION bug5274_f1| +DROP FUNCTION bug5274_f2| + + ### --echo End of 5.0 tests. From 2a4ab288fd8897ce289f047a47855254d40bfbbf Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Apr 2007 10:05:55 +0500 Subject: [PATCH 07/13] Bug#20095 Changing length of VARCHAR field with UTF8 collation does not truncate values Problem: single byte do_varstring1() function was called, which didn't check limit on "number of character", and checked only "number of bytes". Fix: adding a multi-byte aware function do_varstring1_mb(), to limit on "number of characters" mysql-test/r/ctype_utf8.result: Adding test case mysql-test/t/ctype_utf8.test: Adding test case sql/field_conv.cc: Adding missing function to copy VARCHAR strings having one length byte. --- mysql-test/r/bdb_notembedded.result | 35 +++++++++++++++++++++++ mysql-test/r/ctype_utf8.result | 43 +++++++++++++++++++++++++++++ mysql-test/t/bdb_notembedded.test | 38 +++++++++++++++++++++++++ mysql-test/t/ctype_utf8.test | 35 +++++++++++++++++++++++ sql/field_conv.cc | 32 +++++++++++++++++++-- 5 files changed, 181 insertions(+), 2 deletions(-) create mode 100644 mysql-test/r/bdb_notembedded.result create mode 100644 mysql-test/t/bdb_notembedded.test diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result new file mode 100644 index 00000000000..14cb5fad915 --- /dev/null +++ b/mysql-test/r/bdb_notembedded.result @@ -0,0 +1,35 @@ +set autocommit=1; +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; insert into bug16206 values(2) +drop table bug16206; +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb +f n Query 1 n use `test`; insert into bug16206 values(0) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; BEGIN +f n Query 1 n use `test`; insert into bug16206 values(2) +f n Query 1 n use `test`; COMMIT +f n Query 1 n use `test`; insert into bug16206 values(3) +drop table bug16206; +set autocommit=0; +End of 5.0 tests diff --git a/mysql-test/r/ctype_utf8.result b/mysql-test/r/ctype_utf8.result index 1c6bc0e05b6..216b5f393fb 100644 --- a/mysql-test/r/ctype_utf8.result +++ b/mysql-test/r/ctype_utf8.result @@ -1480,6 +1480,49 @@ aa xxx yyy DROP TABLE t1; +create table t1 ( +a varchar(26) not null +) default character set utf8; +insert into t1 (a) values ('abcdefghijklmnopqrstuvwxyz'); +select * from t1; +a +abcdefghijklmnopqrstuvwxyz +alter table t1 change a a varchar(20) character set utf8 not null; +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +select * from t1; +a +abcdefghijklmnopqrst +alter table t1 change a a char(15) character set utf8 not null; +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +select * from t1; +a +abcdefghijklmno +alter table t1 change a a char(10) character set utf8 not null; +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +select * from t1; +a +abcdefghij +alter table t1 change a a varchar(5) character set utf8 not null; +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +select * from t1; +a +abcde +drop table t1; +create table t1 ( +a varchar(4000) not null +) default character set utf8; +insert into t1 values (repeat('a',4000)); +alter table t1 change a a varchar(3000) character set utf8 not null; +Warnings: +Warning 1265 Data truncated for column 'a' at row 1 +select length(a) from t1; +length(a) +3000 +drop table t1; set names utf8; select hex(char(1 using utf8)); hex(char(1 using utf8)) diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test new file mode 100644 index 00000000000..24e64ebbfb2 --- /dev/null +++ b/mysql-test/t/bdb_notembedded.test @@ -0,0 +1,38 @@ +-- source include/not_embedded.inc +-- source include/have_bdb.inc + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/ctype_utf8.test b/mysql-test/t/ctype_utf8.test index 79b73fc7880..c4637d14edc 100644 --- a/mysql-test/t/ctype_utf8.test +++ b/mysql-test/t/ctype_utf8.test @@ -1192,6 +1192,41 @@ SELECT DISTINCT id FROM t1 ORDER BY id; DROP TABLE t1; +# +# Bug#20095 Changing length of VARCHAR field with UTF8 +# collation does not truncate values +# +create table t1 ( + a varchar(26) not null +) default character set utf8; +insert into t1 (a) values ('abcdefghijklmnopqrstuvwxyz'); +select * from t1; +# varchar to varchar +alter table t1 change a a varchar(20) character set utf8 not null; +select * from t1; +# varchar to char +alter table t1 change a a char(15) character set utf8 not null; +select * from t1; +# char to char +alter table t1 change a a char(10) character set utf8 not null; +select * from t1; +# char to varchar +alter table t1 change a a varchar(5) character set utf8 not null; +select * from t1; +drop table t1; + +# +# Check that do_varstring2_mb produces a warning +# +create table t1 ( + a varchar(4000) not null +) default character set utf8; +insert into t1 values (repeat('a',4000)); +alter table t1 change a a varchar(3000) character set utf8 not null; +select length(a) from t1; +drop table t1; + + # # Bug#10504: Character set does not support traditional mode # Bug#14146: CHAR(...USING ...) and CONVERT(CHAR(...) USING...) diff --git a/sql/field_conv.cc b/sql/field_conv.cc index 429d914db97..5670b1e0676 100644 --- a/sql/field_conv.cc +++ b/sql/field_conv.cc @@ -434,6 +434,26 @@ static void do_varstring1(Copy_field *copy) } +static void do_varstring1_mb(Copy_field *copy) +{ + int well_formed_error; + CHARSET_INFO *cs= copy->from_field->charset(); + uint from_length= (uint) *(uchar*) copy->from_ptr; + const char *from_ptr= copy->from_ptr + 1; + uint to_char_length= (copy->to_length - 1) / cs->mbmaxlen; + uint length= cs->cset->well_formed_len(cs, from_ptr, from_ptr + from_length, + to_char_length, &well_formed_error); + if (length < from_length) + { + if (current_thd->count_cuted_fields) + copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + WARN_DATA_TRUNCATED, 1); + } + *(uchar*) copy->to_ptr= (uchar) length; + memcpy(copy->to_ptr + 1, from_ptr, length); +} + + static void do_varstring2(Copy_field *copy) { uint length=uint2korr(copy->from_ptr); @@ -459,6 +479,12 @@ static void do_varstring2_mb(Copy_field *copy) const char *from_beg= copy->from_ptr + HA_KEY_BLOB_LENGTH; uint length= cs->cset->well_formed_len(cs, from_beg, from_beg + from_length, char_length, &well_formed_error); + if (length < from_length) + { + if (current_thd->count_cuted_fields) + copy->to_field->set_warning(MYSQL_ERROR::WARN_LEVEL_WARN, + WARN_DATA_TRUNCATED, 1); + } int2store(copy->to_ptr, length); memcpy(copy->to_ptr+HA_KEY_BLOB_LENGTH, from_beg, length); } @@ -634,8 +660,10 @@ void (*Copy_field::get_copy_func(Field *to,Field *from))(Copy_field*) return do_field_string; if (to_length != from_length) return (((Field_varstring*) to)->length_bytes == 1 ? - do_varstring1 : (from->charset()->mbmaxlen == 1 ? - do_varstring2 : do_varstring2_mb)); + (from->charset()->mbmaxlen == 1 ? do_varstring1 : + do_varstring1_mb) : + (from->charset()->mbmaxlen == 1 ? do_varstring2 : + do_varstring2_mb)); } else if (to_length < from_length) return (from->charset()->mbmaxlen == 1 ? From 579c2bff63fb8833226d86afb6ac2eab0ead9737 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 17 Apr 2007 17:35:29 -0700 Subject: [PATCH 08/13] Fixed bug #27870. The bug that causes crashes manifests itself at some conditions when executing an equijoin query with WHERE condition containing a subquery predicate of the form join_attr NOT IN (SELECT ...). To resolve a problem of the correct evaluation of the expression attr NOT IN (SELECT ...) an array of guards is created to make it possible to filter out some predicates of the EXISTS subquery into which the original subquery predicate is transformed, in the cases when a takes the NULL value. If attr is defined as a field that cannot be NULL than such an array is not needed and is not created. However if the field a occurred also an an equijoin predicate t2.a=t1.b and table t1 is accessed before table t2 then it may happen that the the EXISTS subquery is pushed down to the condition evaluated just after table t1 has been accessed. In this case any occurrence of t2.a is substituted for t1.b. When t1.b takes the value of NULL an attempt is made to turn on the corresponding guard. This action caused a crash as no guard array had been created. Now the code of Item_in_subselect::set_cond_guard_var checks that the guard array has been created before setting a guard variable on. Otherwise the method does nothing. It cannot results in returning a row that could be rejected as the condition t2.a=t1.b will be checked later anyway. mysql-test/r/subselect3.result: Added a test case for bug #27870. mysql-test/t/subselect3.test: Added a test case for bug #27870. sql/item_subselect.h: Fixed bug #27870. The bug that causes crashes manifests itself at some conditions when executing an equijoin query with WHERE condition containing a subquery predicate of the form join_attr NOT IN (SELECT ...). Forced Item_in_subselect::set_cond_guard_var to check that the guard array has been created before setting a guard variable on. Otherwise the method does nothing. --- mysql-test/r/bdb_notembedded.result | 35 ++++++++++++++++++++++++++ mysql-test/r/subselect3.result | 19 +++++++++++++++ mysql-test/t/bdb_notembedded.test | 38 +++++++++++++++++++++++++++++ mysql-test/t/subselect3.test | 18 ++++++++++++++ sql/item_subselect.h | 6 ++++- 5 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 mysql-test/r/bdb_notembedded.result create mode 100644 mysql-test/t/bdb_notembedded.test diff --git a/mysql-test/r/bdb_notembedded.result b/mysql-test/r/bdb_notembedded.result new file mode 100644 index 00000000000..14cb5fad915 --- /dev/null +++ b/mysql-test/r/bdb_notembedded.result @@ -0,0 +1,35 @@ +set autocommit=1; +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; insert into bug16206 values(2) +drop table bug16206; +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +show binlog events; +Log_name Pos Event_type Server_id End_log_pos Info +f n Format_desc 1 n Server ver: VERSION, Binlog ver: 4 +f n Query 1 n use `test`; create table bug16206 (a int) engine= bdb +f n Query 1 n use `test`; insert into bug16206 values(0) +f n Query 1 n use `test`; insert into bug16206 values(1) +f n Query 1 n use `test`; BEGIN +f n Query 1 n use `test`; insert into bug16206 values(2) +f n Query 1 n use `test`; COMMIT +f n Query 1 n use `test`; insert into bug16206 values(3) +drop table bug16206; +set autocommit=0; +End of 5.0 tests diff --git a/mysql-test/r/subselect3.result b/mysql-test/r/subselect3.result index 33e7fc54ed2..f52249db8a1 100644 --- a/mysql-test/r/subselect3.result +++ b/mysql-test/r/subselect3.result @@ -692,3 +692,22 @@ a MAX(b) test 2 3 h 3 4 i DROP TABLE t1, t2; +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int, PRIMARY KEY(b)); +INSERT INTO t1 VALUES (1), (NULL), (4); +INSERT INTO t2 VALUES (3), (1),(2), (5), (4), (7), (6); +EXPLAIN EXTENDED +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1)); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 Using where +1 PRIMARY t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index +2 DEPENDENT SUBQUERY t1 ALL NULL NULL NULL NULL 3 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` join `test`.`t2` where ((`test`.`t2`.`b` = `test`.`t1`.`a`) and (not((`test`.`t1`.`a`,(select 1 AS `Not_used` from `test`.`t1` where (((`test`.`t2`.`b`) = `test`.`t1`.`a`) or isnull(`test`.`t1`.`a`)) having (`test`.`t1`.`a`)))))) +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1)); +a +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4)); +a +1 +4 +DROP TABLE t1,t2; diff --git a/mysql-test/t/bdb_notembedded.test b/mysql-test/t/bdb_notembedded.test new file mode 100644 index 00000000000..24e64ebbfb2 --- /dev/null +++ b/mysql-test/t/bdb_notembedded.test @@ -0,0 +1,38 @@ +-- source include/not_embedded.inc +-- source include/have_bdb.inc + +# +# Bug #16206: Superfluous COMMIT event in binlog when updating BDB in autocommit mode +# +set autocommit=1; + +let $VERSION=`select version()`; + +reset master; +create table bug16206 (a int); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +reset master; +create table bug16206 (a int) engine= bdb; +insert into bug16206 values(0); +insert into bug16206 values(1); +start transaction; +insert into bug16206 values(2); +commit; +insert into bug16206 values(3); +--replace_result $VERSION VERSION +--replace_column 1 f 2 n 5 n +show binlog events; +drop table bug16206; + +set autocommit=0; + + +--echo End of 5.0 tests diff --git a/mysql-test/t/subselect3.test b/mysql-test/t/subselect3.test index 11468cd6759..dfe09968fa2 100644 --- a/mysql-test/t/subselect3.test +++ b/mysql-test/t/subselect3.test @@ -528,3 +528,21 @@ SELECT a, MAX(b), DROP TABLE t1, t2; + + +# +# Bug #27870: crash of an equijoin query with WHERE condition containing +# a subquery predicate of the form NOT IN (SELECT ...) +# + +CREATE TABLE t1 (a int); +CREATE TABLE t2 (b int, PRIMARY KEY(b)); +INSERT INTO t1 VALUES (1), (NULL), (4); +INSERT INTO t2 VALUES (3), (1),(2), (5), (4), (7), (6); + +EXPLAIN EXTENDED +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1)); +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1)); +SELECT a FROM t1, t2 WHERE a=b AND (b NOT IN (SELECT a FROM t1 WHERE a > 4)); + +DROP TABLE t1,t2; diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 6b605e96432..118609671b8 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -276,7 +276,11 @@ public: { return pushed_cond_guards ? pushed_cond_guards + i : NULL; } - void set_cond_guard_var(int i, bool v) { pushed_cond_guards[i]= v; } + void set_cond_guard_var(int i, bool v) + { + if ( pushed_cond_guards) + pushed_cond_guards[i]= v; + } bool have_guarded_conds() { return test(pushed_cond_guards); } Item_func_not_all *upper_item; // point on NOT/NOP before ALL/SOME subquery From 09db49764281b944393331d8fc8f859ab9557498 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 19 Apr 2007 16:49:21 +0500 Subject: [PATCH 09/13] Bug#27499 DROP TABLE race with SHOW TABLE STATUS They can drop table after table names list creation and before table opening. We open non existing table and get ER_NO_SUCH_TABLE error. In this case we do not store the record into I_S table and clear error. sql/sql_show.cc: Hide error for not existing table --- sql/sql_show.cc | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 0c9ea7b0bbf..ff3f76f446c 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2314,18 +2314,32 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond) res= open_normal_and_derived_tables(thd, show_table_list, MYSQL_LOCK_IGNORE_FLUSH); lex->sql_command= save_sql_command; - /* - We should use show_table_list->alias instead of - show_table_list->table_name because table_name - could be changed during opening of I_S tables. It's safe - to use alias because alias contains original table name - in this case. + /* + They can drop table after table names list creation and + before table opening. We open non existing table and + get ER_NO_SUCH_TABLE error. In this case we do not store + the record into I_S table and clear error. */ - res= schema_table->process_table(thd, show_table_list, table, - res, orig_base_name, - show_table_list->alias); - close_tables_for_reopen(thd, &show_table_list); - DBUG_ASSERT(!lex->query_tables_own_last); + if (thd->net.last_errno == ER_NO_SUCH_TABLE) + { + res= 0; + thd->clear_error(); + } + else + { + /* + We should use show_table_list->alias instead of + show_table_list->table_name because table_name + could be changed during opening of I_S tables. It's safe + to use alias because alias contains original table name + in this case. + */ + res= schema_table->process_table(thd, show_table_list, table, + res, orig_base_name, + show_table_list->alias); + close_tables_for_reopen(thd, &show_table_list); + DBUG_ASSERT(!lex->query_tables_own_last); + } if (res) goto err; } From e0444ba436798b25c16bfe0097b87cc1d39a7b9a Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Apr 2007 10:49:45 +0300 Subject: [PATCH 10/13] Bug #27786: When merging views into the enclosing statement the ORDER BY clause of the view is merged to the parent's ORDER BY clause. However when the VIEW is merged into an UNION branch the ORDER BY should be ignored. Use of ORDER BY for individual SELECT statements implies nothing about the order in which the rows appear in the final result because UNION by default produces unordered set of rows. Fixed by ignoring the ORDER BY clause from the merge view when expanded in an UNION branch. mysql-test/r/view.result: Bug #27786: test case mysql-test/t/view.test: Bug #27786: test case sql/sql_lex.h: Bug #27786: add a is_union() inlined function Returns true if the unit represents an UNION. sql/sql_view.cc: Bug #27786: ignore ORDER BY in mergeable views when in UNION context --- mysql-test/r/view.result | 35 +++++++++++++++++++++++++++++++++++ mysql-test/t/view.test | 16 ++++++++++++++++ sql/sql_lex.h | 8 ++++++++ sql/sql_view.cc | 9 +++++++-- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 71d743f37b9..70dd6b2550f 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3319,4 +3319,39 @@ lgid clid 2 YES DROP VIEW v1; DROP table t1,t2; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a; +SELECT * FROM t1 UNION SELECT * FROM v1; +a +1 +2 +3 +EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 UNION t1 ALL NULL NULL NULL NULL 3 +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT * FROM v1 UNION SELECT * FROM t1; +a +1 +2 +3 +EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 UNION t1 ALL NULL NULL NULL NULL 3 +NULL UNION RESULT ALL NULL NULL NULL NULL NULL +SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; +a +1 +2 +3 +EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 UNION t1 ALL NULL NULL NULL NULL 3 +NULL UNION RESULT ALL NULL NULL NULL NULL NULL Using filesort +DROP VIEW v1; +DROP TABLE t1; End of 5.0 tests. diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index 920fcee3b24..e5bf9de13eb 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3205,4 +3205,20 @@ SELECT * FROM v1; DROP VIEW v1; DROP table t1,t2; +# +# Bug#27786: Inconsistent Operation Performing UNION On View With ORDER BY +# +CREATE TABLE t1 (a INT); INSERT INTO t1 VALUES (1),(2),(3); +CREATE VIEW v1 AS SELECT a FROM t1 ORDER BY a; + +SELECT * FROM t1 UNION SELECT * FROM v1; +EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1; +SELECT * FROM v1 UNION SELECT * FROM t1; +EXPLAIN SELECT * FROM v1 UNION SELECT * FROM t1; +SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; +EXPLAIN SELECT * FROM t1 UNION SELECT * FROM v1 ORDER BY a; + +DROP VIEW v1; +DROP TABLE t1; + --echo End of 5.0 tests. diff --git a/sql/sql_lex.h b/sql/sql_lex.h index de7de0d46e9..2ff29d684d1 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -468,6 +468,7 @@ public: bool change_result(select_subselect *result, select_subselect *old_result); void set_limit(st_select_lex *values); void set_thd(THD *thd_arg) { thd= thd_arg; } + inline bool is_union (); friend void lex_start(THD *thd, uchar *buf, uint length); friend int subselect_union_engine::exec(); @@ -700,6 +701,13 @@ public: }; typedef class st_select_lex SELECT_LEX; + +inline bool st_select_lex_unit::is_union () +{ + return first_select()->next_select() && + first_select()->next_select()->linkage == UNION_TYPE; +} + #define ALTER_ADD_COLUMN 1 #define ALTER_DROP_COLUMN 2 #define ALTER_CHANGE_COLUMN 4 diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 83beec3d1be..95dec40450f 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1263,13 +1263,18 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, unit->slave= save_slave; // fix include_down initialisation } + /* + We can safely ignore the VIEW's ORDER BY if we merge into union + branch, as order is not important there. + */ + if (!table->select_lex->master_unit()->is_union()) + table->select_lex->order_list.push_back(&lex->select_lex.order_list); /* This SELECT_LEX will be linked in global SELECT_LEX list to make it processed by mysql_handle_derived(), but it will not be included to SELECT_LEX tree, because it will not be executed - */ - table->select_lex->order_list.push_back(&lex->select_lex.order_list); + */ goto ok; } From f3e261a99786291c076f1637002b7caaee828c32 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Apr 2007 11:01:53 +0200 Subject: [PATCH 11/13] Bug #24778: Innodb: No result when using ORDER BY This bug was intruduced by the fix for bug#17212 (in 4.1). It is not ok to call test_if_skip_sort_order since this function will alter the execution plan. By contract it is not ok to call test_if_skip_sort_order in this context. This bug appears only in the case when the optimizer has chosen an index for accessing a particular table but finds a covering index that enables it to skip ORDER BY. This happens in test_if_skip_sort_order. mysql-test/r/key.result: Bug#24778 test case. The bug causes the result to be the empty set. mysql-test/t/key.test: Bug#24778 The minimal test case that reveals the bug. The reason for such a complicated schema is that we have to convince the optimizer to pick one index, then discard it in order to be able to skip ORDER BY. sql/sql_select.cc: bug#24778 Removed the call to test_if_skip_sort_order that constituted the bug. --- mysql-test/r/key.result | 41 +++++++++++++++++++++++++++++++++++ mysql-test/t/key.test | 48 +++++++++++++++++++++++++++++++++++++++++ sql/sql_select.cc | 5 +---- 3 files changed, 90 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/key.result b/mysql-test/r/key.result index eea884e4294..ec15eaa97f5 100644 --- a/mysql-test/r/key.result +++ b/mysql-test/r/key.result @@ -414,3 +414,44 @@ a int(11) NO PRI b varchar(20) NO MUL c varchar(20) NO drop table t1; +CREATE TABLE t1 ( +a INTEGER auto_increment PRIMARY KEY, +b INTEGER NOT NULL, +c INTEGER NOT NULL, +d CHAR(64) +); +CREATE TABLE t2 ( +a INTEGER auto_increment PRIMARY KEY, +b INTEGER NOT NULL, +c SMALLINT NOT NULL, +d DATETIME NOT NULL, +e SMALLINT NOT NULL, +f INTEGER NOT NULL, +g INTEGER NOT NULL, +h SMALLINT NOT NULL, +i INTEGER NOT NULL, +j INTEGER NOT NULL, +UNIQUE INDEX (b), +INDEX (b, d, e, f, g, h, i, j, c), +INDEX (c) +); +INSERT INTO t2 VALUES +(NULL, 1, 254, '1000-01-01 00:00:00', 257, 0, 0, 0, 0, 0), +(NULL, 2, 1, '2004-11-30 12:00:00', 1, 0, 0, 0, 0, 0), +(NULL, 3, 1, '2004-11-30 12:00:00', 1, 0, 0, 2, -21600, 0), +(NULL, 4, 1, '2004-11-30 12:00:00', 1, 0, 0, 2, -10800, 0), +(NULL, 5, 1, '2004-11-30 12:00:00', 1, 0, 0, 5, -10800, 0), +(NULL, 6, 1, '2004-11-30 12:00:00', 102, 0, 0, 0, 0, 0), +(NULL, 7, 1, '2004-11-30 12:00:00', 105, 2, 0, 0, 0, 0), +(NULL, 8, 1, '2004-11-30 12:00:00', 105, 10, 0, 0, 0, 0); +INSERT INTO t1 (b, c, d) VALUES +(3388000, -553000, NULL), +(3388000, -553000, NULL); +SELECT * +FROM t2 c JOIN t1 pa ON c.b = pa.a +WHERE c.c = 1 +ORDER BY c.b, c.d +; +a b c d e f g h i j a b c d +2 2 1 2004-11-30 12:00:00 1 0 0 0 0 0 2 3388000 -553000 NULL +DROP TABLE t1, t2; diff --git a/mysql-test/t/key.test b/mysql-test/t/key.test index 3767f5f885e..e84b2071ab1 100644 --- a/mysql-test/t/key.test +++ b/mysql-test/t/key.test @@ -384,3 +384,51 @@ desc t1; drop table t1; # End of 4.1 tests + +# +# Bug #24778: Innodb: No result when using ORDER BY +# +CREATE TABLE t1 ( + a INTEGER auto_increment PRIMARY KEY, + b INTEGER NOT NULL, + c INTEGER NOT NULL, + d CHAR(64) +); + +CREATE TABLE t2 ( + a INTEGER auto_increment PRIMARY KEY, + b INTEGER NOT NULL, + c SMALLINT NOT NULL, + d DATETIME NOT NULL, + e SMALLINT NOT NULL, + f INTEGER NOT NULL, + g INTEGER NOT NULL, + h SMALLINT NOT NULL, + i INTEGER NOT NULL, + j INTEGER NOT NULL, + UNIQUE INDEX (b), + INDEX (b, d, e, f, g, h, i, j, c), + INDEX (c) +); + +INSERT INTO t2 VALUES + (NULL, 1, 254, '1000-01-01 00:00:00', 257, 0, 0, 0, 0, 0), + (NULL, 2, 1, '2004-11-30 12:00:00', 1, 0, 0, 0, 0, 0), + (NULL, 3, 1, '2004-11-30 12:00:00', 1, 0, 0, 2, -21600, 0), + (NULL, 4, 1, '2004-11-30 12:00:00', 1, 0, 0, 2, -10800, 0), + (NULL, 5, 1, '2004-11-30 12:00:00', 1, 0, 0, 5, -10800, 0), + (NULL, 6, 1, '2004-11-30 12:00:00', 102, 0, 0, 0, 0, 0), + (NULL, 7, 1, '2004-11-30 12:00:00', 105, 2, 0, 0, 0, 0), + (NULL, 8, 1, '2004-11-30 12:00:00', 105, 10, 0, 0, 0, 0); + +INSERT INTO t1 (b, c, d) VALUES + (3388000, -553000, NULL), + (3388000, -553000, NULL); + +SELECT * +FROM t2 c JOIN t1 pa ON c.b = pa.a +WHERE c.c = 1 +ORDER BY c.b, c.d +; + +DROP TABLE t1, t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index dc018dd43bb..77565ca8f7b 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -5982,10 +5982,7 @@ make_join_readinfo(JOIN *join, ulonglong options) */ if (!ordered_set && (table == join->sort_by_table && - (!join->order || join->skip_sort_order || - test_if_skip_sort_order(tab, join->order, join->select_limit, - 1)) - ) || + (!join->order || join->skip_sort_order)) || (join->sort_by_table == (TABLE *) 1 && i != join->const_tables)) ordered_set= 1; From a8f639fccc19ef80d67c52e698bf6366fdcf6f94 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Apr 2007 15:14:09 +0500 Subject: [PATCH 12/13] Bug#27704: incorrect comparison of rows with NULL components Support for NULL components was incomplete for row comparison, fixed. Added support for abort_on_null at compare_row() like in 5.x sql/item_cmpfunc.h: Bug#27704: incorrect comparison of rows with NULL components Added support for abort_on_null at Item_bool_func2 like in 5.x sql/item_cmpfunc.cc: Bug#27704: incorrect comparison of rows with NULL components Support for NULL components was incomplete for row comparison, fixed. Added support for abort_on_null at compare_row() like in 5.x mysql-test/t/row.test: Test case updated for Bug#27704 (incorrect comparison of rows with NULL components) mysql-test/r/row.result: Test case updated for Bug#27704 (incorrect comparison of rows with NULL components) mysql-test/r/subselect.result: Test case updated for Bug#27704 (incorrect comparison of rows with NULL components) --- mysql-test/r/row.result | 99 ++++++++++++++++++++++++++++++++++- mysql-test/r/subselect.result | 4 +- mysql-test/t/row.test | 45 ++++++++++++++++ sql/item_cmpfunc.cc | 36 +++++++++++-- sql/item_cmpfunc.h | 4 +- 5 files changed, 180 insertions(+), 8 deletions(-) diff --git a/mysql-test/r/row.result b/mysql-test/r/row.result index 1c1c4809f36..6169619712b 100644 --- a/mysql-test/r/row.result +++ b/mysql-test/r/row.result @@ -53,7 +53,7 @@ SELECT (1,2,3)=(1,NULL,3); NULL SELECT (1,2,3)=(1,NULL,0); (1,2,3)=(1,NULL,0) -NULL +0 SELECT ROW(1,2,3)=ROW(1,2,3); ROW(1,2,3)=ROW(1,2,3) 1 @@ -188,3 +188,100 @@ SELECT ROW(2,1) IN (ROW(21,2),ROW(ROW(1,1,3),0)); ERROR 21000: Operand should contain 1 column(s) SELECT ROW(2,1) IN (ROW(ROW(1,1,3),0),ROW(21,2)); ERROR 21000: Operand should contain 1 column(s) +CREATE TABLE t1(a int, b int, c int); +INSERT INTO t1 VALUES (1, 2, 3), +(NULL, 2, 3 ), (1, NULL, 3 ), (1, 2, NULL), +(NULL, 2, 3+1), (1, NULL, 3+1), (1, 2+1, NULL), +(NULL, 2, 3-1), (1, NULL, 3-1), (1, 2-1, NULL); +SELECT (1,2,3) = (1, NULL, 3); +(1,2,3) = (1, NULL, 3) +NULL +SELECT (1,2,3) = (1+1, NULL, 3); +(1,2,3) = (1+1, NULL, 3) +0 +SELECT (1,2,3) = (1, NULL, 3+1); +(1,2,3) = (1, NULL, 3+1) +0 +SELECT * FROM t1 WHERE (a,b,c) = (1,2,3); +a b c +1 2 3 +SELECT (1,2,3) <> (1, NULL, 3); +(1,2,3) <> (1, NULL, 3) +NULL +SELECT (1,2,3) <> (1+1, NULL, 3); +(1,2,3) <> (1+1, NULL, 3) +1 +SELECT (1,2,3) <> (1, NULL, 3+1); +(1,2,3) <> (1, NULL, 3+1) +1 +SELECT * FROM t1 WHERE (a,b,c) <> (1,2,3); +a b c +NULL 2 4 +1 NULL 4 +1 3 NULL +NULL 2 2 +1 NULL 2 +1 1 NULL +SELECT (1,2,3) < (NULL, 2, 3); +(1,2,3) < (NULL, 2, 3) +NULL +SELECT (1,2,3) < (1, NULL, 3); +(1,2,3) < (1, NULL, 3) +NULL +SELECT (1,2,3) < (1-1, NULL, 3); +(1,2,3) < (1-1, NULL, 3) +0 +SELECT (1,2,3) < (1+1, NULL, 3); +(1,2,3) < (1+1, NULL, 3) +1 +SELECT * FROM t1 WHERE (a,b,c) < (1,2,3); +a b c +1 1 NULL +SELECT (1,2,3) <= (NULL, 2, 3); +(1,2,3) <= (NULL, 2, 3) +NULL +SELECT (1,2,3) <= (1, NULL, 3); +(1,2,3) <= (1, NULL, 3) +NULL +SELECT (1,2,3) <= (1-1, NULL, 3); +(1,2,3) <= (1-1, NULL, 3) +0 +SELECT (1,2,3) <= (1+1, NULL, 3); +(1,2,3) <= (1+1, NULL, 3) +1 +SELECT * FROM t1 WHERE (a,b,c) <= (1,2,3); +a b c +1 2 3 +1 1 NULL +SELECT (1,2,3) > (NULL, 2, 3); +(1,2,3) > (NULL, 2, 3) +NULL +SELECT (1,2,3) > (1, NULL, 3); +(1,2,3) > (1, NULL, 3) +NULL +SELECT (1,2,3) > (1-1, NULL, 3); +(1,2,3) > (1-1, NULL, 3) +1 +SELECT (1,2,3) > (1+1, NULL, 3); +(1,2,3) > (1+1, NULL, 3) +0 +SELECT * FROM t1 WHERE (a,b,c) > (1,2,3); +a b c +1 3 NULL +SELECT (1,2,3) >= (NULL, 2, 3); +(1,2,3) >= (NULL, 2, 3) +NULL +SELECT (1,2,3) >= (1, NULL, 3); +(1,2,3) >= (1, NULL, 3) +NULL +SELECT (1,2,3) >= (1-1, NULL, 3); +(1,2,3) >= (1-1, NULL, 3) +1 +SELECT (1,2,3) >= (1+1, NULL, 3); +(1,2,3) >= (1+1, NULL, 3) +0 +SELECT * FROM t1 WHERE (a,b,c) >= (1,2,3); +a b c +1 2 3 +1 3 NULL +DROP TABLE t1; diff --git a/mysql-test/r/subselect.result b/mysql-test/r/subselect.result index a339a139687..5bb79a53771 100644 --- a/mysql-test/r/subselect.result +++ b/mysql-test/r/subselect.result @@ -913,7 +913,7 @@ select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a'),(select c from t a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,2,'a') (select c from t1 where a=t2.a) 1 1 a 2 0 b -NULL NULL NULL +NULL 0 NULL select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b'),(select c from t1 where a=t2.a) from t2; a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,3,'b') (select c from t1 where a=t2.a) 1 0 a @@ -923,7 +923,7 @@ select a, (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c'),(select c from t a (select a,b,c from t1 where t1.a=t2.a) = ROW(a,4,'c') (select c from t1 where a=t2.a) 1 0 a 2 0 b -NULL NULL NULL +NULL 0 NULL drop table t1,t2; create table t1 (a int, b real, c varchar(10)); insert into t1 values (1, 1, 'a'), (2,2,'b'), (NULL, 2, 'b'); diff --git a/mysql-test/t/row.test b/mysql-test/t/row.test index 6c66d45b942..6f845607d8c 100644 --- a/mysql-test/t/row.test +++ b/mysql-test/t/row.test @@ -108,4 +108,49 @@ SELECT ROW(2,1) IN (ROW(21,2),ROW(ROW(1,1,3),0)); --error 1241 SELECT ROW(2,1) IN (ROW(ROW(1,1,3),0),ROW(21,2)); +# +# Bug#27704: erroneous comparison of rows with NULL components +# +CREATE TABLE t1(a int, b int, c int); +INSERT INTO t1 VALUES (1, 2, 3), + (NULL, 2, 3 ), (1, NULL, 3 ), (1, 2, NULL), + (NULL, 2, 3+1), (1, NULL, 3+1), (1, 2+1, NULL), + (NULL, 2, 3-1), (1, NULL, 3-1), (1, 2-1, NULL); + +SELECT (1,2,3) = (1, NULL, 3); +SELECT (1,2,3) = (1+1, NULL, 3); +SELECT (1,2,3) = (1, NULL, 3+1); +SELECT * FROM t1 WHERE (a,b,c) = (1,2,3); + +SELECT (1,2,3) <> (1, NULL, 3); +SELECT (1,2,3) <> (1+1, NULL, 3); +SELECT (1,2,3) <> (1, NULL, 3+1); +SELECT * FROM t1 WHERE (a,b,c) <> (1,2,3); + +SELECT (1,2,3) < (NULL, 2, 3); +SELECT (1,2,3) < (1, NULL, 3); +SELECT (1,2,3) < (1-1, NULL, 3); +SELECT (1,2,3) < (1+1, NULL, 3); +SELECT * FROM t1 WHERE (a,b,c) < (1,2,3); + +SELECT (1,2,3) <= (NULL, 2, 3); +SELECT (1,2,3) <= (1, NULL, 3); +SELECT (1,2,3) <= (1-1, NULL, 3); +SELECT (1,2,3) <= (1+1, NULL, 3); +SELECT * FROM t1 WHERE (a,b,c) <= (1,2,3); + +SELECT (1,2,3) > (NULL, 2, 3); +SELECT (1,2,3) > (1, NULL, 3); +SELECT (1,2,3) > (1-1, NULL, 3); +SELECT (1,2,3) > (1+1, NULL, 3); +SELECT * FROM t1 WHERE (a,b,c) > (1,2,3); + +SELECT (1,2,3) >= (NULL, 2, 3); +SELECT (1,2,3) >= (1, NULL, 3); +SELECT (1,2,3) >= (1-1, NULL, 3); +SELECT (1,2,3) >= (1+1, NULL, 3); +SELECT * FROM t1 WHERE (a,b,c) >= (1,2,3); + +DROP TABLE t1; + # End of 4.1 tests diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index ce3096da778..be44d490415 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -680,17 +680,45 @@ int Arg_comparator::compare_e_int_diff_signedness() int Arg_comparator::compare_row() { int res= 0; + bool was_null= 0; (*a)->bring_value(); (*b)->bring_value(); uint n= (*a)->cols(); for (uint i= 0; inull_value) - return -1; + { + // NULL was compared + switch (owner->functype()) { + case Item_func::NE_FUNC: + break; // NE never aborts on NULL even if abort_on_null is set + case Item_func::LT_FUNC: + case Item_func::LE_FUNC: + case Item_func::GT_FUNC: + case Item_func::GE_FUNC: + return -1; // <, <=, > and >= always fail on NULL + default: // EQ_FUNC + if (owner->abort_on_null) + return -1; // We do not need correct NULL returning + } + was_null= 1; + owner->null_value= 0; + res= 0; // continue comparison (maybe we will meet explicit difference) + } + else if (res) + return res; } - return res; + if (was_null) + { + /* + There was NULL(s) in comparison in some parts, but there was no + explicit difference in other parts, so we have to return NULL. + */ + owner->null_value= 1; + return -1; + } + return 0; } int Arg_comparator::compare_e_row() diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 132e019b4a3..7dbbdc7a63b 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -206,10 +206,11 @@ class Item_bool_func2 :public Item_int_func protected: Arg_comparator cmp; String tmp_value1,tmp_value2; + bool abort_on_null; public: Item_bool_func2(Item *a,Item *b) - :Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1) {} + :Item_int_func(a,b), cmp(tmp_arg, tmp_arg+1), abort_on_null(FALSE) {} void fix_length_and_dec(); void set_cmp_func() { @@ -222,6 +223,7 @@ public: bool is_null() { return test(args[0]->is_null() || args[1]->is_null()); } bool is_bool_func() { return 1; } CHARSET_INFO *compare_collation() { return cmp.cmp_collation.collation; } + void top_level_item() { abort_on_null= TRUE; } friend class Arg_comparator; }; From 4a3027aaa22e947c36f398c45a2e77324c6492e4 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 20 Apr 2007 14:08:12 +0200 Subject: [PATCH 13/13] Added missing result file for rpl_critical_errors. mysql-test/r/rpl_critical_errors.result: New BitKeeper file ``mysql-test/r/rpl_critical_errors.result'' --- mysql-test/r/rpl_critical_errors.result | 1 + 1 file changed, 1 insertion(+) create mode 100644 mysql-test/r/rpl_critical_errors.result diff --git a/mysql-test/r/rpl_critical_errors.result b/mysql-test/r/rpl_critical_errors.result new file mode 100644 index 00000000000..bcc53565084 --- /dev/null +++ b/mysql-test/r/rpl_critical_errors.result @@ -0,0 +1 @@ +Turn on parsing to run this test