diff options
author | osku@127.(none) <> | 2005-08-12 11:39:19 +0300 |
---|---|---|
committer | osku@127.(none) <> | 2005-08-12 11:39:19 +0300 |
commit | 04056ffd3d6f300bc16d738f9450e93d42ef9f0b (patch) | |
tree | 21b7de1b8632c1f1729e35528e580de73fb20e60 /sql | |
parent | 445bc1336ece8428a3db3374c1d2b3ce57a61ede (diff) | |
download | mariadb-git-04056ffd3d6f300bc16d738f9450e93d42ef9f0b.tar.gz |
InnoDB: Print more than 300 characters of queries in various error conditions,
most notably deadlocked ones in SHOW INNODB STATUS. Fixes bug #7819.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/ha_innodb.cc | 65 |
1 files changed, 44 insertions, 21 deletions
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc index 0a01c08c916..9f1b5d34cce 100644 --- a/sql/ha_innodb.cc +++ b/sql/ha_innodb.cc @@ -550,19 +550,20 @@ innobase_mysql_end_print_arbitrary_thd(void) } /***************************************************************** -Prints info of a THD object (== user session thread) to the -standard output. NOTE that /mysql/innobase/trx/trx0trx.c must contain -the prototype for this function! */ +Prints info of a THD object (== user session thread) to the given file. +NOTE that /mysql/innobase/trx/trx0trx.c must contain the prototype for +this function! */ extern "C" void innobase_mysql_print_thd( /*=====================*/ - FILE* f, /* in: output stream */ - void* input_thd)/* in: pointer to a MySQL THD object */ + FILE* f, /* in: output stream */ + void* input_thd, /* in: pointer to a MySQL THD object */ + uint max_query_len) /* in: max query length to print, or 0 to + use the default max length */ { const THD* thd; const char* s; - char buf[301]; thd = (const THD*) input_thd; @@ -589,25 +590,47 @@ innobase_mysql_print_thd( } if ((s = thd->query)) { - /* determine the length of the query string */ - uint32 i, len; + /* 3100 is chosen because currently 3000 is the maximum + max_query_len we ever give this. */ + char buf[3100]; + uint len; + + /* If buf is too small, we dynamically allocate storage + in this. */ + char* dyn_str = NULL; + + /* Points to buf or dyn_str. */ + char* str = buf; - len = thd->query_length; - - if (len > 300) { - len = 300; /* ADDITIONAL SAFETY: print at most - 300 chars to reduce the probability of - a seg fault if there is a race in - thd->query_length in MySQL; after - May 14, 2004 probably no race any more, - but better be safe */ + if (max_query_len == 0) + { + /* ADDITIONAL SAFETY: the default is to print at + most 300 chars to reduce the probability of a + seg fault if there is a race in + thd->query_length in MySQL; after May 14, 2004 + probably no race any more, but better be + safe */ + max_query_len = 300; } + + len = min(thd->query_length, max_query_len); - /* Use strmake to reduce the timeframe - for a race, compared to fwrite() */ - i= (uint) (strmake(buf, s, len) - buf); + if (len > (sizeof(buf) - 1)) + { + dyn_str = my_malloc(len + 1, MYF(0)); + str = dyn_str; + } + + /* Use strmake to reduce the timeframe for a race, + compared to fwrite() */ + len = (uint) (strmake(str, s, len) - str); putc('\n', f); - fwrite(buf, 1, i, f); + fwrite(str, 1, len, f); + + if (dyn_str) + { + my_free(dyn_str, MYF(0)); + } } putc('\n', f); |