mirror of
https://github.com/MariaDB/server.git
synced 2025-08-31 22:22:30 +03:00
Fix for bug #10015 "Crash in InnoDB if stored routines are used".
We should not allow explicit or implicit transaction commits inside of stored functions or triggers (so in autocommit mode we should not do commits after execution of sub-statement). Also since we don't support nested statement transactions in 5.0, we shouldn't commit or rollback stmt transactions while we are inside stored functions or triggers. This should be fixed in later (>=5.1) releases. mysql-test/r/sp_trans.result: Added test for bug #10015 "Crash in InnoDB if stored routines are used" and for general transaction handling inside of functions. mysql-test/t/sp_trans.test: Added test for bug #10015 "Crash in InnoDB if stored routines are used" and for general transaction handling inside of functions. sql/handler.cc: ha_trans_commit()/ha_trans_rollback(): Since we don't support nested statement transactions in 5.0, we can't commit or rollback stmt transactions while we are inside stored functions or triggers. So we simply do nothing now. This should be fixed in later ( >= 5.1) releases. sql/item_func.cc: Item_func_sp::execute(): Set THD::transaction.in_sub_stmt flag to TRUE during stored function execution to prevent commits and rollbacks for statement level transactions, since doing them will ruin such transaction for stateemtn which calls this function. sql/share/errmsg.txt: Added error message which says that statements doing explicit or implicit commits are disallowed in triggers and stored functions. sql/sql_base.cc: close_thread_tables(): Clarified comment about committing of statement transactions in prelocked mode. sql/sql_class.h: THD::transaction: Added in_sub_stmt method which indicates that we are executing statements from trigger or stored function now, and thus statement transaction belongs to statement which invoked this routine and we should not commit or rollback it while executing these sub-statements. sql/sql_parse.cc: end_active_trans()/begin_trans()/end_trans(): We should not commit or rollback global (non-stmt) transaction if we are executing stored function or trigger. These checks will catch situation when we are trying to do commit or rollback in stored procedure which is called from function or trigger. sql/sql_trigger.h: Table_triggers_list::process_triggers(): Set THD::transaction.in_sub_stmt flag to TRUE during trigger execution to prevent commits and rollbacks for statement level transactions, since doing them will ruin such transaction for stateemtn which invokes this trigger. sql/sql_yacc.yy: Prohibited usage of statements which do explicit or implicit commit or rollback inside of stored functions and triggers.
This commit is contained in:
@@ -595,6 +595,27 @@ int ha_commit_trans(THD *thd, bool all)
|
||||
handlerton **ht= trans->ht;
|
||||
my_xid xid= thd->transaction.xid.get_my_xid();
|
||||
DBUG_ENTER("ha_commit_trans");
|
||||
|
||||
if (thd->transaction.in_sub_stmt)
|
||||
{
|
||||
/*
|
||||
Since we don't support nested statement transactions in 5.0,
|
||||
we can't commit or rollback stmt transactions while we are inside
|
||||
stored functions or triggers. So we simply do nothing now.
|
||||
TODO: This should be fixed in later ( >= 5.1) releases.
|
||||
*/
|
||||
if (!all)
|
||||
DBUG_RETURN(0);
|
||||
/*
|
||||
We assume that all statements which commit or rollback main transaction
|
||||
are prohibited inside of stored functions or triggers. So they should
|
||||
bail out with error even before ha_commit_trans() call. To be 100% safe
|
||||
let us throw error in non-debug builds.
|
||||
*/
|
||||
DBUG_ASSERT(0);
|
||||
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
|
||||
DBUG_RETURN(2);
|
||||
}
|
||||
#ifdef USING_TRANSACTIONS
|
||||
if (trans->nht)
|
||||
{
|
||||
@@ -689,6 +710,19 @@ int ha_rollback_trans(THD *thd, bool all)
|
||||
THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
|
||||
bool is_real_trans=all || thd->transaction.all.nht == 0;
|
||||
DBUG_ENTER("ha_rollback_trans");
|
||||
if (thd->transaction.in_sub_stmt)
|
||||
{
|
||||
/*
|
||||
If we are inside stored function or trigger we should not commit or
|
||||
rollback current statement transaction. See comment in ha_commit_trans()
|
||||
call for more information.
|
||||
*/
|
||||
if (!all)
|
||||
DBUG_RETURN(0);
|
||||
DBUG_ASSERT(0);
|
||||
my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
|
||||
DBUG_RETURN(1);
|
||||
}
|
||||
#ifdef USING_TRANSACTIONS
|
||||
if (trans->nht)
|
||||
{
|
||||
|
Reference in New Issue
Block a user