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