Never pass NULL to innobase_get_stmt()

This commit is contained in:
Marko Mäkelä 2017-05-16 17:45:22 +03:00
parent 71cd205956
commit 408ef65f84
6 changed files with 40 additions and 38 deletions

View File

@ -2265,16 +2265,11 @@ innobase_get_stmt(
THD* thd, /*!< in: MySQL thread handle */ THD* thd, /*!< in: MySQL thread handle */
size_t* length) /*!< out: length of the SQL statement */ size_t* length) /*!< out: length of the SQL statement */
{ {
const char* query = NULL; if (const LEX_STRING *stmt = thd_query_string(thd)) {
LEX_STRING *stmt = NULL; *length = stmt->length;
if (thd) { return stmt->str;
stmt = thd_query_string(thd);
if (stmt) {
*length = stmt->length;
query = stmt->str;
}
} }
return (query); return NULL;
} }
/**********************************************************************//** /**********************************************************************//**

View File

@ -909,12 +909,18 @@ lock_reset_lock_and_trx_wait(
const char* stmt2=NULL; const char* stmt2=NULL;
size_t stmt_len; size_t stmt_len;
trx_id_t trx_id = 0; trx_id_t trx_id = 0;
stmt = innobase_get_stmt(lock->trx->mysql_thd, &stmt_len); stmt = lock->trx->mysql_thd
? innobase_get_stmt(lock->trx->mysql_thd, &stmt_len)
: NULL;
if (lock->trx->lock.wait_lock && if (lock->trx->lock.wait_lock &&
lock->trx->lock.wait_lock->trx) { lock->trx->lock.wait_lock->trx) {
trx_id = lock->trx->lock.wait_lock->trx->id; trx_id = lock->trx->lock.wait_lock->trx->id;
stmt2 = innobase_get_stmt(lock->trx->lock.wait_lock->trx->mysql_thd, &stmt_len); stmt2 = lock->trx->lock.wait_lock->trx->mysql_thd
? innobase_get_stmt(
lock->trx->lock.wait_lock
->trx->mysql_thd, &stmt_len)
: NULL;
} }
ib_logf(IB_LOG_LEVEL_INFO, ib_logf(IB_LOG_LEVEL_INFO,
@ -5586,13 +5592,11 @@ lock_rec_unlock(
trx_mutex_exit(trx); trx_mutex_exit(trx);
stmt = innobase_get_stmt(trx->mysql_thd, &stmt_len); stmt = innobase_get_stmt(trx->mysql_thd, &stmt_len);
ut_print_timestamp(stderr);
fprintf(stderr, ib_logf(IB_LOG_LEVEL_ERROR,
" InnoDB: Error: unlock row could not" "unlock row could not find a %u mode lock on the record;"
" find a %lu mode lock on the record\n", " statement=%.*s",
(ulong) lock_mode); lock_mode,
ut_print_timestamp(stderr);
fprintf(stderr, " InnoDB: current statement: %.*s\n",
(int) stmt_len, stmt); (int) stmt_len, stmt);
return; return;

View File

@ -503,7 +503,9 @@ fill_trx_row(
row->trx_mysql_thread_id = thd_get_thread_id(trx->mysql_thd); row->trx_mysql_thread_id = thd_get_thread_id(trx->mysql_thd);
stmt = innobase_get_stmt(trx->mysql_thd, &stmt_len); stmt = trx->mysql_thd
? innobase_get_stmt(trx->mysql_thd, &stmt_len)
: NULL;
if (stmt != NULL) { if (stmt != NULL) {
char query[TRX_I_S_TRX_QUERY_MAX_LEN + 1]; char query[TRX_I_S_TRX_QUERY_MAX_LEN + 1];

View File

@ -2591,16 +2591,11 @@ innobase_get_stmt(
THD* thd, /*!< in: MySQL thread handle */ THD* thd, /*!< in: MySQL thread handle */
size_t* length) /*!< out: length of the SQL statement */ size_t* length) /*!< out: length of the SQL statement */
{ {
const char* query = NULL; if (const LEX_STRING *stmt = thd_query_string(thd)) {
LEX_STRING *stmt = NULL; *length = stmt->length;
if (thd) { return stmt->str;
stmt = thd_query_string(thd);
if (stmt) {
*length = stmt->length;
query = stmt->str;
}
} }
return (query); return NULL;
} }
/**********************************************************************//** /**********************************************************************//**

View File

@ -921,12 +921,18 @@ lock_reset_lock_and_trx_wait(
const char* stmt2=NULL; const char* stmt2=NULL;
size_t stmt_len; size_t stmt_len;
trx_id_t trx_id = 0; trx_id_t trx_id = 0;
stmt = innobase_get_stmt(lock->trx->mysql_thd, &stmt_len); stmt = lock->trx->mysql_thd
? innobase_get_stmt(lock->trx->mysql_thd, &stmt_len)
: NULL;
if (lock->trx->lock.wait_lock && if (lock->trx->lock.wait_lock &&
lock->trx->lock.wait_lock->trx) { lock->trx->lock.wait_lock->trx) {
trx_id = lock->trx->lock.wait_lock->trx->id; trx_id = lock->trx->lock.wait_lock->trx->id;
stmt2 = innobase_get_stmt(lock->trx->lock.wait_lock->trx->mysql_thd, &stmt_len); stmt2 = lock->trx->lock.wait_lock->trx->mysql_thd
? innobase_get_stmt(
lock->trx->lock.wait_lock
->trx->mysql_thd, &stmt_len)
: NULL;
} }
ib_logf(IB_LOG_LEVEL_INFO, ib_logf(IB_LOG_LEVEL_INFO,
@ -5636,13 +5642,11 @@ lock_rec_unlock(
trx_mutex_exit(trx); trx_mutex_exit(trx);
stmt = innobase_get_stmt(trx->mysql_thd, &stmt_len); stmt = innobase_get_stmt(trx->mysql_thd, &stmt_len);
ut_print_timestamp(stderr);
fprintf(stderr, ib_logf(IB_LOG_LEVEL_ERROR,
" InnoDB: Error: unlock row could not" "unlock row could not find a %u mode lock on the record;"
" find a %lu mode lock on the record\n", " statement=%.*s",
(ulong) lock_mode); lock_mode,
ut_print_timestamp(stderr);
fprintf(stderr, " InnoDB: current statement: %.*s\n",
(int) stmt_len, stmt); (int) stmt_len, stmt);
return; return;

View File

@ -507,7 +507,9 @@ fill_trx_row(
row->trx_mysql_thread_id = thd_get_thread_id(trx->mysql_thd); row->trx_mysql_thread_id = thd_get_thread_id(trx->mysql_thd);
stmt = innobase_get_stmt(trx->mysql_thd, &stmt_len); stmt = trx->mysql_thd
? innobase_get_stmt(trx->mysql_thd, &stmt_len)
: NULL;
if (stmt != NULL) { if (stmt != NULL) {
char query[TRX_I_S_TRX_QUERY_MAX_LEN + 1]; char query[TRX_I_S_TRX_QUERY_MAX_LEN + 1];