diff options
author | Julius Goryavsky <julius.goryavsky@mariadb.com> | 2021-12-26 12:51:04 +0100 |
---|---|---|
committer | Julius Goryavsky <julius.goryavsky@mariadb.com> | 2021-12-26 12:51:04 +0100 |
commit | 55bb933a880bf048ebc4ce6c6e239dcc8268958d (patch) | |
tree | a3a24c56995df41758205f8f6a4e3cbccf793a19 /client | |
parent | be20b3b03f9c522d17b3454214981506549063eb (diff) | |
parent | 681b7784b6bb3d735d0a745f5891844f43becc90 (diff) | |
download | mariadb-git-55bb933a880bf048ebc4ce6c6e239dcc8268958d.tar.gz |
Merge branch 10.4 into 10.5st-10.5-julius
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql.cc | 11 | ||||
-rw-r--r-- | client/mysqltest.cc | 102 |
2 files changed, 103 insertions, 10 deletions
diff --git a/client/mysql.cc b/client/mysql.cc index 00590868309..15325aec69d 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -100,8 +100,8 @@ extern "C" { # endif # endif #define HAVE_READLINE -#define USE_POPEN #endif +#define USE_POPEN } #ifdef HAVE_VIDATTR @@ -4202,11 +4202,6 @@ com_nopager(String *buffer __attribute__((unused)), } #endif - -/* - Sorry, you can't send the result to an editor in Win32 -*/ - #ifdef USE_POPEN static int com_edit(String *buffer,char *line __attribute__((unused))) @@ -4227,7 +4222,7 @@ com_edit(String *buffer,char *line __attribute__((unused))) if (!(editor = (char *)getenv("EDITOR")) && !(editor = (char *)getenv("VISUAL"))) - editor = "vi"; + editor = IF_WIN("notepad","vi"); strxmov(buff,editor," ",filename,NullS); if ((error= system(buff))) { @@ -4242,7 +4237,7 @@ com_edit(String *buffer,char *line __attribute__((unused))) if ((fd = my_open(filename,O_RDONLY, MYF(MY_WME))) < 0) goto err; (void) buffer->alloc((uint) stat_arg.st_size); - if ((tmp=read(fd,(char*) buffer->ptr(),buffer->alloced_length())) >= 0L) + if ((tmp=(int)my_read(fd,(uchar*) buffer->ptr(),buffer->alloced_length(),MYF(0))) >= 0) buffer->length((uint) tmp); else buffer->length(0); diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 3ba60a5643f..f8f5fd694aa 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -133,6 +133,7 @@ static my_bool disable_info= 1; static my_bool abort_on_error= 1, opt_continue_on_error= 0; static my_bool server_initialized= 0; static my_bool is_windows= 0; +static my_bool optimizer_trace_active= 0; static char **default_argv; static const char *load_default_groups[]= { "mysqltest", "mariadb-test", "client", "client-server", "client-mariadb", @@ -389,6 +390,7 @@ enum enum_commands { Q_MOVE_FILE, Q_REMOVE_FILES_WILDCARD, Q_SEND_EVAL, Q_ENABLE_PREPARE_WARNINGS, Q_DISABLE_PREPARE_WARNINGS, Q_RESET_CONNECTION, + Q_OPTIMIZER_TRACE, Q_UNKNOWN, /* Unknown command. */ Q_COMMENT, /* Comments, ignored. */ Q_COMMENT_WITH_COMMAND, @@ -499,7 +501,7 @@ const char *command_names[]= "enable_prepare_warnings", "disable_prepare_warnings", "reset_connection", - + "optimizer_trace", 0 }; @@ -644,6 +646,9 @@ void free_all_replace(){ } void var_set_int(const char* name, int value); +void enable_optimizer_trace(struct st_connection *con); +void display_optimizer_trace(struct st_connection *con, + DYNAMIC_STRING *ds); class LogFile { @@ -1542,6 +1547,8 @@ static void die(const char *fmt, ...) { char buff[DIE_BUFF_SIZE]; va_list args; + DBUG_ENTER("die"); + va_start(args, fmt); make_error_message(buff, sizeof(buff), fmt, args); really_die(buff); @@ -7893,7 +7900,7 @@ static void handle_no_active_connection(struct st_command *command, */ void run_query_normal(struct st_connection *cn, struct st_command *command, - int flags, char *query, size_t query_len, + int flags, const char *query, size_t query_len, DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings) { MYSQL_RES *res= 0; @@ -8012,6 +8019,7 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, /* If we come here the query is both executed and read successfully */ handle_no_error(command); + display_optimizer_trace(cn, ds); revert_properties(); end: @@ -9632,6 +9640,9 @@ int main(int argc, char **argv) case Q_RESET_CONNECTION: do_reset_connection(); break; + case Q_OPTIMIZER_TRACE: + enable_optimizer_trace(cur_con); + break; case Q_SEND_SHUTDOWN: handle_command_error(command, mysql_shutdown(cur_con->mysql, @@ -11294,3 +11305,90 @@ char *mysql_authentication_dialog_ask(MYSQL *mysql, int type, return buf; } + +/* + Enable optimizer trace for the next command +*/ + +LEX_CSTRING enable_optimizer_trace_query= +{ + STRING_WITH_LEN("set @mysqltest_save_optimzer_trace=@@optimizer_trace,@@optimizer_trace=\"enabled=on\"") +}; + +LEX_CSTRING restore_optimizer_trace_query= +{ + STRING_WITH_LEN("set @@optimizer_trace=@mysqltest_save_optimzer_trace") +}; + + +LEX_CSTRING display_optimizer_trace_query +{ + STRING_WITH_LEN("SELECT * from information_schema.optimizer_trace") +}; + + +void enable_optimizer_trace(struct st_connection *con) +{ + MYSQL *mysql= con->mysql; + my_bool save_ps_protocol_enabled= ps_protocol_enabled; + my_bool save_view_protocol_enabled= view_protocol_enabled; + DYNAMIC_STRING ds_result; + DYNAMIC_STRING ds_warnings; + struct st_command command; + DBUG_ENTER("enable_optimizer_trace"); + + if (!mysql) + DBUG_VOID_RETURN; + ps_protocol_enabled= view_protocol_enabled= 0; + + init_dynamic_string(&ds_result, NULL, 0, 256); + init_dynamic_string(&ds_warnings, NULL, 0, 256); + bzero(&command, sizeof(command)); + + run_query_normal(con, &command, QUERY_SEND_FLAG | QUERY_REAP_FLAG, + enable_optimizer_trace_query.str, + enable_optimizer_trace_query.length, + &ds_result, &ds_warnings); + dynstr_free(&ds_result); + dynstr_free(&ds_warnings); + ps_protocol_enabled= save_ps_protocol_enabled; + view_protocol_enabled= save_view_protocol_enabled; + optimizer_trace_active= 1; + DBUG_VOID_RETURN; +} + + +void display_optimizer_trace(struct st_connection *con, + DYNAMIC_STRING *ds) +{ + my_bool save_ps_protocol_enabled= ps_protocol_enabled; + my_bool save_view_protocol_enabled= view_protocol_enabled; + DYNAMIC_STRING ds_result; + DYNAMIC_STRING ds_warnings; + struct st_command command; + DBUG_ENTER("display_optimizer_trace"); + + if (!optimizer_trace_active) + DBUG_VOID_RETURN; + + optimizer_trace_active= 0; + ps_protocol_enabled= view_protocol_enabled= 0; + + init_dynamic_string(&ds_result, NULL, 0, 256); + init_dynamic_string(&ds_warnings, NULL, 0, 256); + bzero(&command, sizeof(command)); + + run_query_normal(con, &command, QUERY_SEND_FLAG | QUERY_REAP_FLAG, + display_optimizer_trace_query.str, + display_optimizer_trace_query.length, + ds, &ds_warnings); + run_query_normal(con, &command, QUERY_SEND_FLAG | QUERY_REAP_FLAG, + restore_optimizer_trace_query.str, + restore_optimizer_trace_query.length, + ds, &ds_warnings); + dynstr_free(&ds_result); + dynstr_free(&ds_warnings); + ps_protocol_enabled= save_ps_protocol_enabled; + view_protocol_enabled= save_view_protocol_enabled; + DBUG_VOID_RETURN; +} |