Commit 1fbaf8b6 authored by Monty's avatar Monty Committed by Sergei Golubchik

Decrease stack space usage of mysql_execute_command()

The extensive usage of stack space, especially when used with ASan
(AdressSanitizer) of mysql_execute_command caused the test
rpl.rpl_row_sp011 to fail because it did run out of stack.  In this
test case mysql_execute_command is called recursively for each
function all.

Changes done:
- Changed a few functions that used big local variables to be marked
  __attribute__ ((noinline))
- Moved sub parts that used big local variables to external functions.
- Changed wsrep_commit_empty() from inline to normal function as this used
  more than 1K of stack space and because there is no reason for this
  rarely used function to be inline.

End result (with gcc 7.4.1 on Intel Xeon):

Starting point for stack space usage:

gcc -O:                                  7800
gcc with -fsanitize=address -O (ASan) : 27240

After this patch:

gcc -O:                                  1160
gcc -O0 (debug build)                    1584
gcc with -fsanitize=address -O (ASan):   4424
gcc with -fsanitize=address -O2 (ASan):  3874

A 6x improvement and will allow us to run all mtr tests with ASan.
parent e21408b7
This diff is collapsed.
......@@ -2782,3 +2782,54 @@ bool wsrep_consistency_check(THD *thd)
{
return thd->wsrep_consistency_check == CONSISTENCY_CHECK_RUNNING;
}
/*
Commit an empty transaction.
If the transaction is real and the wsrep transaction is still active,
the transaction did not generate any rows or keys and is committed
as empty. Here the wsrep transaction is rolled back and after statement
step is performed to leave the wsrep transaction in the state as it
never existed.
This should not be an inline functions as it requires a lot of stack space
because of WSREP_DBUG() usage. It's also not a function that is
frequently called.
*/
void wsrep_commit_empty(THD* thd, bool all)
{
DBUG_ENTER("wsrep_commit_empty");
WSREP_DEBUG("wsrep_commit_empty(%llu)", thd->thread_id);
if (wsrep_is_real(thd, all) &&
wsrep_thd_is_local(thd) &&
thd->wsrep_trx().active() &&
thd->wsrep_trx().state() != wsrep::transaction::s_committed)
{
/* @todo CTAS with STATEMENT binlog format and empty result set
seems to be committing empty. Figure out why and try to fix
elsewhere. */
DBUG_ASSERT(!wsrep_has_changes(thd) ||
(thd->lex->sql_command == SQLCOM_CREATE_TABLE &&
!thd->is_current_stmt_binlog_format_row()));
bool have_error= wsrep_current_error(thd);
int ret= wsrep_before_rollback(thd, all) ||
wsrep_after_rollback(thd, all) ||
wsrep_after_statement(thd);
/* The committing transaction was empty but it held some locks and
got BF aborted. As there were no certified changes in the
data, we ignore the deadlock error and rely on error reporting
by storage engine/server. */
if (!ret && !have_error && wsrep_current_error(thd))
{
DBUG_ASSERT(wsrep_current_error(thd) == wsrep::e_deadlock_error);
thd->wsrep_cs().reset_error();
}
if (ret)
{
WSREP_DEBUG("wsrep_commit_empty failed: %d", wsrep_current_error(thd));
}
}
DBUG_VOID_RETURN;
}
......@@ -26,6 +26,8 @@
class THD;
void wsrep_commit_empty(THD* thd, bool all);
/*
Return true if THD has active wsrep transaction.
*/
......@@ -466,50 +468,4 @@ wsrep_current_error_status(THD* thd)
return thd->wsrep_cs().current_error_status();
}
/*
Commit an empty transaction.
If the transaction is real and the wsrep transaction is still active,
the transaction did not generate any rows or keys and is committed
as empty. Here the wsrep transaction is rolled back and after statement
step is performed to leave the wsrep transaction in the state as it
never existed.
*/
static inline void wsrep_commit_empty(THD* thd, bool all)
{
DBUG_ENTER("wsrep_commit_empty");
WSREP_DEBUG("wsrep_commit_empty(%llu)", thd->thread_id);
if (wsrep_is_real(thd, all) &&
wsrep_thd_is_local(thd) &&
thd->wsrep_trx().active() &&
thd->wsrep_trx().state() != wsrep::transaction::s_committed)
{
/* @todo CTAS with STATEMENT binlog format and empty result set
seems to be committing empty. Figure out why and try to fix
elsewhere. */
DBUG_ASSERT(!wsrep_has_changes(thd) ||
(thd->lex->sql_command == SQLCOM_CREATE_TABLE &&
!thd->is_current_stmt_binlog_format_row()));
bool have_error= wsrep_current_error(thd);
int ret= wsrep_before_rollback(thd, all) ||
wsrep_after_rollback(thd, all) ||
wsrep_after_statement(thd);
/* The committing transaction was empty but it held some locks and
got BF aborted. As there were no certified changes in the
data, we ignore the deadlock error and rely on error reporting
by storage engine/server. */
if (!ret && !have_error && wsrep_current_error(thd))
{
DBUG_ASSERT(wsrep_current_error(thd) == wsrep::e_deadlock_error);
thd->wsrep_cs().reset_error();
}
if (ret)
{
WSREP_DEBUG("wsrep_commit_empty failed: %d", wsrep_current_error(thd));
}
}
DBUG_VOID_RETURN;
}
#endif /* WSREP_TRANS_OBSERVER */
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