#At file:///export/home/didrik/repo/next-mr-bf-wl5208-explain/ based on revid:mattias.jonsson@stripped
3318 Tor Didriksen 2010-09-13
WL#5208 Add --explain-protocol to mysql/MTR
This is a simplified version, compared to the description in the worklog.
We add a new --explain-protocol option, which makes mtr re-run
all SELECT queries with 'EXPLAIN EXTENDED' prepended.
@ client/mysqltest.cc
Adds explain-protocol option.
@ mysql-test/mysql-test-run.pl
Adds explain-protocol option.
modified:
client/mysqltest.cc
mysql-test/mysql-test-run.pl
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc 2010-09-28 15:30:47 +0000
+++ b/client/mysqltest.cc 2010-09-13 13:12:38 +0000
@@ -87,7 +87,7 @@ enum {
OPT_PS_PROTOCOL=OPT_MAX_CLIENT_OPTION, OPT_SP_PROTOCOL,
OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL, OPT_MAX_CONNECT_RETRIES,
OPT_MAX_CONNECTIONS, OPT_MARK_PROGRESS, OPT_LOG_DIR,
- OPT_TAIL_LINES, OPT_RESULT_FORMAT_VERSION
+ OPT_TAIL_LINES, OPT_RESULT_FORMAT_VERSION, OPT_EXPLAIN_PROTOCOL
};
static int record= 0, opt_sleep= -1;
@@ -107,6 +107,7 @@ static my_bool opt_mark_progress= 0;
static my_bool ps_protocol= 0, ps_protocol_enabled= 0;
static my_bool sp_protocol= 0, sp_protocol_enabled= 0;
static my_bool view_protocol= 0, view_protocol_enabled= 0;
+static my_bool explain_protocol= 0, explain_protocol_enabled= 0;
static my_bool cursor_protocol= 0, cursor_protocol_enabled= 0;
static my_bool parsing_disabled= 0;
static my_bool display_result_vertically= FALSE, display_result_lower= FALSE,
@@ -6166,6 +6167,9 @@ static struct my_option my_long_options[
{"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select.",
&view_protocol, &view_protocol, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
+ {"explain-protocol", OPT_EXPLAIN_PROTOCOL, "Explains all select.",
+ &explain_protocol, &explain_protocol, 0,
+ GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"connect_timeout", OPT_CONNECT_TIMEOUT,
"Number of seconds before connection timeout.",
&opt_connect_timeout, &opt_connect_timeout, 0, GET_UINT, REQUIRED_ARG,
@@ -7638,6 +7642,35 @@ void run_query(struct st_connection *cn,
DBUG_VOID_RETURN;
}
+
+void run_explain(struct st_connection *cn, struct st_command *command, int flags)
+{
+ if (explain_protocol_enabled &&
+ !command->expected_errors.count &&
+ match_re(&view_re, command->query))
+ {
+ st_command save_command= *command;
+ DYNAMIC_STRING query_str;
+ DYNAMIC_STRING ds_warning_messages;
+
+ init_dynamic_string(&ds_warning_messages, "", 0, 2048);
+ init_dynamic_string(&query_str, "EXPLAIN EXTENDED ", 256, 256);
+ dynstr_append_mem(&query_str, command->query,
+ command->end - command->query);
+ command->query= query_str.str;
+ command->query_len= query_str.length;
+ command->end= strend(command->query);
+
+ run_query(cn, command, flags);
+
+ dynstr_free(&query_str);
+ dynstr_free(&ds_warning_messages);
+
+ *command= save_command;
+ }
+}
+
+
/****************************************************************************/
/*
Functions to detect different SQL statements
@@ -8036,6 +8069,7 @@ int main(int argc, char **argv)
var_set_int("$PS_PROTOCOL", ps_protocol);
var_set_int("$SP_PROTOCOL", sp_protocol);
var_set_int("$VIEW_PROTOCOL", view_protocol);
+ var_set_int("$EXPLAIN_PROTOCOL", explain_protocol);
var_set_int("$CURSOR_PROTOCOL", cursor_protocol);
DBUG_PRINT("info",("result_file: '%s'",
@@ -8058,6 +8092,7 @@ int main(int argc, char **argv)
ps_protocol_enabled= ps_protocol;
sp_protocol_enabled= sp_protocol;
view_protocol_enabled= view_protocol;
+ explain_protocol_enabled= explain_protocol;
cursor_protocol_enabled= cursor_protocol;
/* Cursor protcol implies ps protocol */
if (cursor_protocol_enabled)
@@ -8292,6 +8327,7 @@ int main(int argc, char **argv)
save_file[0]= 0;
}
run_query(cur_con, command, flags);
+ run_explain(cur_con, command, flags);
command_executed++;
command->last_argument= command->end;
=== modified file 'mysql-test/mysql-test-run.pl'
--- a/mysql-test/mysql-test-run.pl 2010-09-28 15:17:29 +0000
+++ b/mysql-test/mysql-test-run.pl 2010-09-13 13:12:38 +0000
@@ -171,6 +171,7 @@ my $opt_ps_protocol;
my $opt_sp_protocol;
my $opt_cursor_protocol;
my $opt_view_protocol;
+my $opt_explain_protocol;
our $opt_debug;
our @opt_cases; # The test cases names in argv
@@ -852,6 +853,7 @@ sub command_line_setup {
'ps-protocol' => \$opt_ps_protocol,
'sp-protocol' => \$opt_sp_protocol,
'view-protocol' => \$opt_view_protocol,
+ 'explain-protocol' => \$opt_explain_protocol,
'cursor-protocol' => \$opt_cursor_protocol,
'ssl|with-openssl' => \$opt_ssl,
'skip-ssl' => \$opt_skip_ssl,
@@ -5039,6 +5041,11 @@ sub start_mysqltest ($) {
mtr_add_arg($args, "--sp-protocol");
}
+ if ( $opt_explain_protocol )
+ {
+ mtr_add_arg($args, "--explain-protocol");
+ }
+
if ( $opt_view_protocol )
{
mtr_add_arg($args, "--view-protocol");
@@ -5465,6 +5472,7 @@ Options to control what engine/variation
cursor-protocol Use the cursor protocol between client and server
(implies --ps-protocol)
view-protocol Create a view to execute all non updating queries
+ explain-protocol Run 'EXPLAIN EXTENDED' on all SELECT queries
sp-protocol Create a stored procedure to execute all queries
compress Use the compressed protocol between client and server
ssl Use ssl protocol between client and server
Attachment: [text/bzr-bundle] bzr/tor.didriksen@oracle.com-20100913131238-rlj9ez4g0uuw0q8d.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-bugfixing branch (tor.didriksen:3318) WL#5208 | Tor Didriksen | 6 Oct |