Skip to content

Commit 4a1fb00

Browse files
committed
Bug#29899022: REDUCE DEPENDENCIES ON PROTOCOL.H
Make the THD class have pointers to the Protocol_text and Protocol_binary instances, so that sql_class.h doesn't have to include protocol.h and protocol_classic.h. Move the Query_fetch_protocol_binary class definition from sql_prepare.h to sql_prepare.cc, since it is only used in that file. Move PTI_simple_ident_q_3d::itemize() from parse_tree_items.h to parse_tree_items.h, so that the header doesn't need to include protocol.h. Include plugin.h instead of protocol.h from thd_var_access.h, as it is only used to get the definition of MYSQL_THD. Change-Id: Iecc1b4986b45533d9b2187e7a25d6c4dd932f6f0
1 parent 0771e9b commit 4a1fb00

22 files changed

+143
-108
lines changed

plugin/group_replication/src/applier.cc

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "plugin/group_replication/include/plugin_server_include.h"
4040
#include "plugin/group_replication/include/services/notification/notification.h"
4141
#include "plugin/group_replication/libmysqlgcs/include/mysql/gcs/gcs_member_identifier.h"
42+
#include "sql/protocol_classic.h"
4243

4344
char applier_module_channel_name[] = "group_replication_applier";
4445
bool applier_thread_is_exiting = false;

plugin/innodb_memcached/innodb_memcache/src/handler_api.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*****************************************************************************
22
3-
Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
3+
Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
44
55
This program is free software; you can redistribute it and/or modify it under
66
the terms of the GNU General Public License, version 2.0, as published by the
@@ -51,6 +51,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
5151
#include "sql/log_event.h"
5252
#include "sql/mysqld.h"
5353
#include "sql/mysqld_thd_manager.h"
54+
#include "sql/protocol_classic.h"
5455
#include "sql/sql_base.h"
5556
#include "sql/sql_class.h"
5657
#include "sql/sql_handler.h"

plugin/semisync/semisync_master_ack_receiver.cc

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
it under the terms of the GNU General Public License, version 2.0,
@@ -34,6 +34,8 @@
3434
#include "plugin/semisync/semisync.h"
3535
#include "plugin/semisync/semisync_master.h"
3636
#include "plugin/semisync/semisync_master_socket_listener.h"
37+
#include "sql/protocol_classic.h"
38+
#include "sql/sql_class.h"
3739

3840
extern ReplSemiSyncMaster *repl_semisync;
3941

plugin/semisync/semisync_master_plugin.cc

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "plugin/semisync/semisync_master.h"
3333
#include "plugin/semisync/semisync_master_ack_receiver.h"
3434
#include "sql/current_thd.h"
35+
#include "sql/protocol_classic.h"
3536
#include "sql/sql_class.h" // THD
3637
#include "typelib.h"
3738

sql/ha_ndbcluster_binlog.cc

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "sql/ndb_table_guard.h"
6262
#include "sql/ndb_tdc.h"
6363
#include "sql/ndb_thd.h"
64+
#include "sql/protocol_classic.h"
6465
#include "sql/rpl_injector.h"
6566
#include "sql/rpl_slave.h"
6667
#include "sql/sql_lex.h"

sql/item_func.cc

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
#include "sql/mdl.h"
9696
#include "sql/mysqld.h" // log_10 stage_user_sleep
9797
#include "sql/parse_tree_helpers.h" // PT_item_list
98+
#include "sql/protocol.h"
9899
#include "sql/psi_memory_key.h"
99100
#include "sql/resourcegroups/resource_group.h"
100101
#include "sql/resourcegroups/resource_group_basic_types.h"
@@ -125,9 +126,6 @@
125126
#include "template_utils.h" // pointer_cast
126127
#include "thr_mutex.h"
127128

128-
class Protocol;
129-
class sp_rcontext;
130-
131129
using std::max;
132130
using std::min;
133131

sql/log.cc

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include "sql/field.h"
8383
#include "sql/handler.h"
8484
#include "sql/mysqld.h"
85+
#include "sql/protocol_classic.h"
8586
#include "sql/psi_memory_key.h" // key_memory_File_query_log_name
8687
#include "sql/query_options.h"
8788
#include "sql/sql_audit.h" // mysql_audit_general_log

sql/parse_tree_items.cc

+21
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
#include "my_dbug.h"
2626
#include "my_sqlcommand.h"
2727
#include "mysql/udf_registration_types.h"
28+
#include "mysql_com.h"
2829
#include "sql/auth/auth_acls.h"
2930
#include "sql/item_cmpfunc.h" // Item_func_eq
3031
#include "sql/mysqld.h" // using_udf_functions
3132
#include "sql/parse_tree_nodes.h"
33+
#include "sql/protocol.h"
3234
#include "sql/sp.h"
3335
#include "sql/sp_pcontext.h" // sp_pcontext
3436
#include "sql/sql_udf.h"
@@ -377,6 +379,25 @@ bool PTI_simple_ident_ident::itemize(Parse_context *pc, Item **res) {
377379
return *res == NULL;
378380
}
379381

