Commit 90a5e244 authored by guilhem@mysql.com's avatar guilhem@mysql.com

To save 32KB memory per thread when --log-bin is not used, we do not

init the binlog_cache (THD::transaction.trans_log).
I have checked all places where trans_log is used, because as now
it may not be inited in some cases, we have to be cautious
(will forward this commit mail to Heikki).
parent 34aefdf3
...@@ -486,7 +486,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) ...@@ -486,7 +486,7 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans)
operation_done=1; operation_done=1;
} }
#endif #endif
if (trans == &thd->transaction.all) if ((trans == &thd->transaction.all) && mysql_bin_log.is_open())
{ {
/* /*
Update the binary log with a BEGIN/ROLLBACK block if we have cached some Update the binary log with a BEGIN/ROLLBACK block if we have cached some
...@@ -494,7 +494,6 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans) ...@@ -494,7 +494,6 @@ int ha_rollback_trans(THD *thd, THD_TRANS *trans)
be rare (updating a non-transactional table inside a transaction...). be rare (updating a non-transactional table inside a transaction...).
*/ */
if (unlikely((thd->options & OPTION_STATUS_NO_TRANS_UPDATE) && if (unlikely((thd->options & OPTION_STATUS_NO_TRANS_UPDATE) &&
mysql_bin_log.is_open() &&
my_b_tell(&thd->transaction.trans_log))) my_b_tell(&thd->transaction.trans_log)))
mysql_bin_log.write(thd, &thd->transaction.trans_log, 0); mysql_bin_log.write(thd, &thd->transaction.trans_log, 0);
/* Flushed or not, empty the binlog cache */ /* Flushed or not, empty the binlog cache */
...@@ -559,7 +558,7 @@ int ha_rollback_to_savepoint(THD *thd, char *savepoint_name) ...@@ -559,7 +558,7 @@ int ha_rollback_to_savepoint(THD *thd, char *savepoint_name)
my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), error); my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), error);
error=1; error=1;
} }
else else if (mysql_bin_log.is_open())
{ {
/* /*
Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some Write ROLLBACK TO SAVEPOINT to the binlog cache if we have updated some
...@@ -567,7 +566,6 @@ int ha_rollback_to_savepoint(THD *thd, char *savepoint_name) ...@@ -567,7 +566,6 @@ int ha_rollback_to_savepoint(THD *thd, char *savepoint_name)
from the SAVEPOINT command. from the SAVEPOINT command.
*/ */
if (unlikely((thd->options & OPTION_STATUS_NO_TRANS_UPDATE) && if (unlikely((thd->options & OPTION_STATUS_NO_TRANS_UPDATE) &&
mysql_bin_log.is_open() &&
my_b_tell(&thd->transaction.trans_log))) my_b_tell(&thd->transaction.trans_log)))
{ {
Query_log_event qinfo(thd, thd->query, thd->query_length, TRUE); Query_log_event qinfo(thd, thd->query, thd->query_length, TRUE);
...@@ -596,23 +594,26 @@ Return value: always 0, that is, succeeds always ...@@ -596,23 +594,26 @@ Return value: always 0, that is, succeeds always
int ha_savepoint(THD *thd, char *savepoint_name) int ha_savepoint(THD *thd, char *savepoint_name)
{ {
my_off_t binlog_cache_pos=0;
int error=0; int error=0;
DBUG_ENTER("ha_savepoint"); DBUG_ENTER("ha_savepoint");
#ifdef USING_TRANSACTIONS #ifdef USING_TRANSACTIONS
if (opt_using_transactions) if (opt_using_transactions)
{ {
binlog_cache_pos=my_b_tell(&thd->transaction.trans_log); /* Write it to the binary log (see comments of ha_rollback_to_savepoint) */
#ifdef HAVE_INNOBASE_DB
innobase_savepoint(thd,savepoint_name, binlog_cache_pos);
#endif
/* Write it to the binary log (see comments of ha_rollback_to_savepoint). */
if (mysql_bin_log.is_open()) if (mysql_bin_log.is_open())
{ {
#ifdef HAVE_INNOBASE_DB
innobase_savepoint(thd,savepoint_name,
my_b_tell(&thd->transaction.trans_log));
#endif
Query_log_event qinfo(thd, thd->query, thd->query_length, TRUE); Query_log_event qinfo(thd, thd->query, thd->query_length, TRUE);
if (mysql_bin_log.write(&qinfo)) if (mysql_bin_log.write(&qinfo))
error= 1; error= 1;
} }
#ifdef HAVE_INNOBASE_DB
else
innobase_savepoint(thd,savepoint_name,0);
#endif
} }
#endif /* USING_TRANSACTIONS */ #endif /* USING_TRANSACTIONS */
DBUG_RETURN(error); DBUG_RETURN(error);
......
...@@ -169,7 +169,11 @@ THD::THD():user_time(0), current_statement(0), is_fatal_error(0), ...@@ -169,7 +169,11 @@ THD::THD():user_time(0), current_statement(0), is_fatal_error(0),
tablespace_op=FALSE; tablespace_op=FALSE;
#ifdef USING_TRANSACTIONS #ifdef USING_TRANSACTIONS
bzero((char*) &transaction,sizeof(transaction)); bzero((char*) &transaction,sizeof(transaction));
if (opt_using_transactions) /*
Binlog is always open (if needed) before a THD is created (including
bootstrap).
*/
if (opt_using_transactions && mysql_bin_log.is_open())
{ {
if (open_cached_file(&transaction.trans_log, if (open_cached_file(&transaction.trans_log,
mysql_tmpdir, LOG_PREFIX, binlog_cache_size, mysql_tmpdir, LOG_PREFIX, binlog_cache_size,
......
...@@ -684,7 +684,7 @@ class THD :public ilink, ...@@ -684,7 +684,7 @@ class THD :public ilink,
delayed_insert *di; delayed_insert *di;
my_bool tablespace_op; /* This is TRUE in DISCARD/IMPORT TABLESPACE */ my_bool tablespace_op; /* This is TRUE in DISCARD/IMPORT TABLESPACE */
struct st_transactions { struct st_transactions {
IO_CACHE trans_log; IO_CACHE trans_log; // Inited ONLY if binlog is open !
THD_TRANS all; // Trans since BEGIN WORK THD_TRANS all; // Trans since BEGIN WORK
THD_TRANS stmt; // Trans for current statement THD_TRANS stmt; // Trans for current statement
uint bdb_lock_count; uint bdb_lock_count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment