#At file:///export/home/jl208045/mysql/wl4800/mysql-next-mr-opt-backporting-wl4800-mtrtrace/ based on revid:guilhem@stripped
3216 Jorgen Loland 2010-09-28
WL#5581: "Add --opt-trace-protocol to MTR"
Add a new opt-trace-protocol to mtr so that existing
regression test suites can be used to test optimizer tracing.
The opt-trace-protocol does this:
1) Enables optimizer tracing
2) Prints the optimizer trace for every statement
eligible for tracing
The statements eligible for tracing are:
[EXPLAIN [EXTENDED]] SELECT
INSERT
DELETE
UPDATE
@ client/mysqltest.cc
Added optimizer trace protocol
@ mysql-test/mysql-test-run.pl
Added optimizer trace protocol
modified:
client/mysqltest.cc
mysql-test/mysql-test-run.pl
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc 2010-09-08 07:10:51 +0000
+++ b/client/mysqltest.cc 2010-09-28 08:58:16 +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_TRACE_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 opt_trace_protocol= 0, opt_trace_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,
@@ -194,6 +195,8 @@ static ulong connection_retry_sleep= 100
static my_regex_t ps_re; /* the query can be run using PS protocol */
static my_regex_t sp_re; /* the query can be run as a SP */
static my_regex_t view_re; /* the query can be run as a view*/
+/* the query can be traced with optimizer trace*/
+static my_regex_t opt_trace_re;
static void init_re(void);
static int match_re(my_regex_t *, char *);
@@ -6158,6 +6161,10 @@ 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},
+ {"opt-trace-protocol", OPT_TRACE_PROTOCOL,
+ "Trace DML statements with optimizer trace",
+ &opt_trace_protocol, &opt_trace_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,
@@ -7630,6 +7637,36 @@ void run_query(struct st_connection *cn,
DBUG_VOID_RETURN;
}
+/**
+ Display the optimizer trace produced by the last executed statement.
+ */
+void display_opt_trace(struct st_connection *cn,
+ struct st_command *command,
+ int flags)
+{
+ if (!disable_query_log &&
+ opt_trace_protocol_enabled &&
+ !command->expected_errors.count &&
+ match_re(&opt_trace_re, command->query))
+ {
+ st_command save_command= *command;
+ DYNAMIC_STRING query_str;
+ init_dynamic_string(&query_str,
+ "SELECT trace FROM information_schema.optimizer_trace "
+ "/* injected by --opt-trace-mode */",
+ 128, 128);
+
+ 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);
+ *command= save_command;
+ }
+}
+
/****************************************************************************/
/*
Functions to detect different SQL statements
@@ -7689,9 +7726,18 @@ void init_re(void)
"^("
"[[:space:]]*SELECT[[:space:]])";
+ const char *opt_trace_re_str =
+ "^("
+ "[[:space:]]*INSERT[[:space:]]|"
+ "[[:space:]]*UPDATE[[:space:]]|"
+ "[[:space:]]*DELETE[[:space:]]|"
+ "[[:space:]]*EXPLAIN[[:space:]]|"
+ "[[:space:]]*SELECT[[:space:]])";
+
init_re_comp(&ps_re, ps_re_str);
init_re_comp(&sp_re, sp_re_str);
init_re_comp(&view_re, view_re_str);
+ init_re_comp(&opt_trace_re, opt_trace_re_str);
}
@@ -8028,6 +8074,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("$OPT_TRACE_PROTOCOL", opt_trace_protocol);
var_set_int("$CURSOR_PROTOCOL", cursor_protocol);
DBUG_PRINT("info",("result_file: '%s'",
@@ -8050,6 +8097,7 @@ int main(int argc, char **argv)
ps_protocol_enabled= ps_protocol;
sp_protocol_enabled= sp_protocol;
view_protocol_enabled= view_protocol;
+ opt_trace_protocol_enabled= opt_trace_protocol;
cursor_protocol_enabled= cursor_protocol;
/* Cursor protcol implies ps protocol */
if (cursor_protocol_enabled)
@@ -8282,6 +8330,7 @@ int main(int argc, char **argv)
save_file[0]= 0;
}
run_query(cur_con, command, flags);
+ display_opt_trace(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-03 20:49:28 +0000
+++ b/mysql-test/mysql-test-run.pl 2010-09-28 08:58:16 +0000
@@ -171,6 +171,7 @@ my $opt_ps_protocol;
my $opt_sp_protocol;
my $opt_cursor_protocol;
my $opt_view_protocol;
+my $opt_trace_protocol;
our $opt_debug;
our @opt_cases; # The test cases names in argv
@@ -843,6 +844,7 @@ sub command_line_setup {
'ps-protocol' => \$opt_ps_protocol,
'sp-protocol' => \$opt_sp_protocol,
'view-protocol' => \$opt_view_protocol,
+ 'opt-trace-protocol' => \$opt_trace_protocol,
'cursor-protocol' => \$opt_cursor_protocol,
'ssl|with-openssl' => \$opt_ssl,
'skip-ssl' => \$opt_skip_ssl,
@@ -1441,6 +1443,11 @@ sub command_line_setup {
unless @valgrind_args;
}
+ if ( $opt_trace_protocol )
+ {
+ push(@opt_extra_mysqld_opt, "--optimizer_trace=enabled=on,one_line=off");
+ }
+
if ( $opt_valgrind )
{
# Set valgrind_options to default unless already defined
@@ -5029,6 +5036,11 @@ sub start_mysqltest ($) {
mtr_add_arg($args, "--view-protocol");
}
+ if ( $opt_trace_protocol )
+ {
+ mtr_add_arg($args, "--opt-trace-protocol");
+ }
+
if ( $opt_cursor_protocol )
{
mtr_add_arg($args, "--cursor-protocol");
@@ -5450,6 +5462,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
+ opt-trace-protocol Print optimizer trace
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/jorgen.loland@oracle.com-20100928085816-exj41towenor8rux.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-bugfixing branch (jorgen.loland:3216) WL#5581 | Jorgen Loland | 28 Sep |