From 0f0d4720b840c2e3d2c42f9b071c87a048cb558a Mon Sep 17 00:00:00 2001 From: "igor@olga.mysql.com" <> Date: Thu, 14 Jun 2007 18:55:07 -0700 Subject: [PATCH 01/22] Fixed bug #27932: the function LOCATE returned NULL if any of its arguments was evaluated to NULL, while the predicate LOCATE(str,NULL) IS NULL erroneously was evaluated to FALSE. This happened because the Item_func_locate::fix_length_and_dec method by mistake set the value of the maybe_null flag for the function item to 0. In consequence of this the function was considered as the one that could not ever return NULL. --- mysql-test/r/func_str.result | 76 ++++++++++++++++++++++++++++++++++++ mysql-test/t/func_str.test | 33 ++++++++++++++++ sql/item_func.cc | 1 - 3 files changed, 109 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index d8afbe13c76..e79670b3f76 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -2061,4 +2061,80 @@ C 2707236321 DROP TABLE t1, t2; DROP VIEW v1; +SELECT LOCATE('foo', NULL) FROM DUAL; +LOCATE('foo', NULL) +NULL +SELECT LOCATE(NULL, 'o') FROM DUAL; +LOCATE(NULL, 'o') +NULL +SELECT LOCATE(NULL, NULL) FROM DUAL; +LOCATE(NULL, NULL) +NULL +SELECT LOCATE('foo', NULL) IS NULL FROM DUAL; +LOCATE('foo', NULL) IS NULL +1 +SELECT LOCATE(NULL, 'o') IS NULL FROM DUAL; +LOCATE(NULL, 'o') IS NULL +1 +SELECT LOCATE(NULL, NULL) IS NULL FROM DUAL; +LOCATE(NULL, NULL) IS NULL +1 +SELECT ISNULL(LOCATE('foo', NULL)) FROM DUAL; +ISNULL(LOCATE('foo', NULL)) +1 +SELECT ISNULL(LOCATE(NULL, 'o')) FROM DUAL; +ISNULL(LOCATE(NULL, 'o')) +1 +SELECT ISNULL(LOCATE(NULL, NULL)) FROM DUAL; +ISNULL(LOCATE(NULL, NULL)) +1 +SELECT LOCATE('foo', NULL) <=> NULL FROM DUAL; +LOCATE('foo', NULL) <=> NULL +1 +SELECT LOCATE(NULL, 'o') <=> NULL FROM DUAL; +LOCATE(NULL, 'o') <=> NULL +1 +SELECT LOCATE(NULL, NULL) <=> NULL FROM DUAL; +LOCATE(NULL, NULL) <=> NULL +1 +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a varchar(10), p varchar(10)); +INSERT INTO t1 VALUES (1, 'foo', 'o'); +INSERT INTO t1 VALUES (2, 'foo', NULL); +INSERT INTO t1 VALUES (3, NULL, 'o'); +INSERT INTO t1 VALUES (4, NULL, NULL); +SELECT id, LOCATE(a,p) FROM t1; +id LOCATE(a,p) +1 0 +2 NULL +3 NULL +4 NULL +SELECT id, LOCATE(a,p) IS NULL FROM t1; +id LOCATE(a,p) IS NULL +1 0 +2 1 +3 1 +4 1 +SELECT id, ISNULL(LOCATE(a,p)) FROM t1; +id ISNULL(LOCATE(a,p)) +1 0 +2 1 +3 1 +4 1 +SELECT id, LOCATE(a,p) <=> NULL FROM t1; +id LOCATE(a,p) <=> NULL +1 0 +2 1 +3 1 +4 1 +SELECT id FROM t1 WHERE LOCATE(a,p) IS NULL; +id +2 +3 +4 +SELECT id FROM t1 WHERE LOCATE(a,p) <=> NULL; +id +2 +3 +4 +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index bca977e6df3..c8fd06cd1cd 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -1076,4 +1076,37 @@ SELECT * FROM (SELECT * FROM v1) x; DROP TABLE t1, t2; DROP VIEW v1; +# +# Bug #27932: LOCATE with argument evaluated to NULL +# + +SELECT LOCATE('foo', NULL) FROM DUAL; +SELECT LOCATE(NULL, 'o') FROM DUAL; +SELECT LOCATE(NULL, NULL) FROM DUAL; +SELECT LOCATE('foo', NULL) IS NULL FROM DUAL; +SELECT LOCATE(NULL, 'o') IS NULL FROM DUAL; +SELECT LOCATE(NULL, NULL) IS NULL FROM DUAL; +SELECT ISNULL(LOCATE('foo', NULL)) FROM DUAL; +SELECT ISNULL(LOCATE(NULL, 'o')) FROM DUAL; +SELECT ISNULL(LOCATE(NULL, NULL)) FROM DUAL; +SELECT LOCATE('foo', NULL) <=> NULL FROM DUAL; +SELECT LOCATE(NULL, 'o') <=> NULL FROM DUAL; +SELECT LOCATE(NULL, NULL) <=> NULL FROM DUAL; + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, a varchar(10), p varchar(10)); + +INSERT INTO t1 VALUES (1, 'foo', 'o'); +INSERT INTO t1 VALUES (2, 'foo', NULL); +INSERT INTO t1 VALUES (3, NULL, 'o'); +INSERT INTO t1 VALUES (4, NULL, NULL); + +SELECT id, LOCATE(a,p) FROM t1; +SELECT id, LOCATE(a,p) IS NULL FROM t1; +SELECT id, ISNULL(LOCATE(a,p)) FROM t1; +SELECT id, LOCATE(a,p) <=> NULL FROM t1; +SELECT id FROM t1 WHERE LOCATE(a,p) IS NULL; +SELECT id FROM t1 WHERE LOCATE(a,p) <=> NULL; + +DROP TABLE t1; + --echo End of 5.0 tests diff --git a/sql/item_func.cc b/sql/item_func.cc index ab4a9c50332..17a2c584e9d 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -2507,7 +2507,6 @@ longlong Item_func_coercibility::val_int() void Item_func_locate::fix_length_and_dec() { - maybe_null= 0; max_length= MY_INT32_NUM_DECIMAL_DIGITS; agg_arg_charsets(cmp_collation, args, 2, MY_COLL_CMP_CONV, 1); } From 8f09a374ea168ef09ba1bc0b5ddf87eeb89df120 Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Sat, 16 Jun 2007 13:05:07 +0500 Subject: [PATCH 02/22] Fixed bug #28625: DECIMAL column was used instead of BIGINT for the minimal possible BIGINT (-9223372036854775808). The Item_func_neg::fix_length_and_dec has been adjusted to to inherit the type of the argument in the case when it's an Item_int object whose value is equal to LONGLONG_MIN. --- mysql-test/r/bigint.result | 26 ++++++++++++++++++++++++++ mysql-test/t/bigint.test | 13 +++++++++++++ sql/item_func.cc | 22 +++++++++++++--------- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/mysql-test/r/bigint.result b/mysql-test/r/bigint.result index f18d1c9b583..064304b27aa 100644 --- a/mysql-test/r/bigint.result +++ b/mysql-test/r/bigint.result @@ -362,3 +362,29 @@ cast(-19999999999999999999 as signed) -9223372036854775808 Warnings: Error 1292 Truncated incorrect DECIMAL value: '' +select -9223372036854775808; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def -9223372036854775808 8 20 20 N 32897 0 63 +-9223372036854775808 +-9223372036854775808 +select -(9223372036854775808); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def -(9223372036854775808) 8 20 20 N 32897 0 63 +-(9223372036854775808) +-9223372036854775808 +select -((9223372036854775808)); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def -((9223372036854775808)) 8 20 20 N 32897 0 63 +-((9223372036854775808)) +-9223372036854775808 +select -(-(9223372036854775808)); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def -(-(9223372036854775808)) 246 21 19 N 129 0 63 +-(-(9223372036854775808)) +9223372036854775808 +select --9223372036854775808, ---9223372036854775808, ----9223372036854775808; +--9223372036854775808 ---9223372036854775808 ----9223372036854775808 +9223372036854775808 -9223372036854775808 9223372036854775808 +select -(-9223372036854775808), -(-(-9223372036854775808)); +-(-9223372036854775808) -(-(-9223372036854775808)) +9223372036854775808 -9223372036854775808 diff --git a/mysql-test/t/bigint.test b/mysql-test/t/bigint.test index 9a5fb11229d..1f0f7763e87 100644 --- a/mysql-test/t/bigint.test +++ b/mysql-test/t/bigint.test @@ -294,3 +294,16 @@ drop table t1; select cast(19999999999999999999 as signed); select cast(-19999999999999999999 as signed); + +# +# Bug #28625: -9223372036854775808 doesn't fit in BIGINT. +# + +--enable_metadata +select -9223372036854775808; +select -(9223372036854775808); +select -((9223372036854775808)); +select -(-(9223372036854775808)); +--disable_metadata +select --9223372036854775808, ---9223372036854775808, ----9223372036854775808; +select -(-9223372036854775808), -(-(-9223372036854775808)); diff --git a/sql/item_func.cc b/sql/item_func.cc index 95ff432ca5a..487e91e4917 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -1523,16 +1523,20 @@ void Item_func_neg::fix_length_and_dec() Use val() to get value as arg_type doesn't mean that item is Item_int or Item_real due to existence of Item_param. */ - if (hybrid_type == INT_RESULT && - args[0]->type() == INT_ITEM && - ((ulonglong) args[0]->val_int() >= (ulonglong) LONGLONG_MIN)) + if (hybrid_type == INT_RESULT && args[0]->const_item()) { - /* - Ensure that result is converted to DECIMAL, as longlong can't hold - the negated number - */ - hybrid_type= DECIMAL_RESULT; - DBUG_PRINT("info", ("Type changed: DECIMAL_RESULT")); + longlong val= args[0]->val_int(); + if ((ulonglong) val >= (ulonglong) LONGLONG_MIN && + ((ulonglong) val != (ulonglong) LONGLONG_MIN || + args[0]->type() != INT_ITEM)) + { + /* + Ensure that result is converted to DECIMAL, as longlong can't hold + the negated number + */ + hybrid_type= DECIMAL_RESULT; + DBUG_PRINT("info", ("Type changed: DECIMAL_RESULT")); + } } unsigned_flag= 0; DBUG_VOID_RETURN; From dac7ce2d12e39a456b21c4252ef9518ab790c57f Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Sat, 16 Jun 2007 17:00:29 +0500 Subject: [PATCH 03/22] bigint.test: Updated test case for bug #28625. --- mysql-test/t/bigint.test | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mysql-test/t/bigint.test b/mysql-test/t/bigint.test index 1f0f7763e87..4aef7395184 100644 --- a/mysql-test/t/bigint.test +++ b/mysql-test/t/bigint.test @@ -299,11 +299,14 @@ select cast(-19999999999999999999 as signed); # Bug #28625: -9223372036854775808 doesn't fit in BIGINT. # +# PS protocol gives different metadata for `Max length' column +--disable_ps_protocol --enable_metadata select -9223372036854775808; select -(9223372036854775808); select -((9223372036854775808)); select -(-(9223372036854775808)); --disable_metadata +--endble_ps_protocol select --9223372036854775808, ---9223372036854775808, ----9223372036854775808; select -(-9223372036854775808), -(-(-9223372036854775808)); From 63ab91090ddc6ff0588dd4616fb90a77a2036970 Mon Sep 17 00:00:00 2001 From: "igor@olga.mysql.com" <> Date: Sun, 17 Jun 2007 11:23:19 -0700 Subject: [PATCH 04/22] Fixed bug #27130. If the third argument of the function SUBSTR was represented by an expression of the type UNSIGNED INT and this expression was evaluated to 0 then the function erroneously returned the value of the first argument instead of an empty string. This problem was introduced by the patch for bug 10963. The problem has been resolved by a proper modification of the code of Item_func_substr::val_str. --- mysql-test/r/func_str.result | 16 ++++++++++++++++ mysql-test/t/func_str.test | 15 +++++++++++++++ sql/item_strfunc.cc | 5 +++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index d8afbe13c76..0dd7bd8f309 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -2061,4 +2061,20 @@ C 2707236321 DROP TABLE t1, t2; DROP VIEW v1; +SELECT SUBSTR('foo',1,0) FROM DUAL; +SUBSTR('foo',1,0) + +SELECT SUBSTR('foo',1,CAST(0 AS SIGNED)) FROM DUAL; +SUBSTR('foo',1,CAST(0 AS SIGNED)) + +SELECT SUBSTR('foo',1,CAST(0 AS UNSIGNED)) FROM DUAL; +SUBSTR('foo',1,CAST(0 AS UNSIGNED)) + +CREATE TABLE t1 (a varchar(10), len int unsigned); +INSERT INTO t1 VALUES ('bar', 2), ('foo', 0); +SELECT SUBSTR(a,1,len) FROM t1; +SUBSTR(a,1,len) +ba + +DROP TABLE t1; End of 5.0 tests diff --git a/mysql-test/t/func_str.test b/mysql-test/t/func_str.test index bca977e6df3..012e6be2868 100644 --- a/mysql-test/t/func_str.test +++ b/mysql-test/t/func_str.test @@ -1076,4 +1076,19 @@ SELECT * FROM (SELECT * FROM v1) x; DROP TABLE t1, t2; DROP VIEW v1; +# +# Bug #27130: SUBSTR with UNSIGNED 0 as the last argument +# + +SELECT SUBSTR('foo',1,0) FROM DUAL; +SELECT SUBSTR('foo',1,CAST(0 AS SIGNED)) FROM DUAL; +SELECT SUBSTR('foo',1,CAST(0 AS UNSIGNED)) FROM DUAL; + +CREATE TABLE t1 (a varchar(10), len int unsigned); +INSERT INTO t1 VALUES ('bar', 2), ('foo', 0); + +SELECT SUBSTR(a,1,len) FROM t1; + +DROP TABLE t1; + --echo End of 5.0 tests diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 33e9b8de823..0c24f14c8fe 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -1145,8 +1145,9 @@ String *Item_func_substr::val_str(String *str) (arg_count == 3 && args[2]->null_value)))) return 0; /* purecov: inspected */ - /* Negative length, will return empty string. */ - if ((arg_count == 3) && (length <= 0) && !args[2]->unsigned_flag) + /* Negative or zero length, will return empty string. */ + if ((arg_count == 3) && (length <= 0) && + (length == 0 || !args[2]->unsigned_flag)) return &my_empty_string; /* Assumes that the maximum length of a String is < INT_MAX32. */ From c27988f9910cee9a9bbb8d186bdb1028a07307df Mon Sep 17 00:00:00 2001 From: "igor@olga.mysql.com" <> Date: Sun, 17 Jun 2007 11:43:49 -0700 Subject: [PATCH 05/22] Post-merge fix --- mysql-test/r/func_str.result | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/r/func_str.result b/mysql-test/r/func_str.result index d22b184b9ec..ce9633006af 100644 --- a/mysql-test/r/func_str.result +++ b/mysql-test/r/func_str.result @@ -2151,5 +2151,6 @@ INSERT INTO t1 VALUES ('bar', 2), ('foo', 0); SELECT SUBSTR(a,1,len) FROM t1; SUBSTR(a,1,len) ba + DROP TABLE t1; End of 5.0 tests From 5a9d6856dea9c051cd0c7d2f7521494995daeab7 Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Tue, 19 Jun 2007 11:13:11 +0500 Subject: [PATCH 06/22] Bug #29117 (init_file test crashes with embedded server) we use net->vio in my_net_local_init, but in the my_net_init implementation we set it after the call, so work with unspecified net->vio value --- sql/net_serv.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/net_serv.cc b/sql/net_serv.cc index a5a05d381cd..1c356902eae 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -111,13 +111,13 @@ static my_bool net_write_buff(NET *net,const char *packet,ulong len); my_bool my_net_init(NET *net, Vio* vio) { DBUG_ENTER("my_net_init"); + net->vio = vio; my_net_local_init(net); /* Set some limits */ if (!(net->buff=(uchar*) my_malloc((uint32) net->max_packet+ NET_HEADER_SIZE + COMP_HEADER_SIZE, MYF(MY_WME)))) DBUG_RETURN(1); net->buff_end=net->buff+net->max_packet; - net->vio = vio; net->no_send_ok = 0; net->error=0; net->return_errno=0; net->return_status=0; net->pkt_nr=net->compress_pkt_nr=0; From 91f3301c0330984a4aacac3a97cf84cfd741b88a Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Tue, 19 Jun 2007 13:19:20 +0300 Subject: [PATCH 07/22] Bug #29116: Test "rpl_change_master" returns different counters from relay Updated the test to return columns vertically. --- mysql-test/r/rpl_change_master.result | 70 +++++++++++++++++++++++++-- mysql-test/t/rpl_change_master.test | 4 +- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/rpl_change_master.result b/mysql-test/r/rpl_change_master.result index 16e14f5da2e..ec7d3042551 100644 --- a/mysql-test/r/rpl_change_master.result +++ b/mysql-test/r/rpl_change_master.result @@ -15,12 +15,74 @@ select * from t1; n 1 show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 273 slave-relay-bin.000002 258 master-bin.000001 No No 0 0 214 317 None 0 No # +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 273 +Relay_Log_File slave-relay-bin.000002 +Relay_Log_Pos 258 +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +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 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 214 +Relay_Log_Space 317 +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 # change master to master_user='root'; show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 214 # # master-bin.000001 No No 0 0 214 # None 0 No # +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 214 +Relay_Log_File # +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +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 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 214 +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 # select release_lock("a"); release_lock("a") 1 diff --git a/mysql-test/t/rpl_change_master.test b/mysql-test/t/rpl_change_master.test index e7ae798b1a7..acb34b31ea2 100644 --- a/mysql-test/t/rpl_change_master.test +++ b/mysql-test/t/rpl_change_master.test @@ -14,11 +14,11 @@ select * from t1; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 8 # 9 # 23 # 33 # --replace_column 1 # 33 # -show slave status; +query_vertical show slave status; change master to master_user='root'; --replace_result $MASTER_MYPORT MASTER_MYPORT --replace_column 1 # 8 # 9 # 23 # 33 # -show slave status; +query_vertical show slave status; # Will restart from after the values(2), which is bug select release_lock("a"); start slave; From bef15b279be6d5f2230bd27c4a39adb48a559b2b Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Tue, 19 Jun 2007 14:27:53 +0300 Subject: [PATCH 08/22] Bug #26418: Slave out of sync after CREATE/DROP TEMPORARY TABLE + ROLLBACK on master The transaction ability of the storage engines of the tables on the replication master and the replication slave must generally be the same. When the storage engine type of the slave is non-transactional then transactions on the master that mix update of transactional and non-transactional tables should be avoided because they will cause inconsistency of the data between the master's transactional table and the slave's non-transactional table. The effect described by this bug is actually expected. A detailed test case is added (to be merged later to the updated rpl_ddl.test), as there was no coverage by the existing tests. Some code cleanup is also added by this change. --- mysql-test/r/rpl_innodb.result | 70 +++++++++++++++++++++++++++++++++ mysql-test/t/rpl_innodb.test | 71 ++++++++++++++++++++++++++++++++++ sql/events.cc | 21 ++-------- sql/sp.cc | 16 +------- sql/sql_acl.cc | 45 ++++----------------- sql/sql_class.cc | 9 ----- sql/sql_class.h | 1 - sql/sql_delete.cc | 15 +++---- sql/sql_parse.cc | 27 ++----------- sql/sql_rename.cc | 7 +--- sql/sql_tablespace.cc | 6 +-- sql/sql_trigger.cc | 9 +---- sql/sql_udf.cc | 14 +------ sql/sql_view.cc | 7 +--- 14 files changed, 168 insertions(+), 150 deletions(-) diff --git a/mysql-test/r/rpl_innodb.result b/mysql-test/r/rpl_innodb.result index 765de8af458..6dc2c25247f 100644 --- a/mysql-test/r/rpl_innodb.result +++ b/mysql-test/r/rpl_innodb.result @@ -35,3 +35,73 @@ SELECT * FROM t4; id name number 3 XXX 12345 4 XXY 12345 +FLUSH LOGS; +FLUSH LOGS; +DROP DATABASE IF EXISTS mysqltest1; +CREATE DATABASE mysqltest1; +CREATE TEMPORARY TABLE mysqltest1.tmp (f1 BIGINT); +CREATE TABLE mysqltest1.t1 (f1 BIGINT) ENGINE="InnoDB"; +SET AUTOCOMMIT = 0; +-------- switch to slave -------- +SHOW CREATE TABLE mysqltest1.t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `f1` bigint(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +-------- switch to master -------- +INSERT INTO mysqltest1.t1 SET f1= 1; +DROP TEMPORARY TABLE mysqltest1.tmp; +ROLLBACK; +SHOW CREATE TABLE mysqltest1.tmp; +ERROR 42S02: Table 'mysqltest1.tmp' doesn't exist +SELECT COUNT(*) FROM mysqltest1.t1; +COUNT(*) +0 +INSERT INTO mysqltest1.t1 SET f1= 2; +CREATE TEMPORARY TABLE mysqltest1.tmp2(a INT); +ROLLBACK; +SHOW CREATE TABLE mysqltest1.tmp2; +Table Create Table +tmp2 CREATE TEMPORARY TABLE `tmp2` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT COUNT(*) FROM mysqltest1.t1; +COUNT(*) +0 +-------- switch to slave -------- +SHOW CREATE TABLE mysqltest1.tmp; +ERROR 42S02: Table 'mysqltest1.tmp' doesn't exist +SHOW CREATE TABLE mysqltest1.tmp2; +ERROR 42S02: Table 'mysqltest1.tmp2' doesn't exist +SELECT COUNT(*) FROM mysqltest1.t1; +COUNT(*) +2 +FLUSH LOGS; +SHOW BINLOG EVENTS IN 'slave-bin.000002' LIMIT 1,8; +Log_name Pos Event_type Server_id End_log_pos Info +x x x x x DROP DATABASE IF EXISTS mysqltest1 +x x x x x CREATE DATABASE mysqltest1 +x x x x x use `test`; CREATE TEMPORARY TABLE mysqltest1.tmp (f1 BIGINT) +x x x x x use `test`; CREATE TABLE mysqltest1.t1 (f1 BIGINT) ENGINE="InnoDB" +x x x x x use `test`; INSERT INTO mysqltest1.t1 SET f1= 1 +x x x x x use `test`; DROP TEMPORARY TABLE mysqltest1.tmp +x x x x x use `test`; INSERT INTO mysqltest1.t1 SET f1= 2 +x x x x x use `test`; CREATE TEMPORARY TABLE mysqltest1.tmp2(a INT) +-------- switch to master -------- +FLUSH LOGS; +SHOW BINLOG EVENTS IN 'master-bin.000002' LIMIT 1,12; +Log_name Pos Event_type Server_id End_log_pos Info +x x x x x DROP DATABASE IF EXISTS mysqltest1 +x x x x x CREATE DATABASE mysqltest1 +x x x x x use `test`; CREATE TEMPORARY TABLE mysqltest1.tmp (f1 BIGINT) +x x x x x use `test`; CREATE TABLE mysqltest1.t1 (f1 BIGINT) ENGINE="InnoDB" +x x x x x use `test`; BEGIN +x x x x x use `test`; INSERT INTO mysqltest1.t1 SET f1= 1 +x x x x x use `test`; DROP TEMPORARY TABLE mysqltest1.tmp +x x x x x use `test`; ROLLBACK +x x x x x use `test`; BEGIN +x x x x x use `test`; INSERT INTO mysqltest1.t1 SET f1= 2 +x x x x x use `test`; CREATE TEMPORARY TABLE mysqltest1.tmp2(a INT) +x x x x x use `test`; ROLLBACK +DROP DATABASE mysqltest1; +End of 5.1 tests diff --git a/mysql-test/t/rpl_innodb.test b/mysql-test/t/rpl_innodb.test index b88276e2107..f13889349f7 100644 --- a/mysql-test/t/rpl_innodb.test +++ b/mysql-test/t/rpl_innodb.test @@ -44,5 +44,76 @@ connection master; DROP TABLE t4; --enable_query_log sync_slave_with_master; +connection master; # End of 4.1 tests + +# +# Bug #26418: Slave out of sync after CREATE/DROP TEMPORARY TABLE + ROLLBACK +# on master +# +#Note Matthias: to be merged to rpl_ddl.test + +--source include/not_ndb_default.inc + +FLUSH LOGS; +sync_slave_with_master; +FLUSH LOGS; +connection master; +let $engine_type= "InnoDB"; + +--disable_warnings +DROP DATABASE IF EXISTS mysqltest1; +--enable_warnings + +CREATE DATABASE mysqltest1; +CREATE TEMPORARY TABLE mysqltest1.tmp (f1 BIGINT); +eval CREATE TABLE mysqltest1.t1 (f1 BIGINT) ENGINE=$engine_type; +SET AUTOCOMMIT = 0; + +sync_slave_with_master; +--echo -------- switch to slave -------- +connection slave; +SHOW CREATE TABLE mysqltest1.t1; + +--echo -------- switch to master -------- +connection master; +INSERT INTO mysqltest1.t1 SET f1= 1; +DROP TEMPORARY TABLE mysqltest1.tmp; +ROLLBACK; +--error ER_NO_SUCH_TABLE +SHOW CREATE TABLE mysqltest1.tmp; +# Must return no rows here +SELECT COUNT(*) FROM mysqltest1.t1; + +INSERT INTO mysqltest1.t1 SET f1= 2; +CREATE TEMPORARY TABLE mysqltest1.tmp2(a INT); +ROLLBACK; +SHOW CREATE TABLE mysqltest1.tmp2; +# Must return no rows here +SELECT COUNT(*) FROM mysqltest1.t1; + +sync_slave_with_master; +--echo -------- switch to slave -------- +connection slave; +--error ER_NO_SUCH_TABLE +SHOW CREATE TABLE mysqltest1.tmp; +--error ER_NO_SUCH_TABLE +SHOW CREATE TABLE mysqltest1.tmp2; +# has two rows here : as the default is MyISAM and +# it can't be rolled back by the master's ROLLBACK. +SELECT COUNT(*) FROM mysqltest1.t1; +FLUSH LOGS; +--replace_column 1 x 2 x 3 x 4 x 5 x +SHOW BINLOG EVENTS IN 'slave-bin.000002' LIMIT 1,8; + +--echo -------- switch to master -------- +connection master; +FLUSH LOGS; +--replace_column 1 x 2 x 3 x 4 x 5 x +SHOW BINLOG EVENTS IN 'master-bin.000002' LIMIT 1,12; + +DROP DATABASE mysqltest1; +-- source include/master-slave-end.inc + +--echo End of 5.1 tests diff --git a/sql/events.cc b/sql/events.cc index 7838972a5d6..2d1b3c59a4c 100644 --- a/sql/events.cc +++ b/sql/events.cc @@ -425,12 +425,7 @@ Events::create_event(THD *thd, Event_parse_data *parse_data, event_queue->create_event(thd, new_element, &created); /* Binlog the create event. */ DBUG_ASSERT(thd->query && thd->query_length); - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } } pthread_mutex_unlock(&LOCK_event_metadata); @@ -551,12 +546,7 @@ Events::update_event(THD *thd, Event_parse_data *parse_data, new_element); /* Binlog the alter event. */ DBUG_ASSERT(thd->query && thd->query_length); - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } } pthread_mutex_unlock(&LOCK_event_metadata); @@ -631,12 +621,7 @@ Events::drop_event(THD *thd, LEX_STRING dbname, LEX_STRING name, bool if_exists) event_queue->drop_event(thd, dbname, name); /* Binlog the drop event. */ DBUG_ASSERT(thd->query && thd->query_length); - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } pthread_mutex_unlock(&LOCK_event_metadata); DBUG_RETURN(ret); diff --git a/sql/sp.cc b/sql/sp.cc index 49e86f9d07e..0118169ff7c 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -650,13 +650,7 @@ sp_drop_routine(THD *thd, int type, sp_name *name) if (ret == SP_OK) { - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } - + write_bin_log(thd, TRUE, thd->query, thd->query_length); sp_cache_invalidate(); } @@ -723,13 +717,7 @@ sp_update_routine(THD *thd, int type, sp_name *name, st_sp_chistics *chistics) if (ret == SP_OK) { - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } - + write_bin_log(thd, TRUE, thd->query, thd->query_length); sp_cache_invalidate(); } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 59e3c0a7dd4..6d029ba87e4 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3142,12 +3142,7 @@ bool mysql_table_grant(THD *thd, TABLE_LIST *table_list, if (!result) /* success */ { - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } rw_unlock(&LOCK_grant); @@ -3314,12 +3309,7 @@ bool mysql_routine_grant(THD *thd, TABLE_LIST *table_list, bool is_proc, pthread_mutex_unlock(&acl_cache->lock); if (!result && !no_error) { - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } rw_unlock(&LOCK_grant); @@ -3434,12 +3424,7 @@ bool mysql_grant(THD *thd, const char *db, List &list, if (!result) { - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } rw_unlock(&LOCK_grant); @@ -5468,11 +5453,7 @@ bool mysql_create_user(THD *thd, List &list) VOID(pthread_mutex_unlock(&acl_cache->lock)); - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, FALSE, thd->query, thd->query_length); rw_unlock(&LOCK_grant); close_thread_tables(thd); @@ -5538,11 +5519,7 @@ bool mysql_drop_user(THD *thd, List &list) VOID(pthread_mutex_unlock(&acl_cache->lock)); - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, FALSE, thd->query, thd->query_length); rw_unlock(&LOCK_grant); close_thread_tables(thd); @@ -5621,11 +5598,7 @@ bool mysql_rename_user(THD *thd, List &list) VOID(pthread_mutex_unlock(&acl_cache->lock)); - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, FALSE, thd->query, thd->query_length); rw_unlock(&LOCK_grant); close_thread_tables(thd); @@ -5809,11 +5782,7 @@ bool mysql_revoke_all(THD *thd, List &list) VOID(pthread_mutex_unlock(&acl_cache->lock)); - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, FALSE, thd->query, thd->query_length); rw_unlock(&LOCK_grant); close_thread_tables(thd); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 9dbc79344a9..5b9c9259434 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -3028,15 +3028,6 @@ int THD::binlog_flush_pending_rows_event(bool stmt_end) } -void THD::binlog_delete_pending_rows_event() -{ - if (Rows_log_event *pending= binlog_get_pending_rows_event()) - { - delete pending; - binlog_set_pending_rows_event(0); - } -} - /* Member function that will log query, either row-based or statement-based depending on the value of the 'current_stmt_binlog_row_based' diff --git a/sql/sql_class.h b/sql/sql_class.h index de7aaafbe3b..1c719eb9734 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1096,7 +1096,6 @@ public: Rows_log_event* binlog_get_pending_rows_event() const; void binlog_set_pending_rows_event(Rows_log_event* ev); int binlog_flush_pending_rows_event(bool stmt_end); - void binlog_delete_pending_rows_event(); private: uint binlog_table_maps; // Number of table maps currently in the binlog diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index fe54a12e4dc..8581803a9ad 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -975,16 +975,11 @@ end: { if (!error) { - if (mysql_bin_log.is_open()) - { - /* - TRUNCATE must always be statement-based binlogged (not row-based) so - we don't test current_stmt_binlog_row_based. - */ - thd->clear_error(); - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + /* + TRUNCATE must always be statement-based binlogged (not row-based) so + we don't test current_stmt_binlog_row_based. + */ + write_bin_log(thd, TRUE, thd->query, thd->query_length); send_ok(thd); // This should return record count } VOID(pthread_mutex_lock(&LOCK_open)); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 411c26ea3c4..b0e6f351a6b 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2504,12 +2504,7 @@ end_with_restore_list: /* Presumably, REPAIR and binlog writing doesn't require synchronization */ - if (mysql_bin_log.is_open()) - { - thd->clear_error(); // No binlog error generated - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, 0, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } select_lex->table_list.first= (uchar*) first_table; lex->query_tables=all_tables; @@ -2539,12 +2534,7 @@ end_with_restore_list: /* Presumably, ANALYZE and binlog writing doesn't require synchronization */ - if (mysql_bin_log.is_open()) - { - thd->clear_error(); // No binlog error generated - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, 0, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } select_lex->table_list.first= (uchar*) first_table; lex->query_tables=all_tables; @@ -2566,12 +2556,7 @@ end_with_restore_list: /* Presumably, OPTIMIZE and binlog writing doesn't require synchronization */ - if (mysql_bin_log.is_open()) - { - thd->clear_error(); // No binlog error generated - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, 0, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); } select_lex->table_list.first= (uchar*) first_table; lex->query_tables=all_tables; @@ -3471,11 +3456,7 @@ end_with_restore_list: */ if (!lex->no_write_to_binlog && write_to_binlog) { - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, 0, FALSE); - } + write_bin_log(thd, FALSE, thd->query, thd->query_length); } send_ok(thd); } diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index f34ec83b29c..866d82377c0 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -174,12 +174,7 @@ bool mysql_rename_tables(THD *thd, TABLE_LIST *table_list, bool silent) /* Lets hope this doesn't fail as the result will be messy */ if (!silent && !error) { - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); send_ok(thd); } diff --git a/sql/sql_tablespace.cc b/sql/sql_tablespace.cc index b4a03a370ba..9fec0e3bc63 100644 --- a/sql/sql_tablespace.cc +++ b/sql/sql_tablespace.cc @@ -66,10 +66,6 @@ int mysql_alter_tablespace(THD *thd, st_alter_tablespace *ts_info) ha_resolve_storage_engine_name(hton), "TABLESPACE or LOGFILE GROUP"); } - if (mysql_bin_log.is_open()) - { - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, FALSE, TRUE); - } + write_bin_log(thd, FALSE, thd->query, thd->query_length); DBUG_RETURN(FALSE); } diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index e15003ab243..6e8a40e68a2 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -306,14 +306,7 @@ end: if (!result) { - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - - /* Such a statement can always go directly to binlog, no trans cache. */ - thd->binlog_query(THD::STMT_QUERY_TYPE, - stmt_query.ptr(), stmt_query.length(), FALSE, FALSE); - } + write_bin_log(thd, TRUE, stmt_query.ptr(), stmt_query.length()); } VOID(pthread_mutex_unlock(&LOCK_open)); diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc index 20ce614f361..8361fc64f33 100644 --- a/sql/sql_udf.cc +++ b/sql/sql_udf.cc @@ -493,12 +493,7 @@ int mysql_create_function(THD *thd,udf_func *udf) rw_unlock(&THR_LOCK_udf); /* Binlog the create function. */ - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); DBUG_RETURN(0); @@ -569,12 +564,7 @@ int mysql_drop_function(THD *thd,const LEX_STRING *udf_name) rw_unlock(&THR_LOCK_udf); /* Binlog the drop function. */ - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::MYSQL_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); DBUG_RETURN(0); err: diff --git a/sql/sql_view.cc b/sql/sql_view.cc index c1e4006555f..ba13ac3520f 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1467,12 +1467,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode) DBUG_RETURN(TRUE); } - if (mysql_bin_log.is_open()) - { - thd->clear_error(); - thd->binlog_query(THD::STMT_QUERY_TYPE, - thd->query, thd->query_length, FALSE, FALSE); - } + write_bin_log(thd, TRUE, thd->query, thd->query_length); send_ok(thd); VOID(pthread_mutex_unlock(&LOCK_open)); From 6782e85059784c5277460ba80765a656d91c5d40 Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Wed, 20 Jun 2007 09:54:42 +0300 Subject: [PATCH 09/22] removed undeterministic tests introduced by the fix for bug 26418 --- mysql-test/r/rpl_innodb.result | 24 ------------------------ mysql-test/t/rpl_innodb.test | 4 ---- 2 files changed, 28 deletions(-) diff --git a/mysql-test/r/rpl_innodb.result b/mysql-test/r/rpl_innodb.result index 6dc2c25247f..658f92f4d75 100644 --- a/mysql-test/r/rpl_innodb.result +++ b/mysql-test/r/rpl_innodb.result @@ -77,31 +77,7 @@ SELECT COUNT(*) FROM mysqltest1.t1; COUNT(*) 2 FLUSH LOGS; -SHOW BINLOG EVENTS IN 'slave-bin.000002' LIMIT 1,8; -Log_name Pos Event_type Server_id End_log_pos Info -x x x x x DROP DATABASE IF EXISTS mysqltest1 -x x x x x CREATE DATABASE mysqltest1 -x x x x x use `test`; CREATE TEMPORARY TABLE mysqltest1.tmp (f1 BIGINT) -x x x x x use `test`; CREATE TABLE mysqltest1.t1 (f1 BIGINT) ENGINE="InnoDB" -x x x x x use `test`; INSERT INTO mysqltest1.t1 SET f1= 1 -x x x x x use `test`; DROP TEMPORARY TABLE mysqltest1.tmp -x x x x x use `test`; INSERT INTO mysqltest1.t1 SET f1= 2 -x x x x x use `test`; CREATE TEMPORARY TABLE mysqltest1.tmp2(a INT) -------- switch to master -------- FLUSH LOGS; -SHOW BINLOG EVENTS IN 'master-bin.000002' LIMIT 1,12; -Log_name Pos Event_type Server_id End_log_pos Info -x x x x x DROP DATABASE IF EXISTS mysqltest1 -x x x x x CREATE DATABASE mysqltest1 -x x x x x use `test`; CREATE TEMPORARY TABLE mysqltest1.tmp (f1 BIGINT) -x x x x x use `test`; CREATE TABLE mysqltest1.t1 (f1 BIGINT) ENGINE="InnoDB" -x x x x x use `test`; BEGIN -x x x x x use `test`; INSERT INTO mysqltest1.t1 SET f1= 1 -x x x x x use `test`; DROP TEMPORARY TABLE mysqltest1.tmp -x x x x x use `test`; ROLLBACK -x x x x x use `test`; BEGIN -x x x x x use `test`; INSERT INTO mysqltest1.t1 SET f1= 2 -x x x x x use `test`; CREATE TEMPORARY TABLE mysqltest1.tmp2(a INT) -x x x x x use `test`; ROLLBACK DROP DATABASE mysqltest1; End of 5.1 tests diff --git a/mysql-test/t/rpl_innodb.test b/mysql-test/t/rpl_innodb.test index f13889349f7..30d40e19614 100644 --- a/mysql-test/t/rpl_innodb.test +++ b/mysql-test/t/rpl_innodb.test @@ -104,14 +104,10 @@ SHOW CREATE TABLE mysqltest1.tmp2; # it can't be rolled back by the master's ROLLBACK. SELECT COUNT(*) FROM mysqltest1.t1; FLUSH LOGS; ---replace_column 1 x 2 x 3 x 4 x 5 x -SHOW BINLOG EVENTS IN 'slave-bin.000002' LIMIT 1,8; --echo -------- switch to master -------- connection master; FLUSH LOGS; ---replace_column 1 x 2 x 3 x 4 x 5 x -SHOW BINLOG EVENTS IN 'master-bin.000002' LIMIT 1,12; DROP DATABASE mysqltest1; -- source include/master-slave-end.inc From 2379f9778deabf14da0f0beaa97e543ce808bcbd Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Wed, 20 Jun 2007 12:25:07 +0500 Subject: [PATCH 10/22] Fixed bug #28898. For a join query with GROUP BY and/or ORDER BY and a view reference in the FROM list the metadata erroneously showed empty table aliases and database names for the view columns. --- mysql-test/r/metadata.result | 41 ++++++++++++++++++++++++++++++++++++ mysql-test/t/metadata.test | 21 ++++++++++++++++++ sql/item.cc | 15 +++++++++++++ sql/item.h | 6 +----- sql/sql_select.cc | 7 ++++++ 5 files changed, 85 insertions(+), 5 deletions(-) diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index d33fb038b79..283dc8a02ae 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -140,4 +140,45 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def a v_small v_small 3 9 9 N 32769 0 63 v_small 214748364 +CREATE TABLE t1 (c1 CHAR(1)); +CREATE TABLE t2 (c2 CHAR(1)); +CREATE VIEW v1 AS SELECT t1.c1 FROM t1; +CREATE VIEW v2 AS SELECT t2.c2 FROM t2; +INSERT INTO t1 VALUES ('1'), ('2'), ('3'); +INSERT INTO t2 VALUES ('1'), ('2'), ('3'), ('2'); +SELECT v1.c1 FROM v1 JOIN t2 ON c1=c2 ORDER BY 1; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 v1 c1 c1 254 1 1 Y 0 0 8 +c1 +1 +2 +2 +3 +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 v1 c1 c1 254 1 1 Y 0 0 8 +def test t2 v2 c2 c2 254 1 1 Y 0 0 8 +c1 c2 +1 1 +2 2 +3 3 +2 2 +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 v1 c1 c1 254 1 1 Y 32768 0 8 +def test t2 v2 c2 c2 254 1 1 Y 0 0 8 +c1 c2 +1 1 +2 2 +3 3 +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1 ORDER BY v2.c2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 v1 c1 c1 254 1 1 Y 32768 0 8 +def test t2 v2 c2 c2 254 1 1 Y 0 0 8 +c1 c2 +1 1 +2 2 +3 3 +DROP VIEW v1; +DROP TABLE t1,t2; End of 5.0 tests diff --git a/mysql-test/t/metadata.test b/mysql-test/t/metadata.test index df4acec2021..ed510bc2c89 100644 --- a/mysql-test/t/metadata.test +++ b/mysql-test/t/metadata.test @@ -90,5 +90,26 @@ select a.* from (select 2147483648 as v_large) a; select a.* from (select 214748364 as v_small) a; --disable_metadata +# +# Bug #28898: table alias and database name of VIEW columns is empty in the +# metadata of # SELECT statement where join is executed via temporary table. +# + +CREATE TABLE t1 (c1 CHAR(1)); +CREATE TABLE t2 (c2 CHAR(1)); +CREATE VIEW v1 AS SELECT t1.c1 FROM t1; +CREATE VIEW v2 AS SELECT t2.c2 FROM t2; +INSERT INTO t1 VALUES ('1'), ('2'), ('3'); +INSERT INTO t2 VALUES ('1'), ('2'), ('3'), ('2'); + +--enable_metadata +SELECT v1.c1 FROM v1 JOIN t2 ON c1=c2 ORDER BY 1; +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2; +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1; +SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1 ORDER BY v2.c2; +--disable_metadata + +DROP VIEW v1; +DROP TABLE t1,t2; --echo End of 5.0 tests diff --git a/sql/item.cc b/sql/item.cc index 32c43eaa865..b1b85ba8b41 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -5501,6 +5501,21 @@ void Item_ref::make_field(Send_field *field) } +Item *Item_ref::get_tmp_table_item(THD *thd) +{ + if (!result_field) + return (*ref)->get_tmp_table_item(thd); + + Item_field *item= new Item_field(result_field); + if (item) + { + item->table_name= table_name; + item->db_name= db_name; + } + return item; +} + + void Item_ref_null_helper::print(String *str) { str->append(STRING_WITH_LEN("(")); diff --git a/sql/item.h b/sql/item.h index 9268afaba0c..3478095351a 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1904,11 +1904,7 @@ public: enum_field_types field_type() const { return (*ref)->field_type(); } Field *get_tmp_table_field() { return result_field ? result_field : (*ref)->get_tmp_table_field(); } - Item *get_tmp_table_item(THD *thd) - { - return (result_field ? new Item_field(result_field) : - (*ref)->get_tmp_table_item(thd)); - } + Item *get_tmp_table_item(THD *thd); table_map used_tables() const { return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables(); diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6bff302f7f8..d962518495f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -14241,6 +14241,13 @@ change_to_use_tmp_fields(THD *thd, Item **ref_pointer_array, if (!item_field) DBUG_RETURN(TRUE); // Fatal error item_field->name= item->name; + if (item->type() == Item::REF_ITEM) + { + Item_field *ifield= (Item_field *) item_field; + Item_ref *iref= (Item_ref *) item; + ifield->table_name= iref->table_name; + ifield->db_name= iref->db_name; + } #ifndef DBUG_OFF if (_db_on_ && !item_field->name) { From 3b08919f6afe89416465c77ab7d854a7c85dcb78 Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Wed, 20 Jun 2007 14:05:49 +0500 Subject: [PATCH 11/22] Bug #28839 Errors in strict mode silently stop SQL thread if --slave-skip-errors exists. slave_sql thread calls thd->clear_error() to force error to be ignored, though this method didn't clear thd->killed state, what causes slave_sql thread to stop. clear thd->killed state if we ignore an error --- mysql-test/r/rpl_skip_error.result | 19 +++++++++++++++++++ mysql-test/t/rpl_skip_error.test | 19 +++++++++++++++++++ sql/log_event.cc | 1 + 3 files changed, 39 insertions(+) diff --git a/mysql-test/r/rpl_skip_error.result b/mysql-test/r/rpl_skip_error.result index adc61f8c2c8..4cd4e1e73f5 100644 --- a/mysql-test/r/rpl_skip_error.result +++ b/mysql-test/r/rpl_skip_error.result @@ -14,3 +14,22 @@ n 2 3 drop table t1; +create table t1(a int primary key); +insert into t1 values (1),(2); +delete from t1 where @@server_id=1; +set sql_mode=strict_trans_tables; +select @@server_id; +@@server_id +1 +insert into t1 values (1),(2),(3); +select @@server_id; +@@server_id +2 +select * from t1; +a +1 +2 +show slave status; +Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master +Waiting for master to send event 127.0.0.1 root 9306 1 master-bin.000001 843 slave-relay-bin.000003 981 master-bin.000001 Yes Yes 0 0 843 981 None 0 No 0 +drop table t1; diff --git a/mysql-test/t/rpl_skip_error.test b/mysql-test/t/rpl_skip_error.test index f6fc73f58f2..1f476829bde 100644 --- a/mysql-test/t/rpl_skip_error.test +++ b/mysql-test/t/rpl_skip_error.test @@ -17,3 +17,22 @@ connection master; drop table t1; sync_with_master; # End of 4.1 tests + +# +# #28839 Errors in strict mode silently stop SQL thread if --slave-skip-errors exists +# +create table t1(a int primary key); +insert into t1 values (1),(2); +delete from t1 where @@server_id=1; +set sql_mode=strict_trans_tables; +select @@server_id; +insert into t1 values (1),(2),(3); +sync_slave_with_master; +connection slave; +select @@server_id; +select * from t1; +show slave status; +connection master; +drop table t1; +sync_with_master; +# End of 5.0 tests diff --git a/sql/log_event.cc b/sql/log_event.cc index 6eb247488b0..0c8b1f6d4c9 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1964,6 +1964,7 @@ Default database: '%s'. Query: '%s'", { DBUG_PRINT("info",("error ignored")); clear_all_errors(thd, rli); + thd->killed= THD::NOT_KILLED; } /* Other cases: mostly we expected no error and get one. From 0bd3dd9a37ff64083b3c2eb8681ee36817108e5b Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Wed, 20 Jun 2007 14:21:48 +0500 Subject: [PATCH 12/22] metadata.test, metadata.result: Updated test case for bug #28898. Additional cleanup. --- mysql-test/r/metadata.result | 2 +- mysql-test/t/metadata.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index 283dc8a02ae..4a776b6a253 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -179,6 +179,6 @@ c1 c2 1 1 2 2 3 3 -DROP VIEW v1; +DROP VIEW v1,v2; DROP TABLE t1,t2; End of 5.0 tests diff --git a/mysql-test/t/metadata.test b/mysql-test/t/metadata.test index ed510bc2c89..65c062399b7 100644 --- a/mysql-test/t/metadata.test +++ b/mysql-test/t/metadata.test @@ -109,7 +109,7 @@ SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1; SELECT v1.c1, v2.c2 FROM v1 JOIN v2 ON c1=c2 GROUP BY v1.c1 ORDER BY v2.c2; --disable_metadata -DROP VIEW v1; +DROP VIEW v1,v2; DROP TABLE t1,t2; --echo End of 5.0 tests From 49e3ed9ffaebcd21049881ca3547818f5c2013cd Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Wed, 20 Jun 2007 13:15:46 +0300 Subject: [PATCH 13/22] port of the fix for bug 19116 4.1-opt -> 5.0-opt --- mysql-test/r/rpl_change_master.result | 70 +++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/rpl_change_master.result b/mysql-test/r/rpl_change_master.result index 7f2ba568fb3..98c42069470 100644 --- a/mysql-test/r/rpl_change_master.result +++ b/mysql-test/r/rpl_change_master.result @@ -12,12 +12,74 @@ insert into t1 values(1); insert into t1 values(2); stop slave; show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 357 # # master-bin.000001 No No 0 0 183 # None 0 No # +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 357 +Relay_Log_File # +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +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 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 183 +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 # change master to master_user='root'; show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -# 127.0.0.1 root MASTER_MYPORT 1 master-bin.000001 183 # # master-bin.000001 No No 0 0 183 # None 0 No # +Slave_IO_State # +Master_Host 127.0.0.1 +Master_User root +Master_Port MASTER_MYPORT +Connect_Retry 1 +Master_Log_File master-bin.000001 +Read_Master_Log_Pos 183 +Relay_Log_File # +Relay_Log_Pos # +Relay_Master_Log_File master-bin.000001 +Slave_IO_Running No +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 0 +Last_Error +Skip_Counter 0 +Exec_Master_Log_Pos 183 +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 # start slave; select * from t1; n From 23bac8d8df3247f428d70d60dc3069eeb10ea791 Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Wed, 20 Jun 2007 16:26:14 +0300 Subject: [PATCH 14/22] fixed a (merge?) problem running the tests: now the cluster related commands have 'use db' in the binlog. --- mysql-test/r/rpl_ndb_dd_basic.result | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/rpl_ndb_dd_basic.result b/mysql-test/r/rpl_ndb_dd_basic.result index f1cc6e9af24..6a0c863440e 100644 --- a/mysql-test/r/rpl_ndb_dd_basic.result +++ b/mysql-test/r/rpl_ndb_dd_basic.result @@ -35,20 +35,20 @@ pk1 b c show binlog events from ; Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Query 1 # use `test`; DROP TABLE IF EXISTS t1 -master-bin.000001 # Query 1 # CREATE LOGFILE GROUP lg1 +master-bin.000001 # Query 1 # use `test`; CREATE LOGFILE GROUP lg1 ADD UNDOFILE 'undofile.dat' INITIAL_SIZE 16M UNDO_BUFFER_SIZE = 1M ENGINE=NDB -master-bin.000001 # Query 1 # alter logfile group lg1 +master-bin.000001 # Query 1 # use `test`; alter logfile group lg1 add undofile 'undofile02.dat' initial_size 4M engine=ndb -master-bin.000001 # Query 1 # CREATE TABLESPACE ts1 +master-bin.000001 # Query 1 # use `test`; CREATE TABLESPACE ts1 ADD DATAFILE 'datafile.dat' USE LOGFILE GROUP lg1 INITIAL_SIZE 12M ENGINE NDB -master-bin.000001 # Query 1 # alter tablespace ts1 +master-bin.000001 # Query 1 # use `test`; alter tablespace ts1 add datafile 'datafile02.dat' initial_size 4M engine=ndb master-bin.000001 # Query 1 # use `test`; CREATE TABLE t1 From c6cc50960ba0dfe4ef5cb6cfaccff77480d73ef7 Mon Sep 17 00:00:00 2001 From: "igor@olga.mysql.com" <> Date: Wed, 20 Jun 2007 12:43:14 -0700 Subject: [PATCH 15/22] Fixed bug #29104: assertion abort for grouping queries using views. The abort happened when a query contained a conjunctive predicate of the form 'view column = constant' in the WHERE condition and the grouping list also contained a reference to a view column yet a different one. Removed the failing assertion as invalid in a general case. Also fixed a bug that prevented applying some optimization for grouping queries using views. If the WHERE condition of such a query contains a conjunctive condition of the form 'view column = constant' and this view column is used in the grouping list then grouping by this column can be eliminated. The bug blocked performing this elimination. --- mysql-test/r/view.result | 24 ++++++++++++++++++++++++ mysql-test/t/view.test | 24 ++++++++++++++++++++++++ sql/item.cc | 10 ++++------ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 043057f64f7..9adb3f96142 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -3476,4 +3476,28 @@ a1 c 2 0 DROP VIEW v1,v2; DROP TABLE t1,t2,t3,t4; +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2); +CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1; +SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; +b SUM(a) +3 4 +EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; +a SUM(b) +1 6 +2 3 +EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where; Using temporary; Using filesort +SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; +a SUM(b) +1 10 +EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 4 Using where +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 3c370da4139..f670ac8a49d 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -3324,4 +3324,28 @@ SELECT * FROM t1; DROP VIEW v1,v2; DROP TABLE t1,t2,t3,t4; +# +# Bug #29104: assertion abort for a query with a view column reference +# in the GROUP BY list and a condition requiring the value +# of another view column to be equal to a constant +# + +CREATE TABLE t1 (a int, b int); +INSERT INTO t1 VALUES (1,2), (2,2), (1,3), (1,2); + +CREATE VIEW v1 AS SELECT a, b+1 as b FROM t1; + + +SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; +EXPLAIN SELECT b, SUM(a) FROM v1 WHERE b=3 GROUP BY b; + +SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; +EXPLAIN SELECT a, SUM(b) FROM v1 WHERE b=3 GROUP BY a; + +SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; +EXPLAIN SELECT a, SUM(b) FROM v1 WHERE a=1 GROUP BY a; + +DROP VIEW v1; +DROP TABLE t1; + --echo End of 5.0 tests. diff --git a/sql/item.cc b/sql/item.cc index 32c43eaa865..0e75d018b98 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1938,10 +1938,11 @@ bool Item_field::val_bool_result() bool Item_field::eq(const Item *item, bool binary_cmp) const { - if (item->type() != FIELD_ITEM) + Item *real_item= ((Item *) item)->real_item(); + if (real_item->type() != FIELD_ITEM) return 0; - Item_field *item_field= (Item_field*) item; + Item_field *item_field= (Item_field*) real_item; if (item_field->field && field) return item_field->field == field; /* @@ -5627,8 +5628,7 @@ bool Item_outer_ref::fix_fields(THD *thd, Item **reference) DESCRIPTION A view column reference is considered equal to another column reference if the second one is a view column and if both column - references resolve to the same item. It is assumed that both - items are of the same type. + references resolve to the same item. RETURN TRUE Referenced item is equal to given item @@ -5644,8 +5644,6 @@ bool Item_direct_view_ref::eq(const Item *item, bool binary_cmp) const if (item_ref->ref_type() == VIEW_REF) { Item *item_ref_ref= *(item_ref->ref); - DBUG_ASSERT((*ref)->real_item()->type() == - item_ref_ref->real_item()->type()); return ((*ref)->real_item() == item_ref_ref->real_item()); } } From 1b5d893122ca966b1e6246a7586877ef69497ceb Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Thu, 21 Jun 2007 02:11:28 +0500 Subject: [PATCH 16/22] Fixed bug #28293. Occasionally mysqlbinlog --hexdump failed with error: ERROR 1064 (42000) at line ...: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Query thread_id=... exec_time=... error_code=... When the length of hexadecimal dump of binlog header was divisible by 16, commentary sign '#' after header was lost. The Log_event::print_header function has been modified to always finish hexadecimal binlog header with "\n# ". --- mysql-test/r/mysqlbinlog.result | 6 ++++++ mysql-test/t/mysqlbinlog.test | 13 +++++++++++++ sql/log_event.cc | 6 +++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/mysqlbinlog.result b/mysql-test/r/mysqlbinlog.result index a50d131cca8..1ba198dfd75 100644 --- a/mysql-test/r/mysqlbinlog.result +++ b/mysql-test/r/mysqlbinlog.result @@ -312,4 +312,10 @@ DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; +CREATE TABLE t1 (c1 CHAR(10)); +flush logs; +INSERT INTO t1 VALUES ('0123456789'); +flush logs; +DROP TABLE t1; +# Query thread_id=REMOVED exec_time=REMOVED error_code=REMOVED End of 5.0 tests diff --git a/mysql-test/t/mysqlbinlog.test b/mysql-test/t/mysqlbinlog.test index ba161ddbb89..bd90dcfb930 100644 --- a/mysql-test/t/mysqlbinlog.test +++ b/mysql-test/t/mysqlbinlog.test @@ -203,4 +203,17 @@ flush logs; --replace_result $MYSQLTEST_VARDIR MYSQLTEST_VARDIR --exec $MYSQL_BINLOG --short-form --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLTEST_VARDIR/log/master-bin.000009 +# +# Bug#28293 missed '#' sign in the hex dump when the dump length +# is divisible by 16. +# + +CREATE TABLE t1 (c1 CHAR(10)); +# we need this for getting fixed timestamps inside of this test +flush logs; +INSERT INTO t1 VALUES ('0123456789'); +flush logs; +DROP TABLE t1; +--exec $MYSQL_BINLOG --hexdump --local-load=$MYSQLTEST_VARDIR/tmp/ $MYSQLTEST_VARDIR/log/master-bin.000011 | grep 'Query' | sed 's/[0-9]\{1,\}/REMOVED/g' + --echo End of 5.0 tests diff --git a/sql/log_event.cc b/sql/log_event.cc index 6eb247488b0..0f150eeaf2d 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1001,11 +1001,15 @@ void Log_event::print_header(FILE* file, PRINT_EVENT_INFO* print_event_info) } *c= '\0'; - /* Non-full last line */ if (hex_string[0]) + { + /* Non-full last line */ fprintf(file, "# %8.8lx %-48.48s |%s|\n# ", (unsigned long) (hexdump_from + (i & 0xfffffff0)), hex_string, char_string); + } + else + fprintf(file, "# "); } } From 67fcb4c3e213cfb5db410b6b485702c4c19b98a1 Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Thu, 21 Jun 2007 11:48:01 +0500 Subject: [PATCH 17/22] merging --- mysql-test/r/rpl_skip_error.result | 5 +++-- mysql-test/t/rpl_skip_error.test | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/rpl_skip_error.result b/mysql-test/r/rpl_skip_error.result index 38d9ec218a6..a407d1e39c0 100644 --- a/mysql-test/r/rpl_skip_error.result +++ b/mysql-test/r/rpl_skip_error.result @@ -29,7 +29,8 @@ select * from t1; a 1 2 +3 show slave status; -Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -Waiting for master to send event 127.0.0.1 root 9306 1 master-bin.000001 843 slave-relay-bin.000003 981 master-bin.000001 Yes Yes 0 0 843 981 None 0 No 0 +Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master Master_SSL_Verify_Server_Cert +Waiting for master to send event 127.0.0.1 root 9306 1 master-bin.000001 776 slave-relay-bin.000003 922 master-bin.000001 Yes Yes 0 0 776 1077 None 0 No 0 No drop table t1; diff --git a/mysql-test/t/rpl_skip_error.test b/mysql-test/t/rpl_skip_error.test index bcef3e93e5d..14e91044560 100644 --- a/mysql-test/t/rpl_skip_error.test +++ b/mysql-test/t/rpl_skip_error.test @@ -31,6 +31,7 @@ sync_slave_with_master; # # #28839 Errors in strict mode silently stop SQL thread if --slave-skip-errors exists # +connection master; create table t1(a int primary key); insert into t1 values (1),(2); delete from t1 where @@server_id=1; From a5b37d95ff85d9cb7008cedd980589f4a542b7b0 Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Thu, 21 Jun 2007 15:25:28 +0500 Subject: [PATCH 18/22] rpl_skip_error test fixed --- mysql-test/r/rpl_skip_error.result | 2 +- mysql-test/t/rpl_skip_error.test | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/rpl_skip_error.result b/mysql-test/r/rpl_skip_error.result index 4cd4e1e73f5..5e67409a3d7 100644 --- a/mysql-test/r/rpl_skip_error.result +++ b/mysql-test/r/rpl_skip_error.result @@ -31,5 +31,5 @@ a 2 show slave status; Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -Waiting for master to send event 127.0.0.1 root 9306 1 master-bin.000001 843 slave-relay-bin.000003 981 master-bin.000001 Yes Yes 0 0 843 981 None 0 No 0 +Waiting for master to send event 127.0.0.1 root MASTER_PORT 1 master-bin.000001 843 slave-relay-bin.000003 981 master-bin.000001 Yes Yes 0 0 843 981 None 0 No 0 drop table t1; diff --git a/mysql-test/t/rpl_skip_error.test b/mysql-test/t/rpl_skip_error.test index 1f476829bde..19eb2d8ae5e 100644 --- a/mysql-test/t/rpl_skip_error.test +++ b/mysql-test/t/rpl_skip_error.test @@ -31,6 +31,7 @@ sync_slave_with_master; connection slave; select @@server_id; select * from t1; +--replace_result $MASTER_MYPORT MASTER_PORT show slave status; connection master; drop table t1; From 78c53ea32ebf8b2a2b5ce1bf288b366d6eca0800 Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Fri, 22 Jun 2007 09:28:38 +0500 Subject: [PATCH 19/22] rpl_skip_error.test fixed --- mysql-test/r/rpl_skip_error.result | 2 +- mysql-test/t/rpl_skip_error.test | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/rpl_skip_error.result b/mysql-test/r/rpl_skip_error.result index 5e67409a3d7..22ba357ef49 100644 --- a/mysql-test/r/rpl_skip_error.result +++ b/mysql-test/r/rpl_skip_error.result @@ -31,5 +31,5 @@ a 2 show slave status; Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master -Waiting for master to send event 127.0.0.1 root MASTER_PORT 1 master-bin.000001 843 slave-relay-bin.000003 981 master-bin.000001 Yes Yes 0 0 843 981 None 0 No 0 +# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 843 # # master-bin.000001 Yes Yes 0 0 843 # None 0 No # drop table t1; diff --git a/mysql-test/t/rpl_skip_error.test b/mysql-test/t/rpl_skip_error.test index 19eb2d8ae5e..baa7a88b8bb 100644 --- a/mysql-test/t/rpl_skip_error.test +++ b/mysql-test/t/rpl_skip_error.test @@ -31,6 +31,7 @@ sync_slave_with_master; connection slave; select @@server_id; select * from t1; +--replace_column 1 # 8 # 9 # 23 # 33 # --replace_result $MASTER_MYPORT MASTER_PORT show slave status; connection master; From 38991f3e803c552f014eda86a974587bceea03c0 Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Fri, 22 Jun 2007 09:59:23 +0500 Subject: [PATCH 20/22] merging fix --- mysql-test/r/rpl_skip_error.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/r/rpl_skip_error.result b/mysql-test/r/rpl_skip_error.result index 65960875653..ffada04c7b8 100644 --- a/mysql-test/r/rpl_skip_error.result +++ b/mysql-test/r/rpl_skip_error.result @@ -32,5 +32,5 @@ a 3 show slave status; Slave_IO_State Master_Host Master_User Master_Port Connect_Retry Master_Log_File Read_Master_Log_Pos Relay_Log_File Relay_Log_Pos Relay_Master_Log_File Slave_IO_Running Slave_SQL_Running Replicate_Do_DB Replicate_Ignore_DB Replicate_Do_Table Replicate_Ignore_Table Replicate_Wild_Do_Table Replicate_Wild_Ignore_Table Last_Errno Last_Error Skip_Counter Exec_Master_Log_Pos Relay_Log_Space Until_Condition Until_Log_File Until_Log_Pos Master_SSL_Allowed Master_SSL_CA_File Master_SSL_CA_Path Master_SSL_Cert Master_SSL_Cipher Master_SSL_Key Seconds_Behind_Master Master_SSL_Verify_Server_Cert -Waiting for master to send event 127.0.0.1 root MASTER_PORT 1 master-bin.000001 776 # # master-bin.000001 Yes Yes 0 0 776 # None 0 No 0 No +# 127.0.0.1 root MASTER_PORT 1 master-bin.000001 776 # # master-bin.000001 Yes Yes 0 0 776 # None 0 No # No drop table t1; From f45601ce584acb22b26c367d4658197a7d19c933 Mon Sep 17 00:00:00 2001 From: "gkodinov/kgeorge@magare.gmz" <> Date: Fri, 22 Jun 2007 15:34:28 +0300 Subject: [PATCH 21/22] Bug #27383: Crash in test "mysql_client_test" The C optimizer may decide that data access operations through pointer of different type are not related to the original data (strict aliasing). This is what happens in fetch_long_with_conversion(), when called as part of mysql_stmt_fetch() : it tries to check for truncation errors by first storing float (and other types of data) into a char * buffer and then accesses them through a float pointer. This is done to prevent the effects of excess precision when using FPU registers. However the doublestore() macro converts a double pointer to an union pointer. This violates the strict aliasing rule. Fixed by making the intermediary variables volatile ( to not re-introduce the excess precision bug) and using the intermediary value instead of the char * buffer. Note that there can be loss of precision for both signed and unsigned 64 bit integers converted to double and back, so the check must stay there (even for compatibility reasons). Based on the excellent analysis in bug 28400. --- libmysql/libmysql.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index e426d2c549e..cb60fb20863 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -3663,33 +3663,38 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field, case MYSQL_TYPE_FLOAT: { /* - We need to store data in the buffer before the truncation check to + We need to mark the local variable volatile to workaround Intel FPU executive precision feature. (See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323 for details) - AFAIU it does not guarantee to work. */ - float data; + volatile float data; if (is_unsigned) + { data= (float) ulonglong2double(value); + *param->error= ((ulonglong) value) != ((ulonglong) data); + } else - data= (float) value; + { + data= (float)value; + *param->error= value != ((longlong) data); + } floatstore(buffer, data); - *param->error= is_unsigned ? - ((ulonglong) value) != ((ulonglong) (*(float*) buffer)) : - ((longlong) value) != ((longlong) (*(float*) buffer)); break; } case MYSQL_TYPE_DOUBLE: { - double data; + volatile double data; if (is_unsigned) + { data= ulonglong2double(value); + *param->error= ((ulonglong) value) != ((ulonglong) data); + } else + { data= (double)value; + *param->error= value != ((longlong) data); + } doublestore(buffer, data); - *param->error= is_unsigned ? - ((ulonglong) value) != ((ulonglong) (*(double*) buffer)) : - ((longlong) value) != ((longlong) (*(double*) buffer)); break; } case MYSQL_TYPE_TIME: From fbbb30a6228d84b02b941021c3356fb837977a81 Mon Sep 17 00:00:00 2001 From: "gshchepa/uchum@gleb.loc" <> Date: Sun, 24 Jun 2007 01:20:14 +0500 Subject: [PATCH 22/22] Fixed bug #29095. INSERT into table from SELECT from the same table with ORDER BY and LIMIT was inserting other data than sole SELECT ... ORDER BY ... LIMIT returns. One part of the patch for bug #9676 improperly pushed LIMIT to temporary table in the presence of the ORDER BY clause. That part has been removed. --- mysql-test/r/insert_select.result | 31 +++++++++++++++++++++++++++++++ mysql-test/t/insert_select.test | 25 +++++++++++++++++++++++++ sql/sql_select.cc | 3 +-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/insert_select.result b/mysql-test/r/insert_select.result index 08a865e0b94..8cb94072818 100644 --- a/mysql-test/r/insert_select.result +++ b/mysql-test/r/insert_select.result @@ -688,7 +688,16 @@ ERROR 42S22: Unknown column 't2.x' in 'field list' drop table t1,t2; CREATE TABLE t1 (a int PRIMARY KEY); INSERT INTO t1 values (1), (2); +flush status; INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1; +show status like 'Handler_read%'; +Variable_name Value +Handler_read_first 1 +Handler_read_key 0 +Handler_read_next 0 +Handler_read_prev 0 +Handler_read_rnd 0 +Handler_read_rnd_next 1 DROP TABLE t1; CREATE TABLE t1 (x int, y int); CREATE TABLE t2 (z int, y int); @@ -773,3 +782,25 @@ d 20 20 DROP TABLE t1,t2; +CREATE TABLE t1 ( +id INT AUTO_INCREMENT PRIMARY KEY, +prev_id INT, +join_id INT DEFAULT 0); +INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2); +SELECT * FROM t1; +id prev_id join_id +1 NULL 0 +2 1 0 +3 2 0 +CREATE TABLE t2 (join_id INT); +INSERT INTO t2 (join_id) VALUES (0); +INSERT INTO t1 (prev_id) SELECT id +FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id +ORDER BY id DESC LIMIT 1; +SELECT * FROM t1; +id prev_id join_id +1 NULL 0 +2 1 0 +3 2 0 +4 3 0 +DROP TABLE t1,t2; diff --git a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test index bbc51be6dc9..bf6dae96847 100644 --- a/mysql-test/t/insert_select.test +++ b/mysql-test/t/insert_select.test @@ -233,7 +233,9 @@ drop table t1,t2; CREATE TABLE t1 (a int PRIMARY KEY); INSERT INTO t1 values (1), (2); +flush status; INSERT INTO t1 SELECT a + 2 FROM t1 LIMIT 1; +show status like 'Handler_read%'; DROP TABLE t1; @@ -332,3 +334,26 @@ INSERT INTO t2 (d) SELECT * FROM t2; DROP TABLE t1,t2; + +# +# Bug #29095: incorrect pushing of LIMIT into the temporary +# table ignoring ORDER BY clause +# + +CREATE TABLE t1 ( + id INT AUTO_INCREMENT PRIMARY KEY, + prev_id INT, + join_id INT DEFAULT 0); + +INSERT INTO t1 (prev_id) VALUES (NULL), (1), (2); +SELECT * FROM t1; + +CREATE TABLE t2 (join_id INT); +INSERT INTO t2 (join_id) VALUES (0); + +INSERT INTO t1 (prev_id) SELECT id + FROM t2 LEFT JOIN t1 ON t1.join_id = t2.join_id + ORDER BY id DESC LIMIT 1; +SELECT * FROM t1; + +DROP TABLE t1,t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index f4450bf393f..85df73bb31a 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -1347,8 +1347,7 @@ JOIN::optimize() there are aggregate functions, because in all these cases we need all result rows. */ - ha_rows tmp_rows_limit= ((order == 0 || skip_sort_order || - test(select_options & OPTION_BUFFER_RESULT)) && + ha_rows tmp_rows_limit= ((order == 0 || skip_sort_order) && !tmp_group && !thd->lex->current_select->with_sum_func) ? select_limit : HA_POS_ERROR;