1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-29 05:21:33 +03:00

Clean-up, give better names, add comments to

thd->in_multi_stmt_transaction() and thd->active_transaction().
This commit is contained in:
Konstantin Osipov
2010-05-06 02:02:08 +04:00
parent 24a14875bc
commit cca59e83d7
15 changed files with 128 additions and 48 deletions

View File

@ -2309,10 +2309,6 @@ public:
{
return limit_found_rows;
}
inline bool active_transaction()
{
return server_status & SERVER_STATUS_IN_TRANS;
}
/**
Returns TRUE if session is in a multi-statement transaction mode.
@ -2323,11 +2319,60 @@ public:
OPTION_BEGIN: Regardless of the autocommit status, a multi-statement
transaction can be explicitly started with the statements "START
TRANSACTION", "BEGIN [WORK]", "[COMMIT | ROLLBACK] AND CHAIN", etc.
Note: this doesn't tell you whether a transaction is active.
A session can be in multi-statement transaction mode, and yet
have no active transaction, e.g., in case of:
set @@autocommit=0;
set @a= 3; <-- these statements don't
set transaction isolation level serializable; <-- start an active
flush tables; <-- transaction
I.e. for the above scenario this function returns TRUE, even
though no active transaction has begun.
@sa in_active_multi_stmt_transaction()
*/
inline bool in_multi_stmt_transaction()
inline bool in_multi_stmt_transaction_mode()
{
return variables.option_bits & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN);
}
/**
TRUE if the session is in a multi-statement transaction mode
(@sa in_multi_stmt_transaction_mode()) *and* there is an
active transaction, i.e. there is an explicit start of a
transaction with BEGIN statement, or implicit with a
statement that uses a transactional engine.
For example, these scenarios don't start an active transaction
(even though the server is in multi-statement transaction mode):
set @@autocommit=0;
select * from nontrans_table;
set @var=TRUE;
flush tables;
Note, that even for a statement that starts a multi-statement
transaction (i.e. select * from trans_table), this
flag won't be set until we open the statement's tables
and the engines register themselves for the transaction
(see trans_register_ha()),
hence this method is reliable to use only after
open_tables() has completed.
Why do we need a flag?
----------------------
We need to maintain a (at first glance redundant)
session flag, rather than looking at thd->transaction.all.ha_list
because of explicit start of a transaction with BEGIN.
I.e. in case of
BEGIN;
select * from nontrans_t1; <-- in_active_multi_stmt_transaction() is true
*/
inline bool in_active_multi_stmt_transaction()
{
return server_status & SERVER_STATUS_IN_TRANS;
}
inline bool fill_derived_tables()
{
return !stmt_arena->is_stmt_prepare() && !lex->only_view_structure();