diff --git a/BitKeeper/etc/logging_ok b/BitKeeper/etc/logging_ok index 00f4c86d319e6faffdfa3459bc574dc8ccf21884..b8043910a111266776ddb1bedefaae8d37a2995d 100644 --- a/BitKeeper/etc/logging_ok +++ b/BitKeeper/etc/logging_ok @@ -87,6 +87,7 @@ jcole@mugatu.jcole.us jcole@mugatu.spaceapes.com jcole@sarvik.tfr.cafe.ee jcole@tetra.spaceapes.com +jimw@mysql.com joerg@mysql.com joreland@mysql.com jorge@linux.jorge.mysql.com diff --git a/mysql-test/r/insert_select.result b/mysql-test/r/insert_select.result index 7c7ac152aa5a642061442bd844103acbe97ccfa3..fcb4229fcdb8bdf136abbff19df276654759b9ff 100644 --- a/mysql-test/r/insert_select.result +++ b/mysql-test/r/insert_select.result @@ -81,6 +81,15 @@ a 1 2 drop table t1, t2; +create table t1(a int); +insert into t1 values(1),(1); +reset master; +create table t2(unique(a)) select a from t1; +Duplicate entry '1' for key 1 +show binlog events; +Log_name Pos Event_type Server_id Orig_log_pos Info +master-bin.001 4 Start 1 4 Server ver: VERSION, Binlog ver: 3 +drop table t1; create table t1 (a int not null); create table t2 (a int not null); insert into t1 values (1); diff --git a/mysql-test/t/insert_select.test b/mysql-test/t/insert_select.test index db5dc8d91da5ad98770061eb4d237a2a9c5dbb98..e1459310bb977203494e81793d97eb75a83af5a9 100644 --- a/mysql-test/t/insert_select.test +++ b/mysql-test/t/insert_select.test @@ -89,6 +89,19 @@ show binlog events; select * from t1; drop table t1, t2; +# Verify that a partly-completed CREATE TABLE .. SELECT does not +# get into the binlog (Bug #6682) +create table t1(a int); +insert into t1 values(1),(1); +reset master; +--error 1062 +create table t2(unique(a)) select a from t1; +# The above should produce an error, *and* not appear in the binlog +let $VERSION=`select version()`; +--replace_result $VERSION VERSION +show binlog events; +drop table t1; + # # Test of insert ... select from same table # diff --git a/sql/sql_class.h b/sql/sql_class.h index d0d9afc774628faccd4647719d1a08986c5c2c25..4e695701310fd2ae444a560535d5aaff733c7a73 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1092,6 +1092,15 @@ public: void end_statement(); }; +# define tmp_disable_binlog(A) \ + ulong save_options= (A)->options, save_master_access= (A)->master_access; \ + (A)->options&= ~OPTION_BIN_LOG; \ + (A)->master_access|= SUPER_ACL; /* unneeded in 4.1 */ + +#define reenable_binlog(A) \ + (A)->options= save_options; \ + (A)->master_access= save_master_access; + /* Flags for the THD::system_thread (bitmap) variable */ #define SYSTEM_THREAD_DELAYED_INSERT 1 #define SYSTEM_THREAD_SLAVE_IO 2 @@ -1263,6 +1272,7 @@ public: {} int prepare(List<Item> &list, SELECT_LEX_UNIT *u); bool send_data(List<Item> &values); + void send_error(uint errcode,const char *err); bool send_eof(); void abort(); }; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index d590d3b509337f60aa4c880eb236f5b7e75b3e26..d63bb29affa53224737e6a1cd1578cd026834dc9 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1667,6 +1667,18 @@ bool select_create::send_data(List<Item> &values) } +void select_create::send_error(uint errcode,const char *err) +{ + /* + Disable binlog, because we "roll back" partial inserts in ::abort + by removing the table, even for non-transactional tables. + */ + tmp_disable_binlog(thd); + select_insert::send_error(errcode, err); + reenable_binlog(thd); +} + + bool select_create::send_eof() { bool tmp=select_insert::send_eof(); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 71ce9102fbb74163168a90c1ae3bf2a9171ed28b..abb840568c3c4fbd52fac155dc03143c264640c5 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -29,12 +29,6 @@ #include <io.h> #endif -#define tmp_disable_binlog(A) \ - ulong save_options= (A)->options; \ - (A)->options&= ~OPTION_BIN_LOG; - -#define reenable_binlog(A) (A)->options= save_options; - const char *primary_key_name="PRIMARY"; static bool check_if_keyname_exists(const char *name,KEY *start, KEY *end);