382+
bool PTI_simple_ident_q_3d::itemize(Parse_context *pc, Item **res) {
383+
if (super::itemize(pc, res)) return true;
384+
385+
THD *thd = pc->thd;
386+
const char *schema =
387+
thd->get_protocol()->has_client_capability(CLIENT_NO_SCHEMA) ? nullptr
388+
: db;
389+
if (pc->select->no_table_names_allowed) {
390+
my_error(ER_TABLENAME_NOT_ALLOWED_HERE, MYF(0), table, thd->where);
391+
}
392+
if ((pc->select->parsing_place != CTX_HAVING) ||
393+
(pc->select->get_in_sum_expr() > 0)) {
394+
*res = new (pc->mem_root) Item_field(POS(), schema, table, field);
395+
} else {
396+
*res = new (pc->mem_root) Item_ref(POS(), schema, table, field);
397+
}
398+
return *res == nullptr || (*res)->itemize(pc, res);
399+
}
400+
380401
bool PTI_simple_ident_q_2d::itemize(Parse_context *pc, Item **res) {
381402
THD *thd = pc->thd;
382403
LEX *lex = thd->lex;

sql/parse_tree_items.h

+2-21
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,18 @@
3434
#include "my_inttypes.h"
3535
#include "my_sys.h"
3636
#include "my_time.h"
37-
#include "mysql_com.h"
3837
#include "mysqld_error.h"
3938
#include "sql/field.h"
4039
#include "sql/item.h"
40+
#include "sql/item_cmpfunc.h"
4141
#include "sql/item_create.h" // Create_func
4242
#include "sql/item_func.h"
43-
#include "sql/item_strfunc.h"
4443
#include "sql/item_subselect.h"
4544
#include "sql/item_sum.h" // Item_sum_count
4645
#include "sql/item_timefunc.h" // Item_func_now_local
4746
#include "sql/parse_location.h"
4847
#include "sql/parse_tree_helpers.h" // Parse_tree_item
4948
#include "sql/parse_tree_node_base.h"
50-
#include "sql/protocol.h"
5149
#include "sql/set_var.h"
5250
#include "sql/sp_head.h" // sp_head
5351
#include "sql/sql_class.h"
@@ -157,24 +155,7 @@ class PTI_simple_ident_q_3d : public Parse_tree_item {
157155
const char *table_arg, const char *field_arg)
158156
: super(pos), db(db_arg), table(table_arg), field(field_arg) {}
159157

160-
bool itemize(Parse_context *pc, Item **res) override {
161-
if (super::itemize(pc, res)) return true;
162-
163-
THD *thd = pc->thd;
164-
const char *schema =
165-
thd->get_protocol()->has_client_capability(CLIENT_NO_SCHEMA) ? NULL
166-
: db;
167-
if (pc->select->no_table_names_allowed) {
168-
my_error(ER_TABLENAME_NOT_ALLOWED_HERE, MYF(0), table, thd->where);
169-
}
170-
if ((pc->select->parsing_place != CTX_HAVING) ||
171-
(pc->select->get_in_sum_expr() > 0)) {
172-
*res = new (pc->mem_root) Item_field(POS(), schema, table, field);
173-
} else {
174-
*res = new (pc->mem_root) Item_ref(POS(), schema, table, field);
175-
}
176-
return *res == NULL || (*res)->itemize(pc, res);
177-
}
158+
bool itemize(Parse_context *pc, Item **res) override;
178159
};
179160

180161
/**

sql/protocol.h

+1-14
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,12 @@
2424
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
2525

2626
#include "my_dbug.h"
27+
#include "mysql/com_data.h"
2728
#include "mysql/mysql_lex_string.h" // LEX_STRING
2829
#include "mysql_com.h" // mysql_enum_shutdown_level
2930
#include "mysql_time.h" // MYSQL_TIME
3031
#include "sql_string.h" // String
3132
#include "violite.h" /* SSL && enum_vio_type */
32-
#ifdef HAVE_OPENSSL
33-
#define SSL_handle SSL *
34-
#else
35-
#define SSL_handle void *
36-
#endif
37-
38-
#ifdef __cplusplus
39-
class THD;
40-
#define MYSQL_THD THD *
41-
#else
42-
#define MYSQL_THD void *
43-
#endif
44-
45-
#include "mysql/com_data.h"
4633

4734
class my_decimal;
4835
class Send_field;

