Skip to content

Commit f9639c2

Browse files
committed
MDEV-22037: Add ability to skip content of some tables (work around for MDEV-20939)
--ignore-table-data parameter added.
1 parent 1f7be88 commit f9639c2

File tree

4 files changed

+92
-6
lines changed

4 files changed

+92
-6
lines changed

client/client_priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ enum options_client
9393
OPT_REPORT_PROGRESS,
9494
OPT_SKIP_ANNOTATE_ROWS_EVENTS,
9595
OPT_SSL_CRL, OPT_SSL_CRLPATH,
96+
OPT_IGNORE_DATA,
9697
OPT_MAX_CLIENT_OPTION /* should be always the last */
9798
};
9899

client/mysqldump.c

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
/* Max length GTID position that we will output. */
9191
#define MAX_GTID_LENGTH 1024
9292

93+
static my_bool ignore_table_data(const uchar *hash_key, size_t len);
9394
static void add_load_option(DYNAMIC_STRING *str, const char *option,
9495
const char *option_value);
9596
static ulong find_set(TYPELIB *, const char *, size_t, char **, uint *);
@@ -210,7 +211,7 @@ TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1,
210211

211212
#define MED_ENGINES "MRG_MyISAM, MRG_ISAM, CONNECT, OQGRAPH, SPIDER, VP, FEDERATED"
212213

213-
HASH ignore_table;
214+
HASH ignore_table, ignore_data;
214215

