Index: sql/sql_class.h =================================================================== --- sql/sql_class.h (revision 1) +++ sql/sql_class.h (working copy) @@ -548,6 +548,7 @@ Gtid_specification gtid_next; Gtid_set_or_null gtid_next_list; + my_bool rollback_trans_on_stmt_fail; } SV; Index: sql/sys_vars.cc =================================================================== --- sql/sys_vars.cc (revision 1) +++ sql/sys_vars.cc (working copy) @@ -4548,3 +4548,13 @@ "Give clients that don't signal password expiration support execution time error(s) instead of connection error", READ_ONLY GLOBAL_VAR(disconnect_on_expired_password), CMD_LINE(OPT_ARG), DEFAULT(TRUE)); + +static Sys_var_mybool Sys_rollback_trans_on_stmt_fail( + "rollback_trans_on_stmt_fail", + "rollback the whole transaction when on statement fail", + SESSION_VAR(rollback_trans_on_stmt_fail), + CMD_LINE(OPT_ARG), + DEFAULT(FALSE), NO_MUTEX_GUARD, NOT_IN_BINLOG, ON_CHECK(0), + ON_UPDATE(0)); + + Index: sql/sql_parse.cc =================================================================== --- sql/sql_parse.cc (revision 1) +++ sql/sql_parse.cc (working copy) @@ -6158,6 +6158,10 @@ // needed. error= gtid_empty_group_log_and_cleanup(thd); } + + if (error && thd->variables.rollback_trans_on_stmt_fail) + trans_rollback(thd); + MYSQL_QUERY_EXEC_DONE(error); } }