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

Bug#57306 SHOW PROCESSLIST does not display string literals well.

Problem: Extended characters outside of ASCII range where not displayed
properly in SHOW PROCESSLIST, because thd_info->query was always sent as 
system_character_set (utf8). This was wrong, because query buffer
is never converted to utf8 - it is always have client character set.

Fix: sending query buffer using query character set

  @ sql/sql_class.cc
  @ sql/sql_class.h
    Introducing a new class CSET_STRING, a LEX_STRING with character set.
    Adding set_query(&CSET_STRING)
    Adding reset_query(), to use instead of set_query(0, NULL).

  @ sql/event_data_objects.cc
    Using reset_query()

  @ sql/log_event.cc
    Using reset_query()
    Adding charset argument to set_query_and_id().

  @ sql/slave.cc
    Using reset_query().

  @ sql/sp_head.cc
    Changing backing up and restore code to use CSET_STRING.

  @ sql/sql_audit.h
    Using CSET_STRING.
    In the "else" branch it's OK not to use
    global_system_variables.character_set_client.
    &my_charset_latin1, which is set in constructor, is fine
    (verified with Sergey Vojtovich).

  @ sql/sql_insert.cc
    Using set_query() with proper character set: table_name is utf8.

  @ sql/sql_parse.cc
    Adding character set argument to set_query_and_id().
    (This is the main point where thd->charset() is stored
     into thd->query_string.cs, for use in "SHOW PROCESSLIST".)
    Using reset_query().
    
  @ sql/sql_prepare.cc
    Storing client character set into thd->query_string.cs.

  @ sql/sql_show.cc
    Using CSET_STRING to fetch and send charset-aware query information
    from threads.

  @ storage/myisam/ha_myisam.cc
    Using set_query() with proper character set: table_name is utf8.

  @ mysql-test/r/show_check.result
  @ mysql-test/t/show_check.test
    Adding tests
This commit is contained in:
Alexander Barkov
2010-11-18 17:08:32 +03:00
parent 459c3b8f55
commit fad763a81f
14 changed files with 170 additions and 61 deletions

View File

@ -109,6 +109,41 @@ extern MYSQL_PLUGIN_IMPORT const char **errmesg;
extern bool volatile shutdown_in_progress;
extern "C" LEX_STRING * thd_query_string (MYSQL_THD thd);
extern "C" char **thd_query(MYSQL_THD thd);
/**
@class CSET_STRING
@brief Character set armed LEX_STRING
*/
class CSET_STRING
{
private:
LEX_STRING string;
CHARSET_INFO *cs;
public:
CSET_STRING() : cs(&my_charset_bin)
{
string.str= NULL;
string.length= 0;
}
CSET_STRING(char *str_arg, size_t length_arg, CHARSET_INFO *cs_arg) :
cs(cs_arg)
{
DBUG_ASSERT(cs_arg != NULL);
string.str= str_arg;
string.length= length_arg;
}
inline char *str() const { return string.str; }
inline uint32 length() const { return string.length; }
CHARSET_INFO *charset() const { return cs; }
friend LEX_STRING * thd_query_string (MYSQL_THD thd);
friend char **thd_query(MYSQL_THD thd);
};
#define TC_LOG_PAGE_SIZE 8192
#define TC_LOG_MIN_SIZE (3*TC_LOG_PAGE_SIZE)
@ -722,12 +757,24 @@ public:
This printing is needed at least in SHOW PROCESSLIST and SHOW
ENGINE INNODB STATUS.
*/
LEX_STRING query_string;
inline char *query() { return query_string.str; }
inline uint32 query_length() { return query_string.length; }
void set_query_inner(char *query_arg, uint32 query_length_arg);
CSET_STRING query_string;
inline char *query() const { return query_string.str(); }
inline uint32 query_length() const { return query_string.length(); }
CHARSET_INFO *query_charset() const { return query_string.charset(); }
void set_query_inner(const CSET_STRING &string_arg)
{
query_string= string_arg;
}
void set_query_inner(char *query_arg, uint32 query_length_arg,
CHARSET_INFO *cs_arg)
{
set_query_inner(CSET_STRING(query_arg, query_length_arg, cs_arg));
}
void reset_query_inner()
{
set_query_inner(CSET_STRING());
}
/**
Name of the current (default) database.
@ -2676,9 +2723,20 @@ public:
Assign a new value to thd->query and thd->query_id and mysys_var.
Protected with LOCK_thd_data mutex.
*/
void set_query(char *query_arg, uint32 query_length_arg);
void set_query(char *query_arg, uint32 query_length_arg,
CHARSET_INFO *cs_arg)
{
set_query(CSET_STRING(query_arg, query_length_arg, cs_arg));
}
void set_query(char *query_arg, uint32 query_length_arg) /*Mutex protected*/
{
set_query(CSET_STRING(query_arg, query_length_arg, charset()));
}
void set_query(const CSET_STRING &str); /* Mutex protected */
void reset_query() /* Mutex protected */
{ set_query(CSET_STRING()); }
void set_query_and_id(char *query_arg, uint32 query_length_arg,
query_id_t new_query_id);
CHARSET_INFO *cs, query_id_t new_query_id);
void set_query_id(query_id_t new_query_id);
void set_open_tables(TABLE *open_tables_arg)
{