sql/rpl_channel_service_interface.cc

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "sql/log_event.h"
5252
#include "sql/mysqld.h" // opt_mts_slave_parallel_workers
5353
#include "sql/mysqld_thd_manager.h" // Global_THD_manager
54+
#include "sql/protocol_classic.h"
5455
#include "sql/rpl_gtid.h"
5556
#include "sql/rpl_info_factory.h"
5657
#include "sql/rpl_info_handler.h"

sql/server_component/clone_protocol_service.cc

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "my_byteorder.h"
3030
#include "mysql.h"
3131
#include "sql/mysqld.h"
32+
#include "sql/protocol_classic.h"
3233
#include "sql/set_var.h"
3334
#include "sql/sql_class.h"
3435
#include "sql/sql_show.h"

sql/set_var.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1323,8 +1323,8 @@ int set_var_collation_client::update(THD *thd) {
13231323
->is_enabled())
13241324
thd->session_tracker.get_tracker(SESSION_STATE_CHANGE_TRACKER)
13251325
->mark_as_changed(thd, NULL);
1326-
thd->protocol_text.init(thd);
1327-
thd->protocol_binary.init(thd);
1326+
thd->protocol_text->init(thd);
1327+
thd->protocol_binary->init(thd);
13281328
return 0;
13291329
}
13301330

sql/sql_admin.cc

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
#include "sql/mysqld.h" // key_file_misc
7171
#include "sql/partition_element.h" // PART_ADMIN
7272
#include "sql/protocol.h"
73+
#include "sql/protocol_classic.h"
7374
#include "sql/rpl_group_replication.h" // is_group_replication_running
7475
#include "sql/rpl_gtid.h"
7576
#include "sql/sp.h" // Sroutine_hash_entry

sql/sql_class.cc

+41-4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
#include "sql/mysqld.h" // global_system_variables ...
6464
#include "sql/mysqld_thd_manager.h" // Global_THD_manager
6565
#include "sql/parse_location.h"
66+
#include "sql/protocol.h"
67+
#include "sql/protocol_classic.h"
6668
#include "sql/psi_memory_key.h"
6769
#include "sql/query_result.h"
6870
#include "sql/rpl_rli.h" // Relay_log_info
@@ -364,6 +366,8 @@ THD::THD(bool enable_plugins)
364366
m_current_query_partial_plans(0),
365367
m_main_security_ctx(this),
366368
m_security_ctx(&m_main_security_ctx),
369+
protocol_text(new Protocol_text),
370+
protocol_binary(new Protocol_binary),
367371
query_plan(this),
368372
m_current_stage_key(0),
369373
current_mutex(NULL),
@@ -519,10 +523,10 @@ THD::THD(bool enable_plugins)
519523
sp_func_cache = NULL;
520524

521525
/* Protocol */
522-
m_protocol = &protocol_text; // Default protocol
523-
protocol_text.init(this);
524-
protocol_binary.init(this);
525-
protocol_text.set_client_capabilities(0); // minimalistic client
526+
m_protocol = protocol_text.get(); // Default protocol
527+
protocol_text->init(this);
528+
protocol_binary->init(this);
529+
protocol_text->set_client_capabilities(0); // minimalistic client
526530

527531
/*
528532
Make sure thr_lock_info_init() is called for threads which do not get
@@ -2759,3 +2763,36 @@ void THD::cleanup_after_parse_error() {
27592763
}
27602764
}
27612765
}
2766+
2767+
bool THD::is_classic_protocol() const {
2768+
return get_protocol()->type() == Protocol::PROTOCOL_BINARY ||
2769+
get_protocol()->type() == Protocol::PROTOCOL_TEXT;
2770+
}
2771+
2772+
bool THD::is_connected() {
2773+
/*
2774+
All system threads (e.g., the slave IO thread) are connected but
2775+
not using vio. So this function always returns true for all
2776+
system threads.
2777+
*/
2778+
if (system_thread) return true;
2779+
2780+
if (is_classic_protocol())
2781+
return get_protocol()->connection_alive() &&
2782+
vio_is_connected(get_protocol_classic()->get_vio());
2783+
2784+
return get_protocol()->connection_alive();
2785+
}
2786+
2787+
void THD::push_protocol(Protocol *protocol) {
2788+
DBUG_ASSERT(m_protocol != nullptr);
2789+
DBUG_ASSERT(protocol != nullptr);
2790+
m_protocol->push_protocol(protocol);
2791+
m_protocol = protocol;
2792+
}
2793+
2794+
void THD::pop_protocol() {
2795+
DBUG_ASSERT(m_protocol != nullptr);
2796+
m_protocol = m_protocol->pop_protocol();
2797+
DBUG_ASSERT(m_protocol != nullptr);
2798+
}

0 commit comments

Comments
 (0)