From e771ee75e7d186119dbbcd88d1b0d6d9a94b775b Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 14 May 2008 09:50:16 +0300 Subject: [PATCH] Manual merge and some fixes. mysql-test/include/varchar.inc: Manual merge between 5.1 and maria. Added a comment. mysql-test/r/maria.result: Temporary fix. mysql-test/suite/binlog/r/binlog_unsafe.result: Manual merge. mysql-test/suite/binlog/t/binlog_unsafe.test: Manual merge. sql/handler.h: Manual merge + fix. sql/item.h: Manual merge + fix. sql/log.cc: Manual merge + fix. sql/sql_insert.cc: Manual merge + fix. A commit was done when using create table ... select from for transactional tables other than maria, when an error occurred and transaction should have been aborted. --- mysql-test/include/varchar.inc | 5 ++++ mysql-test/r/maria.result | 1 + .../suite/binlog/r/binlog_unsafe.result | 1 - mysql-test/suite/binlog/t/binlog_unsafe.test | 1 - sql/handler.h | 1 + sql/item.h | 1 + sql/log.cc | 25 ++++++++++++------- sql/sql_insert.cc | 18 +++++++------ 8 files changed, 34 insertions(+), 19 deletions(-) diff --git a/mysql-test/include/varchar.inc b/mysql-test/include/varchar.inc index 15306ed8385..7accbd151a9 100644 --- a/mysql-test/include/varchar.inc +++ b/mysql-test/include/varchar.inc @@ -11,6 +11,11 @@ enable_query_log; # Simple basic test that endspace is saved # +# +# Remember to check that one doesn't get a warning or a note +# from a char field when end spaces get removed. SQL standard! +# + create table t1 (v varchar(10), c char(10), t text); insert into t1 values('+ ', '+ ', '+ '); set @a=repeat(' ',20); diff --git a/mysql-test/r/maria.result b/mysql-test/r/maria.result index a14c6211c47..5487024f073 100644 --- a/mysql-test/r/maria.result +++ b/mysql-test/r/maria.result @@ -983,6 +983,7 @@ set @a=repeat(' ',20); insert into t1 values (concat('+',@a),concat('+',@a),concat('+',@a)); Warnings: Note 1265 Data truncated for column 'v' at row 1 +Note 1265 Data truncated for column 'c' at row 1 select concat('*',v,'*',c,'*',t,'*') from t1; concat('*',v,'*',c,'*',t,'*') *+ *+*+ * diff --git a/mysql-test/suite/binlog/r/binlog_unsafe.result b/mysql-test/suite/binlog/r/binlog_unsafe.result index cd055e6410e..1f7b217dc31 100644 --- a/mysql-test/suite/binlog/r/binlog_unsafe.result +++ b/mysql-test/suite/binlog/r/binlog_unsafe.result @@ -11,7 +11,6 @@ INSERT DELAYED INTO t1 VALUES (5); INSERT INTO t1 VALUES (@@global.sync_binlog); Warnings: Warning 1592 Statement is not safe to log in statement format. -DROP VIEW v1; INSERT INTO t1 VALUES (@@session.insert_id); Warnings: Warning 1592 Statement is not safe to log in statement format. diff --git a/mysql-test/suite/binlog/t/binlog_unsafe.test b/mysql-test/suite/binlog/t/binlog_unsafe.test index 696ded0fd1e..0d7059bc31f 100644 --- a/mysql-test/suite/binlog/t/binlog_unsafe.test +++ b/mysql-test/suite/binlog/t/binlog_unsafe.test @@ -59,7 +59,6 @@ source include/have_log_bin.inc; source include/have_binlog_format_statement.inc; -DROP VIEW v1; --echo ==== Setup tables ==== CREATE TABLE t1 (a INT); diff --git a/sql/handler.h b/sql/handler.h index 222337fd01b..63923733c4d 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -767,6 +767,7 @@ struct THD_TRANS bool modified_non_trans_table; void reset() { no_2pc= FALSE; modified_non_trans_table= FALSE; } + THD_TRANS() {} /* Remove gcc warning */ }; diff --git a/sql/item.h b/sql/item.h index f4d7da55496..57399e935cd 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1028,6 +1028,7 @@ public: if (orig_name) name= orig_name; } + Item_basic_constant() {} /* Remove gcc warning */ }; diff --git a/sql/log.cc b/sql/log.cc index bb18d08f4db..305deb2f0fe 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -1535,16 +1535,23 @@ static int binlog_commit(handlerton *hton, THD *thd, bool all) YESNO(in_transaction), YESNO(thd->transaction.all.modified_non_trans_table), YESNO(thd->transaction.stmt.modified_non_trans_table))); - if (in_transaction && - (all || - (!trx_data->at_least_one_stmt && - thd->transaction.stmt.modified_non_trans_table)) || - !in_transaction && !all) + if (thd->options & OPTION_BIN_LOG) { - Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE); - qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE) - int error= binlog_end_trans(thd, trx_data, &qev, all); - DBUG_RETURN(error); + if (in_transaction && + (all || + (!trx_data->at_least_one_stmt && + thd->transaction.stmt.modified_non_trans_table)) || + !in_transaction && !all) + { + Query_log_event qev(thd, STRING_WITH_LEN("COMMIT"), TRUE, FALSE); + qev.error_code= 0; // see comment in MYSQL_LOG::write(THD, IO_CACHE) + int error= binlog_end_trans(thd, trx_data, &qev, all); + DBUG_RETURN(error); + } + } + else + { + trx_data->reset(); } DBUG_RETURN(0); } diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 394a3d2e7b3..dbfe3cc6d79 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -3533,15 +3533,17 @@ select_create::prepare(List &values, SELECT_LEX_UNIT *u) engines to do logging of insertions (optimization). We don't do it for temporary tables (yet) as re-enabling causes an undesirable commit. */ - if (((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) && - ha_enable_transaction(thd, FALSE)) - DBUG_RETURN(-1); if (!(table= create_table_from_items(thd, create_info, create_table, alter_info, &values, &extra_lock, hook_ptr))) DBUG_RETURN(-1); // abort() deletes table + if (((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) && + !create_info->table_existed && + ha_enable_transaction(thd, FALSE)) + DBUG_RETURN(-1); + if (extra_lock) { DBUG_ASSERT(m_plock == NULL); @@ -3682,7 +3684,8 @@ bool select_create::send_eof() abort(); else { - if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) + if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 && + !create_info->table_existed) ha_enable_transaction(thd, TRUE); /* Do an implicit commit at end of statement for non-temporary @@ -3712,9 +3715,6 @@ void select_create::abort() { DBUG_ENTER("select_create::abort"); - if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0) - ha_enable_transaction(thd, TRUE); - /* In select_insert::abort() we roll back the statement, including truncating the transaction cache of the binary log. To do this, we @@ -3731,11 +3731,13 @@ void select_create::abort() log state. */ tmp_disable_binlog(thd); + if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 && + !create_info->table_existed) + ha_enable_transaction(thd, TRUE); select_insert::abort(); thd->transaction.stmt.modified_non_trans_table= FALSE; reenable_binlog(thd); - if (m_plock) { mysql_unlock_tables(thd, *m_plock);