diff --git a/client/client_priv.h b/client/client_priv.h index 344d65de98d..98e3febdea2 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -177,6 +177,7 @@ enum options_client { OPT_LRA_PAGES_BEFORE_SLEEP, OPT_TIMEOUT, OPT_RECEIVE_BUFFER_SIZE, + OPT_LONG_QUERY_TIME, /* Add new option above this */ OPT_MAX_CLIENT_OPTION }; diff --git a/client/mysqldump.cc b/client/mysqldump.cc index d688cd0ea48..b68e1c7d298 100644 --- a/client/mysqldump.cc +++ b/client/mysqldump.cc @@ -111,6 +111,8 @@ /* Maximum number of fields per table */ #define MAX_FIELDS 4000 +#define LONG_TIMEOUT ((ulong)3600L * 24L * 365L) + using std::string; static void add_load_option(DYNAMIC_STRING *str, const char *option, @@ -166,6 +168,7 @@ static ulong opt_lra_size = 0; static ulong opt_lra_sleep = 0; static ulong opt_lra_pages_before_sleep = 0; static ulong opt_timeout = 0; +static ulong opt_long_query_time = 0; static uint my_end_arg; static char *opt_mysql_unix_port = 0; static char *opt_bind_addr = NULL; @@ -415,6 +418,11 @@ static struct my_option my_long_options[] = { {"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.", &log_error_file, &log_error_file, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"long_query_time", OPT_LONG_QUERY_TIME, + "Set long_query_time for the session of this dump. Setting to 0 means " + "using the server value.", + &opt_long_query_time, &opt_long_query_time, 0, GET_ULONG, REQUIRED_ARG, + 86400, 0, LONG_TIMEOUT, 0, 0, 0}, {"lra_size", OPT_LRA_SIZE, "Set innodb_lra_size for the session of this dump.", &opt_lra_size, &opt_lra_size, 0, GET_ULONG, REQUIRED_ARG, 0, 0, 16384, 0, 0, 0}, @@ -1628,6 +1636,13 @@ static int connect_to_db(char *host, char *user, char *passwd) { "SESSION NET_WRITE_TIMEOUT= 700 "); if (mysql_query_with_error_report(mysql, 0, buff)) DBUG_RETURN(1); } + + if (opt_long_query_time) { + snprintf(buff, sizeof(buff), "SET session long_query_time=%lu", + opt_long_query_time); + if (mysql_query_with_error_report(mysql, 0, buff)) DBUG_RETURN(1); + } + DBUG_RETURN(0); } /* connect_to_db */ diff --git a/mysql-test/r/mysqldump-long-query-time.result b/mysql-test/r/mysqldump-long-query-time.result new file mode 100644 index 00000000000..dbb88cb9d0a --- /dev/null +++ b/mysql-test/r/mysqldump-long-query-time.result @@ -0,0 +1,24 @@ +set @my_slow_query_log_file = @@global.slow_query_log_file; +set @my_slow_query_log = @@global.slow_query_log; +set global slow_query_log_file = "mysqldump_long_query_time-slow.log"; +set global slow_query_log = ON; +create database mysqldump_long_query_time; +use mysqldump_long_query_time; + +# Check the slow log result. We shouldn't find any query. +set @my_long_query_time = @@global.long_query_time; +set global long_query_time = 0; +create table t1 (i int, c char(255)); +insert into t1 values (0, lpad('a', 250, 'b')); +insert into t1 select i+1,c from t1; +insert into t1 select i+2,c from t1; +insert into t1 select i+4,c from t1; +insert into t1 select i+8,c from t1; +insert into t1 select i+16,c from t1; + +# Check the slow log result. One "select" query should be found. +select @@collation_database; +drop database mysqldump_long_query_time; +set @@global.slow_query_log_file = @my_slow_query_log_file; +set @@global.slow_query_log = @my_slow_query_log; +set @@global.long_query_time = @my_long_query_time; diff --git a/mysql-test/t/mysqldump-long-query-time.test b/mysql-test/t/mysqldump-long-query-time.test new file mode 100644 index 00000000000..3a4199e573d --- /dev/null +++ b/mysql-test/t/mysqldump-long-query-time.test @@ -0,0 +1,62 @@ +set @my_slow_query_log_file = @@global.slow_query_log_file; +set @my_slow_query_log = @@global.slow_query_log; +set global slow_query_log_file = "mysqldump_long_query_time-slow.log"; +set global slow_query_log = ON; + +create database mysqldump_long_query_time; +use mysqldump_long_query_time; + +# By default, a long_query_time of 86400 is set. +--exec $MYSQL_DUMP mysqldump_long_query_time > /dev/null + +let MYSQLD_DATADIR = `select @@datadir`; +--echo +--echo # Check the slow log result. We shouldn't find any query. +--perl +open FILE, "$ENV{'MYSQLD_DATADIR'}/mysqldump_long_query_time-slow.log" or die; +my @lines = ; +foreach $line (@lines) { + if ($line =~ /^select/) { + print $line; + } +} +close FILE +EOF + + +# Set to 0 globally, since there is no way to set this on the mysqldump client. +set @my_long_query_time = @@global.long_query_time; +set global long_query_time = 0; + +create table t1 (i int, c char(255)); + +insert into t1 values (0, lpad('a', 250, 'b')); +insert into t1 select i+1,c from t1; +insert into t1 select i+2,c from t1; +insert into t1 select i+4,c from t1; +insert into t1 select i+8,c from t1; +insert into t1 select i+16,c from t1; + +# long_query_time of 0 means using the server value. +--exec $MYSQL_DUMP mysqldump_long_query_time --long_query_time=0 > /dev/null + +--echo +--echo # Check the slow log result. One "select" query should be found. +--perl +open FILE, "$ENV{'MYSQLD_DATADIR'}/mysqldump_long_query_time-slow.log" or die; +my @lines = ; +foreach $line (@lines) { + if ($line =~ /^select/) { + print $line; + } +} +close FILE +EOF + +remove_file $MYSQLD_DATADIR/mysqldump_long_query_time-slow.log; + +drop database mysqldump_long_query_time; + +set @@global.slow_query_log_file = @my_slow_query_log_file; +set @@global.slow_query_log = @my_slow_query_log; +set @@global.long_query_time = @my_long_query_time;