revision-id: b810b210d28329354365391135a3c5c465ad5f8b (mariadb-10.3.6-17-gb810b210d28) parent(s): 346c8ab9533a3de6a4cb348428402ffee2aa8da2 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-04-20 14:39:57 +0200 message: postreview fix --- mysql-test/main/mysql_client_test.result | 2 +- mysql-test/main/mysql_client_test.test | 4 +++- sql/sql_class.cc | 36 ++++++++++++++++++-------------- sql/sql_class.h | 5 +++-- sql/sql_explain.cc | 3 +-- sql/sql_parse.cc | 5 ++--- sql/sql_prepare.cc | 12 +++++++---- sql/sql_prepare.h | 2 -- tests/mysql_client_test.c | 2 ++ 9 files changed, 40 insertions(+), 31 deletions(-) diff --git a/mysql-test/main/mysql_client_test.result b/mysql-test/main/mysql_client_test.result index 20385acfa00..6f65979517b 100644 --- a/mysql-test/main/mysql_client_test.result +++ b/mysql-test/main/mysql_client_test.result @@ -122,6 +122,7 @@ EOF mysql_stmt_next_result(): 0; field_count: 0 # ------------------------------------ + # cat MYSQL_TMP_DIR/test_explain_meta.out.log # ------------------------------------ SELECT number of fields: 1 @@ -243,6 +244,5 @@ ANALYZE JSON DELETE number of fields: 1 - 0: name: 'ANALYZE'/''; table: ''/''; db: ''; catalog: 'def'; length: 234; max_length: 0; type: 253; decimals: 39 # ------------------------------------ - SET @@global.general_log= @old_general_log; SET @@global.slow_query_log= @old_slow_query_log; diff --git a/mysql-test/main/mysql_client_test.test b/mysql-test/main/mysql_client_test.test index 79ad9f84477..2c6febd8ffa 100644 --- a/mysql-test/main/mysql_client_test.test +++ b/mysql-test/main/mysql_client_test.test @@ -27,12 +27,14 @@ echo ok; --echo # ------------------------------------ --cat_file $MYSQL_TMP_DIR/test_wl4435.out.log --echo # ------------------------------------ +--echo + --echo --echo # cat MYSQL_TMP_DIR/test_explain_meta.out.log --echo # ------------------------------------ --cat_file $MYSQL_TMP_DIR/test_explain_meta.out.log --echo # ------------------------------------ --echo ---echo + SET @@global.general_log= @old_general_log; SET @@global.slow_query_log= @old_slow_query_log; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 349ec576264..0ec95e11829 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -69,7 +69,6 @@ #include "wsrep_thd.h" #include "sql_connect.h" #include "my_atomic.h" -#include "sql_prepare.h" #ifdef HAVE_SYS_SYSCALL_H #include <sys/syscall.h> @@ -2660,26 +2659,31 @@ CHANGED_TABLE_LIST* THD::changed_table_dup(const char *key, size_t key_length) } +void THD::prepare_explain_fields(select_result *result, + List<Item> *field_list, + uint8 explain_flags, + bool is_analyze) +{ + ; + if (lex->explain_json) + make_explain_json_field_list(*field_list, is_analyze); + else + make_explain_field_list(*field_list, explain_flags, is_analyze); + + result->prepare(*field_list, NULL); +} + + int THD::send_explain_fields(select_result *result, uint8 explain_flags, - bool is_analyze, - Prepared_statement *stmt) + bool is_analyze) { List<Item> field_list; int rc; - if (lex->explain_json) - make_explain_json_field_list(field_list, is_analyze); - else - make_explain_field_list(field_list, explain_flags, is_analyze); - - result->prepare(field_list, NULL); - if (stmt) - rc= send_prep_stmt(stmt, result->field_count(field_list)) || - result->send_result_set_metadata(field_list, Protocol::SEND_EOF); - else - rc= result->send_result_set_metadata(field_list, - Protocol::SEND_NUM_ROWS | - Protocol::SEND_EOF); + prepare_explain_fields(result, &field_list, explain_flags, is_analyze); + rc= result->send_result_set_metadata(field_list, + Protocol::SEND_NUM_ROWS | + Protocol::SEND_EOF); return(rc); } diff --git a/sql/sql_class.h b/sql/sql_class.h index 706b72d9d06..67bcb639954 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -2174,7 +2174,6 @@ struct QUERY_START_TIME_INFO extern "C" void my_message_sql(uint error, const char *str, myf MyFlags); -class Prepared_statement; /** @class THD For each client connection we create a separate thread with THD serving as @@ -3739,8 +3738,10 @@ class THD :public Statement, void add_changed_table(TABLE *table); void add_changed_table(const char *key, size_t key_length); CHANGED_TABLE_LIST * changed_table_dup(const char *key, size_t key_length); + void prepare_explain_fields(select_result *result, List<Item> *field_list, + uint8 explain_flags, bool is_analyze); int send_explain_fields(select_result *result, uint8 explain_flags, - bool is_analyze, Prepared_statement *stmt); + bool is_analyze); void make_explain_field_list(List<Item> &field_list, uint8 explain_flags, bool is_analyze); void make_explain_json_field_list(List<Item> &field_list, bool is_analyze); diff --git a/sql/sql_explain.cc b/sql/sql_explain.cc index 96374fc1a33..5d977c6d5c2 100644 --- a/sql/sql_explain.cc +++ b/sql/sql_explain.cc @@ -164,8 +164,7 @@ int Explain_query::send_explain(THD *thd) LEX *lex= thd->lex; if (!(result= new (thd->mem_root) select_send(thd)) || - thd->send_explain_fields(result, lex->describe, lex->analyze_stmt, - NULL)) + thd->send_explain_fields(result, lex->describe, lex->analyze_stmt)) return 1; int res= 0; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index fa8279d9d6f..2593bac7462 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -6469,9 +6469,8 @@ static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables) */ if (!(result= new (thd->mem_root) select_send(thd))) return 1; /* purecov: inspected */ - thd->send_explain_fields(result, lex->describe, lex->analyze_stmt, - NULL); - + thd->send_explain_fields(result, lex->describe, lex->analyze_stmt); + /* This will call optimize() for all parts of query. The query plan is printed out below. diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index b9016e72410..e37c2006cc6 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -356,7 +356,7 @@ find_prepared_statement(THD *thd, ulong id) */ #ifndef EMBEDDED_LIBRARY -bool send_prep_stmt(Prepared_statement *stmt, uint columns) +static bool send_prep_stmt(Prepared_statement *stmt, uint columns) { NET *net= &stmt->thd->net; uchar buff[12]; @@ -394,7 +394,7 @@ bool send_prep_stmt(Prepared_statement *stmt, uint columns) DBUG_RETURN(error); } #else -bool send_prep_stmt(Prepared_statement *stmt, +static bool send_prep_stmt(Prepared_statement *stmt, uint columns __attribute__((unused))) { THD *thd= stmt->thd; @@ -2508,8 +2508,12 @@ static bool check_prepared_statement(Prepared_statement *stmt) if (!lex->result && !(lex->result= new (stmt->mem_root) select_send(thd))) DBUG_RETURN(TRUE); - res= thd->send_explain_fields(lex->result, lex->describe, - lex->analyze_stmt, stmt); + List<Item> field_list; + thd->prepare_explain_fields(lex->result, &field_list, + lex->describe, lex->analyze_stmt); + res= send_prep_stmt(stmt, lex->result->field_count(field_list)) || + lex->result->send_result_set_metadata(field_list, + Protocol::SEND_EOF); } else res= send_prep_stmt(stmt, 0); diff --git a/sql/sql_prepare.h b/sql/sql_prepare.h index ce6d9df22d0..ca040da341f 100644 --- a/sql/sql_prepare.h +++ b/sql/sql_prepare.h @@ -83,8 +83,6 @@ void mysqld_stmt_fetch(THD *thd, char *packet, uint packet_length); void mysqld_stmt_reset(THD *thd, char *packet); void mysql_stmt_get_longdata(THD *thd, char *pos, ulong packet_length); void reinit_stmt_before_use(THD *thd, LEX *lex); -class Prepared_statement; -bool send_prep_stmt(Prepared_statement *stmt, uint columns); my_bool bulk_parameters_iterations(THD *thd); my_bool bulk_parameters_set(THD *thd); diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index b2177c660de..ae4b2ead99d 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -20236,8 +20236,10 @@ static void test_proxy_header() test_proxy_header_localhost(); test_proxy_header_ignore(); } + #endif + static void print_metadata(MYSQL_RES *rs_metadata, int num_fields) { MYSQL_FIELD *fields= mysql_fetch_fields(rs_metadata);