Commit 75a1d866 authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-5273 Prepared statement doesn't return metadata after prepare.

        SHOW SLAVE STATUS fixed.
parent 552d3309
......@@ -163,7 +163,6 @@ static int queue_event(Master_info* mi,const char* buf,ulong event_len);
static int terminate_slave_thread(THD *, mysql_mutex_t *, mysql_cond_t *,
volatile uint *, bool);
static bool check_io_slave_killed(Master_info *mi, const char *info);
static bool send_show_master_info_header(THD *, bool, size_t);
static bool send_show_master_info_data(THD *, Master_info *, bool, String *);
/*
Function to set the slave's max_allowed_packet based on the value
......@@ -2497,10 +2496,13 @@ bool show_master_info(THD *thd, Master_info *mi, bool full)
{
DBUG_ENTER("show_master_info");
String gtid_pos;
List<Item> field_list;
if (full && rpl_global_gtid_slave_state->tostring(&gtid_pos, NULL, 0))
DBUG_RETURN(TRUE);
if (send_show_master_info_header(thd, full, gtid_pos.length()))
show_master_info_get_fields(thd, &field_list, full, gtid_pos.length());
if (thd->protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
DBUG_RETURN(TRUE);
if (send_show_master_info_data(thd, mi, full, &gtid_pos))
DBUG_RETURN(TRUE);
......@@ -2508,224 +2510,218 @@ bool show_master_info(THD *thd, Master_info *mi, bool full)
DBUG_RETURN(FALSE);
}
static bool send_show_master_info_header(THD *thd, bool full,
size_t gtid_pos_length)
void show_master_info_get_fields(THD *thd, List<Item> *field_list,
bool full, size_t gtid_pos_length)
{
List<Item> field_list;
Protocol *protocol= thd->protocol;
Master_info *mi;
MEM_ROOT *mem_root= thd->mem_root;
DBUG_ENTER("show_master_info_header");
DBUG_ENTER("show_master_info_get_fields");
if (full)
{
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Connection_name",
MAX_CONNECTION_NAME),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Slave_SQL_State", 30),
thd->mem_root);
}
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Slave_IO_State", 30),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_Host", sizeof(mi->host)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_User", sizeof(mi->user)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Master_Port", 7, MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Connect_Retry", 10,
MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_Log_File", FN_REFLEN),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Read_Master_Log_Pos", 10,
MYSQL_TYPE_LONGLONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Relay_Log_File", FN_REFLEN),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Relay_Log_Pos", 10,
MYSQL_TYPE_LONGLONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Relay_Master_Log_File",
FN_REFLEN),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Slave_IO_Running", 3),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Slave_SQL_Running", 3),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Do_DB", 20),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Ignore_DB", 20),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Do_Table", 20),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Ignore_Table", 23),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Wild_Do_Table", 24),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Wild_Ignore_Table",
28),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Last_Errno", 4, MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Last_Error", 20),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Skip_Counter", 10,
MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Exec_Master_Log_Pos", 10,
MYSQL_TYPE_LONGLONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Relay_Log_Space", 10,
MYSQL_TYPE_LONGLONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Until_Condition", 6),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Until_Log_File", FN_REFLEN),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Until_Log_Pos", 10,
MYSQL_TYPE_LONGLONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Allowed", 7),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_CA_File",
sizeof(mi->ssl_ca)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_CA_Path",
sizeof(mi->ssl_capath)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Cert",
sizeof(mi->ssl_cert)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Cipher",
sizeof(mi->ssl_cipher)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Key",
sizeof(mi->ssl_key)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Seconds_Behind_Master", 10,
MYSQL_TYPE_LONGLONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Verify_Server_Cert",
3),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Last_IO_Errno", 4,
MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Last_IO_Error", 20),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Last_SQL_Errno", 4,
MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Last_SQL_Error", 20),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Ignore_Server_Ids",
FN_REFLEN),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Master_Server_Id", sizeof(ulong),
MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Crl",
sizeof(mi->ssl_crl)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Crlpath",
sizeof(mi->ssl_crlpath)),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Using_Gtid",
sizeof("Current_Pos")-1),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Gtid_IO_Pos", 30),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Do_Domain_Ids",
FN_REFLEN),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Ignore_Domain_Ids",
FN_REFLEN),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Parallel_Mode",
sizeof("conservative")-1),
thd->mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Connection_name",
MAX_CONNECTION_NAME),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Slave_SQL_State", 30),
mem_root);
}
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Slave_IO_State", 30),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_Host", sizeof(mi->host)),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_User", sizeof(mi->user)),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Master_Port", 7, MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Connect_Retry", 10,
MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_Log_File", FN_REFLEN),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Read_Master_Log_Pos", 10,
MYSQL_TYPE_LONGLONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Relay_Log_File", FN_REFLEN),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Relay_Log_Pos", 10,
MYSQL_TYPE_LONGLONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Relay_Master_Log_File",
FN_REFLEN),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Slave_IO_Running", 3),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Slave_SQL_Running", 3),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Do_DB", 20),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Ignore_DB", 20),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Do_Table", 20),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Ignore_Table", 23),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Wild_Do_Table", 24),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Wild_Ignore_Table",
28),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Last_Errno", 4, MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Last_Error", 20),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Skip_Counter", 10,
MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Exec_Master_Log_Pos", 10,
MYSQL_TYPE_LONGLONG),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Relay_Log_Space", 10,
MYSQL_TYPE_LONGLONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Until_Condition", 6),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Until_Log_File", FN_REFLEN),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Until_Log_Pos", 10,
MYSQL_TYPE_LONGLONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Allowed", 7),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_CA_File",
sizeof(mi->ssl_ca)),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_CA_Path",
sizeof(mi->ssl_capath)),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Cert",
sizeof(mi->ssl_cert)),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Cipher",
sizeof(mi->ssl_cipher)),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Key",
sizeof(mi->ssl_key)),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Seconds_Behind_Master", 10,
MYSQL_TYPE_LONGLONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Verify_Server_Cert",
3),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Last_IO_Errno", 4,
MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Last_IO_Error", 20),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Last_SQL_Errno", 4,
MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Last_SQL_Error", 20),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Ignore_Server_Ids",
FN_REFLEN),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Master_Server_Id", sizeof(ulong),
MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Crl",
sizeof(mi->ssl_crl)),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Master_SSL_Crlpath",
sizeof(mi->ssl_crlpath)),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Using_Gtid",
sizeof("Current_Pos")-1),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Gtid_IO_Pos", 30),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Do_Domain_Ids",
FN_REFLEN),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Replicate_Ignore_Domain_Ids",
FN_REFLEN),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Parallel_Mode",
sizeof("conservative")-1),
mem_root);
if (full)
{
field_list.push_back(new (mem_root)
Item_return_int(thd, "Retried_transactions", 10,
MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Max_relay_log_size", 10,
MYSQL_TYPE_LONGLONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Executed_log_entries", 10,
MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_return_int(thd, "Slave_received_heartbeats", 10,
MYSQL_TYPE_LONG),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_float(thd, "Slave_heartbeat_period", 0.0, 3, 10),
thd->mem_root);
field_list.push_back(new (mem_root)
Item_empty_string(thd, "Gtid_Slave_Pos",
gtid_pos_length),
thd->mem_root);
}
if (protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
DBUG_RETURN(TRUE);
DBUG_RETURN(FALSE);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Retried_transactions", 10,
MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Max_relay_log_size", 10,
MYSQL_TYPE_LONGLONG),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Executed_log_entries", 10,
MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_return_int(thd, "Slave_received_heartbeats", 10,
MYSQL_TYPE_LONG),
mem_root);
field_list->push_back(new (mem_root)
Item_float(thd, "Slave_heartbeat_period", 0.0, 3, 10),
mem_root);
field_list->push_back(new (mem_root)
Item_empty_string(thd, "Gtid_Slave_Pos",
gtid_pos_length),
mem_root);
}
DBUG_VOID_RETURN;
}
/* Text for Slave_IO_Running */
......@@ -2962,6 +2958,7 @@ bool show_all_master_info(THD* thd)
uint i, elements;
String gtid_pos;
Master_info **tmp;
List<Item> field_list;
DBUG_ENTER("show_master_info");
mysql_mutex_assert_owner(&LOCK_active_mi);
......@@ -2972,7 +2969,9 @@ bool show_all_master_info(THD* thd)
DBUG_RETURN(TRUE);
}
if (send_show_master_info_header(thd, 1, gtid_pos.length()))
show_master_info_get_fields(thd, &field_list, 1, gtid_pos.length());
if (thd->protocol->send_result_set_metadata(&field_list,
Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
DBUG_RETURN(TRUE);
if (!master_info_index ||
......
......@@ -207,6 +207,8 @@ int mysql_table_dump(THD* thd, const char* db,
int fetch_master_table(THD* thd, const char* db_name, const char* table_name,
Master_info* mi, MYSQL* mysql, bool overwrite);
void show_master_info_get_fields(THD *thd, List<Item> *field_list,
bool full, size_t gtid_pos_length);
bool show_master_info(THD* thd, Master_info* mi, bool full);
bool show_all_master_info(THD* thd);
bool show_binlog_info(THD* thd);
......
......@@ -104,6 +104,7 @@ When one supplies long data for a placeholder:
// mysql_handle_derived
#include "sql_cursor.h"
#include "sql_show.h"
#include "slave.h"
#include "sp_head.h"
#include "sp.h"
#include "sp_cache.h"
......@@ -1892,6 +1893,29 @@ static bool mysql_test_show_grants(Prepared_statement *stmt)
}
/**
Validate and prepare for execution SHOW SLAVE STATUS statement.
@param stmt prepared statement
@retval
FALSE success
@retval
TRUE error, error message is set in THD
*/
static bool mysql_test_show_slave_status(Prepared_statement *stmt)
{
DBUG_ENTER("mysql_test_show_slave_status");
THD *thd= stmt->thd;
List<Item> fields;
show_master_info_get_fields(thd, &fields, 0, 0);
DBUG_RETURN(send_stmt_metadata(thd, stmt, &fields));
}
/**
@brief Validate and prepare for execution CREATE VIEW statement
......@@ -2246,6 +2270,13 @@ static bool check_prepared_statement(Prepared_statement *stmt)
DBUG_RETURN(FALSE);
}
break;
case SQLCOM_SHOW_SLAVE_STAT:
if (!(res= mysql_test_show_slave_status(stmt)))
{
/* Statement and field info has already been sent */
DBUG_RETURN(FALSE);
}
break;
case SQLCOM_CREATE_VIEW:
if (lex->create_view_mode == VIEW_ALTER)
{
......
......@@ -443,6 +443,13 @@ static void test_prepare_simple()
DIE_UNLESS(mysql_stmt_field_count(stmt) == 1);
mysql_stmt_close(stmt);
/* show slave status */
strmov(query, "SHOW SLAVE STATUS");
stmt= mysql_simple_prepare(mysql, query);
check_stmt(stmt);
DIE_UNLESS(mysql_stmt_field_count(stmt) == 47);
mysql_stmt_close(stmt);
/* now fetch the results ..*/
rc= mysql_commit(mysql);
myquery(rc);
......
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