summaryrefslogtreecommitdiff
path: root/sql/sql_class.h
diff options
context:
space:
mode:
authorSergey Petrunya <psergey@askmonty.org>2011-10-27 21:41:19 +0400
committerSergey Petrunya <psergey@askmonty.org>2011-10-27 21:41:19 +0400
commit286a751490cd109a470e30ef486755cd4922802d (patch)
treec872e9c0ead4815600c2e1e490346e5805d16fec /sql/sql_class.h
parent08e9e6a790ea6ba8bbe6fa5c5bd54677f4add072 (diff)
parentba09d25abc1fd3dbe55f1d7974cfe6a1ebda4df0 (diff)
downloadmariadb-git-286a751490cd109a470e30ef486755cd4922802d.tar.gz
MWL#182: Explain running statements
- Merge with 5.3-main
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r--sql/sql_class.h96
1 files changed, 90 insertions, 6 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 0085e982abb..278c3d7c0cc 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1452,6 +1452,19 @@ struct Ha_data
};
+class select_result_explain_buffer;
+
+class Show_explain_request
+{
+public:
+ THD *target_thd;
+ THD *request_thd;
+
+ select_result_explain_buffer *explain_buf;
+
+ static void get_explain_data(void *arg);
+};
+
/**
@class THD
For each client connection we create a separate thread with THD serving as
@@ -2007,6 +2020,8 @@ public:
killed_state volatile killed;
+ bool check_killed();
+
/* scramble - random string sent to client on handshake */
char scramble[SCRAMBLE_LENGTH+1];
@@ -2188,6 +2203,16 @@ public:
void close_active_vio();
#endif
void awake(killed_state state_to_set);
+
+
+ /*
+ This is what allows this thread to serve as a target for others to
+ schedule Async Procedure Calls on.
+
+ It's possible to schedule arbitrary C function call but currently this
+ facility is used only by SHOW EXPLAIN code (See Show_explain_request)
+ */
+ Apc_target apc_target;
#ifndef MYSQL_CLIENT
enum enum_binlog_query_type {
@@ -2319,6 +2344,7 @@ public:
void add_changed_table(const char *key, long key_length);
CHANGED_TABLE_LIST * changed_table_dup(const char *key, long key_length);
int send_explain_fields(select_result *result);
+ void make_explain_field_list(List<Item> &field_list);
#ifndef EMBEDDED_LIBRARY
/**
Clear the current error, if any.
@@ -2762,10 +2788,42 @@ public:
class JOIN;
-class select_result :public Sql_alloc {
+/* Pure interface for sending tabular data */
+class select_result_sink: public Sql_alloc
+{
+public:
+ /*
+ send_data returns 0 on ok, 1 on error and -1 if data was ignored, for
+ example for a duplicate row entry written to a temp table.
+ */
+ virtual int send_data(List<Item> &items)=0;
+ virtual ~select_result_sink() {};
+};
+
+
+/*
+ Interface for sending tabular data, together with some other stuff:
+
+ - Primary purpose seems to be seding typed tabular data:
+ = the DDL is sent with send_fields()
+ = the rows are sent with send_data()
+ Besides that,
+ - there seems to be an assumption that the sent data is a result of
+ SELECT_LEX_UNIT *unit,
+ - nest_level is used by SQL parser
+*/
+
+class select_result :public select_result_sink
+{
protected:
THD *thd;
+ /*
+ All descendant classes have their send_data() skip the first
+ unit->offset_limit_cnt rows sent. Select_materialize
+ also uses unit->get_unit_column_types().
+ */
SELECT_LEX_UNIT *unit;
+ /* Something used only by the parser: */
int nest_level;
public:
select_result();
@@ -2784,11 +2842,6 @@ public:
virtual uint field_count(List<Item> &fields) const
{ return fields.elements; }
virtual bool send_fields(List<Item> &list, uint flags)=0;
- /*
- send_data returns 0 on ok, 1 on error and -1 if data was ignored, for
- example for a duplicate row entry written to a temp table.
- */
- virtual int send_data(List<Item> &items)=0;
virtual bool initialize_tables (JOIN *join=0) { return 0; }
virtual void send_error(uint errcode,const char *err);
virtual bool send_eof()=0;
@@ -2822,6 +2875,35 @@ public:
/*
+ A select result sink that collects the sent data and then can flush it to
+ network when requested.
+
+ This class is targeted at collecting EXPLAIN output:
+ - Unoptimized data storage (can't handle big datasets)
+ - Unlike select_result class, we don't assume that the sent data is an
+ output of a SELECT_LEX_UNIT (and so we dont apply "LIMIT x,y" from the
+ unit)
+*/
+
+class select_result_explain_buffer : public select_result_sink
+{
+public:
+ THD *thd;
+ Protocol *protocol;
+ select_result_explain_buffer(){};
+
+ /* The following is called in the child thread: */
+ int send_data(List<Item> &items);
+
+ /* this will be called in the parent thread: */
+ void flush_data();
+
+ List<String> data_rows;
+};
+
+
+
+/*
Base class for select_result descendands which intercept and
transform result set rows. As the rows are not sent to the client,
sending of result set metadata should be suppressed as well.
@@ -3406,6 +3488,8 @@ class user_var_entry
DTCollation collation;
};
+user_var_entry *get_variable(HASH *hash, LEX_STRING &name,
+ bool create_if_not_exists);
/*
Unique -- class for unique (removing of duplicates).