215216
static struct my_option my_long_options[] =
216217
{
@@ -371,6 +372,12 @@ static struct my_option my_long_options[] =
371372
&opt_hex_blob, &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
372373
{"host", 'h', "Connect to host.", &current_host,
373374
&current_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
375+
{"ignore-table-data", OPT_IGNORE_DATA,
376+
"Do not dump the specified table data. To specify more than one table "
377+
"to ignore, use the directive multiple times, once for each table. "
378+
"Each table must be specified with both database and table names, e.g., "
379+
"--ignore-table-data=database.table.",
380+
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
374381
{"ignore-table", OPT_IGNORE_TABLE,
375382
"Do not dump the specified table. To specify more than one table to ignore, "
376383
"use the directive multiple times, once for each table. Each table must "
@@ -895,6 +902,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
895902
case (int) OPT_TABLES:
896903
opt_databases=0;
897904
break;
905+
case (int) OPT_IGNORE_DATA:
906+
{
907+
if (!strchr(argument, '.'))
908+
{
909+
fprintf(stderr,
910+
"Illegal use of option --ignore-table-data=<database>.<table>\n");
911+
exit(1);
912+
}
913+
if (my_hash_insert(&ignore_data, (uchar*)my_strdup(argument, MYF(0))))
914+
exit(EX_EOM);
915+
break;
916+
}
898917
case (int) OPT_IGNORE_TABLE:
899918
{
900919
if (!strchr(argument, '.'))
@@ -993,6 +1012,10 @@ static int get_options(int *argc, char ***argv)
9931012
(uchar*) my_strdup("mysql.slow_log", MYF(MY_WME))))
9941013
return(EX_EOM);
9951014

1015+
if (my_hash_init(&ignore_data, charset_info, 16, 0, 0,
1016+
(my_hash_get_key) get_table_key, my_free, 0))
1017+
return(EX_EOM);
1018+
9961019
if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
9971020
return(ho_error);
9981021

@@ -1637,6 +1660,8 @@ static void free_resources()
16371660
free_root(&glob_root, MYF(0));
16381661
if (my_hash_inited(&ignore_table))
16391662
my_hash_free(&ignore_table);
1663+
if (my_hash_inited(&ignore_data))
1664+
my_hash_free(&ignore_data);
16401665
dynstr_free(&extended_row);
16411666
dynstr_free(&dynamic_where);
16421667
dynstr_free(&insert_pat);
@@ -3601,7 +3626,7 @@ static char *alloc_query_str(ulong size)
36013626
*/
36023627

36033628

3604-
static void dump_table(char *table, char *db)
3629+
static void dump_table(char *table, char *db, const uchar *hash_key, size_t len)
36053630
{
36063631
char ignore_flag;
36073632
char buf[200], table_buff[NAME_LEN+3];
@@ -3629,7 +3654,7 @@ static void dump_table(char *table, char *db)
36293654
DBUG_VOID_RETURN;
36303655

36313656
/* Check --no-data flag */
3632-
if (opt_no_data)
3657+
if (opt_no_data || (hash_key && ignore_table_data(hash_key, len)))
36333658
{
36343659
verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n",
36353660
table);
@@ -4557,10 +4582,14 @@ static int init_dumping(char *database, int init_func(char*))
45574582

45584583
/* Return 1 if we should copy the table */
45594584

4560-
my_bool include_table(const uchar *hash_key, size_t len)
4585+
static my_bool include_table(const uchar *hash_key, size_t len)
45614586
{
45624587
return ! my_hash_search(&ignore_table, hash_key, len);
45634588
}
4589+
static my_bool ignore_table_data(const uchar *hash_key, size_t len)
4590+
{
4591+
return my_hash_search(&ignore_data, hash_key, len) != NULL;
4592+
}
45644593

45654594

45664595
static int dump_all_tables_in_db(char *database)
@@ -4625,7 +4654,7 @@ static int dump_all_tables_in_db(char *database)
46254654
char *end= strmov(afterdot, table);
46264655
if (include_table((uchar*) hash_key, end - hash_key))
46274656
{
4628-
dump_table(table,database);
4657+
dump_table(table, database, (uchar*) hash_key, end - hash_key);
46294658
my_free(order_by);
46304659
order_by= 0;
46314660
if (opt_dump_triggers && mysql_get_server_version(mysql) >= 50009)
@@ -5014,7 +5043,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
50145043
for (pos= dump_tables; pos < end; pos++)
50155044
{
50165045
DBUG_PRINT("info",("Dumping table %s", *pos));
5017-
dump_table(*pos, db);
5046+
dump_table(*pos, db, NULL, 0);
50185047
if (opt_dump_triggers &&
50195048
mysql_get_server_version(mysql) >= 50009)
50205049
{
@@ -5995,6 +6024,7 @@ int main(int argc, char **argv)
59956024
compatible_mode_normal_str[0]= 0;
59966025
default_charset= (char *)mysql_universal_client_charset;
59976026
bzero((char*) &ignore_table, sizeof(ignore_table));
6027+
bzero((char*) &ignore_data, sizeof(ignore_data));
59986028

59996029
exit_code= get_options(&argc, &argv);
60006030
if (exit_code)

mysql-test/r/mysqldump.result

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5628,3 +5628,22 @@ select count(*) from t2;
56285628
count(*)
56295629
2
56305630
drop tables t2, t1;
5631+
#
5632+
# MDEV-22037: Add ability to skip content of some tables
5633+
# (work around for MDEV-20939)
5634+
#
5635+
use mysql;
5636+
# check that all tables we need are not empty
5637+
select count(*) >= 1 from mysql.proc;
5638+
count(*) >= 1
5639+
1
5640+
select count(*) >= 1 from mysql.db;
5641+
count(*) >= 1
5642+
1
5643+
# for proc we have CREATE and INSERT for all other only CREATE
5644+
FOUND /INSERT INTO `proc`/ in MDEV-20939.sql
5645+
NOT FOUND /INSERT INTO `db`/ in MDEV-20939.sql
5646+
FOUND /CREATE TABLE `db`/ in MDEV-20939.sql
5647+
FOUND /CREATE TABLE `proc`/ in MDEV-20939.sql
5648+
use test;
5649+
# End of 10.1 tests

mysql-test/t/mysqldump.test

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2678,3 +2678,39 @@ select count(*) from t2;
26782678

26792679
--remove_file $MYSQLTEST_VARDIR/tmp/t2.txt
26802680
drop tables t2, t1;
2681+
2682+
2683+
--echo #
2684+
--echo # MDEV-22037: Add ability to skip content of some tables
2685+
--echo # (work around for MDEV-20939)
2686+
--echo #
2687+
2688+
use mysql;
2689+
2690+
--echo # check that all tables we need are not empty
2691+
2692+
select count(*) >= 1 from mysql.proc;
2693+
select count(*) >= 1 from mysql.db;
2694+
2695+
2696+
--exec $MYSQL_DUMP mysql --ignore-table-data=mysql.db >$MYSQLTEST_VARDIR/tmp/MDEV-20939.sql
2697+
2698+
2699+
--echo # for proc we have CREATE and INSERT for all other only CREATE
2700+
2701+
let SEARCH_RANGE=500000000;
2702+
let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/MDEV-20939.sql;
2703+
let SEARCH_PATTERN=INSERT INTO `proc`;
2704+
source include/search_pattern_in_file.inc;
2705+
let SEARCH_PATTERN=INSERT INTO `db`;
2706+
source include/search_pattern_in_file.inc;
2707+
let SEARCH_PATTERN=CREATE TABLE `db`;
2708+
source include/search_pattern_in_file.inc;
2709+
let SEARCH_PATTERN=CREATE TABLE `proc`;
2710+
source include/search_pattern_in_file.inc;
2711+
2712+
--remove_file $MYSQLTEST_VARDIR/tmp/MDEV-20939.sql
2713+
use test;
2714+
2715+
2716+
--echo # End of 10.1 tests

0 commit comments

Comments
 (0)