Skip to content

Commit 3b9423f

Browse files
grooverdancvicentiu
authored andcommitted
MDEV-7384: Add --persistent option for mysqlcheck
10.0 has an "analyze table .. persistent for all" syntax. This adds --persistent to mysqlcheck(mysqlanalyize) to perform this extended analyze table option. Signed-off-by: Vicențiu Ciorbaru <vicentiu@mariadb.org>
1 parent 5efb8f1 commit 3b9423f

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

client/mysqlcheck.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
4343
opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
4444
tty_password= 0, opt_frm= 0, debug_info_flag= 0, debug_check_flag= 0,
4545
opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0,
46-
opt_do_tables= 1;
46+
opt_persistent_all= 0, opt_do_tables= 1;
4747
static my_bool opt_write_binlog= 1, opt_flush_tables= 0;
4848
static uint verbose = 0, opt_mysql_port=0;
4949
static int my_end_arg;
@@ -160,6 +160,10 @@ static struct my_option my_long_options[] =
160160
{"password", 'p',
161161
"Password to use when connecting to server. If password is not given, it's solicited on the tty.",
162162
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
163+
{"persistent", 'Z',
164+
"When using ANALYZE TABLE use the PERSISTENT FOR ALL option.",
165+
&opt_persistent_all, &opt_persistent_all, 0, GET_BOOL, NO_ARG,
166+
0, 0, 0, 0, 0, 0},
163167
#ifdef __WIN__
164168
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
165169
NO_ARG, 0, 0, 0, 0, 0, 0},
@@ -909,6 +913,7 @@ static int handle_request_for_tables(char *tables, size_t length, my_bool view)
909913
case DO_ANALYZE:
910914
DBUG_ASSERT(!view);
911915
op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
916+
if (opt_persistent_all) end = strmov(end, " PERSISTENT FOR ALL");
912917
break;
913918
case DO_OPTIMIZE:
914919
DBUG_ASSERT(!view);

man/mysqlcheck.1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'\" t
22
.\"
3-
.TH "\FBMYSQLCHECK\FR" "1" "04/08/2015" "MariaDB 10\&.0" "MariaDB Database System"
3+
.TH "\FBMYSQLCHECK\FR" "1" "27/12/2015" "MariaDB 10\&.0" "MariaDB Database System"
44
.\" -----------------------------------------------------------------
55
.\" * set default formatting
66
.\" -----------------------------------------------------------------
@@ -677,6 +677,22 @@ Specifying a password on the command line should be considered insecure\&. You c
677677
.sp -1
678678
.IP \(bu 2.3
679679
.\}
680+
.\" mysqlcheck: persisent option
681+
.\" persistent option: mysql
682+
\fB\-\-persistent\fR,
683+
\fB\-Z\fR
684+
.sp
685+
Used with ANALYZE TABLE to append the option PERSISENT FOR ALL.
686+
.RE
687+
.sp
688+
.RS 4
689+
.ie n \{\
690+
\h'-04'\(bu\h'+03'\c
691+
.\}
692+
.el \{\
693+
.sp -1
694+
.IP \(bu 2.3
695+
.\}
680696
.\" mysqlcheck: pipe option
681697
.\" pipe option: mysql
682698
\fB\-\-pipe\fR,

mysql-test/r/mysqlcheck.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ CREATE TABLE test.`t.1` (id int);
347347
mysqlcheck test t.1
348348
test.t.1 OK
349349
drop table test.`t.1`;
350+
#
351+
# MDEV-8123 mysqlcheck: new --process-views option conflicts with --quick, --extended and such
352+
#
350353
create view v1 as select 1;
351354
mysqlcheck --process-views test
352355
test.v1 OK
@@ -361,6 +364,9 @@ test.v1 OK
361364
mysqlcheck --process-views --check-upgrade test
362365
test.v1 OK
363366
drop view v1;
367+
#
368+
# MDEV-8124 mysqlcheck: --auto-repair runs REPAIR TABLE instead of REPAIR VIEW on views
369+
#
364370
create table t1(a int);
365371
mysqlcheck --process-views --check-upgrade --auto-repair test
366372
test.t1 OK
@@ -370,3 +376,16 @@ Repairing views
370376
test.v1 OK
371377
drop view v1;
372378
drop table t1;
379+
#
380+
#MDEV-7384 [PATCH] add PERSISENT FOR ALL option to mysqlanalyze/mysqlcheck
381+
#
382+
create table t1(a int);
383+
insert into t1 (a) values (1), (2), (3);
384+
select * from mysql.column_stats;
385+
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
386+
test.t1 Engine-independent statistics collected
387+
status : OK
388+
select * from mysql.column_stats where db_name = 'test' and table_name = 't1';
389+
db_name table_name column_name min_value max_value nulls_ratio avg_length avg_frequency hist_size hist_type histogram
390+
test t1 a 1 3 0.0000 4.0000 1.0000 0 NULL NULL
391+
drop table t1;

mysql-test/t/mysqlcheck.test

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ CREATE TABLE test.`t.1` (id int);
319319

320320
drop table test.`t.1`;
321321

322-
#
323-
# MDEV-8123 mysqlcheck: new --process-views option conflicts with --quick, --extended and such
324-
#
322+
--echo #
323+
--echo # MDEV-8123 mysqlcheck: new --process-views option conflicts with --quick, --extended and such
324+
--echo #
325325
create view v1 as select 1;
326326
--echo mysqlcheck --process-views test
327327
--exec $MYSQL_CHECK --process-views test
@@ -340,12 +340,22 @@ create view v1 as select 1;
340340
drop view v1;
341341

342342

343-
#
344-
# MDEV-8124 mysqlcheck: --auto-repair runs REPAIR TABLE instead of REPAIR VIEW on views
345-
#
343+
--echo #
344+
--echo # MDEV-8124 mysqlcheck: --auto-repair runs REPAIR TABLE instead of REPAIR VIEW on views
345+
--echo #
346346
create table t1(a int);
347347
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm
348348
--echo mysqlcheck --process-views --check-upgrade --auto-repair test
349349
--exec $MYSQL_CHECK --process-views --check-upgrade --auto-repair test
350350
drop view v1;
351351
drop table t1;
352+
353+
--echo #
354+
--echo #MDEV-7384 [PATCH] add PERSISENT FOR ALL option to mysqlanalyze/mysqlcheck
355+
--echo #
356+
create table t1(a int);
357+
insert into t1 (a) values (1), (2), (3);
358+
select * from mysql.column_stats;
359+
--exec $MYSQL_CHECK --analyze test t1 --persistent
360+
select * from mysql.column_stats where db_name = 'test' and table_name = 't1';
361+
drop table t1;

0 commit comments

Comments
 (0)