|
1 | 1 | /* |
2 | 2 | Copyright (c) 2000, 2013, Oracle and/or its affiliates. |
3 | | - Copyright (c) 2010, 2019, MariaDB Corporation. |
| 3 | + Copyright (c) 2010, 2020, MariaDB Corporation. |
4 | 4 |
|
5 | 5 | This program is free software; you can redistribute it and/or modify |
6 | 6 | it under the terms of the GNU General Public License as published by |
|
90 | 90 | /* Max length GTID position that we will output. */ |
91 | 91 | #define MAX_GTID_LENGTH 1024 |
92 | 92 |
|
| 93 | +static my_bool ignore_table_data(const uchar *hash_key, size_t len); |
93 | 94 | static void add_load_option(DYNAMIC_STRING *str, const char *option, |
94 | 95 | const char *option_value); |
95 | 96 | static ulong find_set(TYPELIB *, const char *, size_t, char **, uint *); |
@@ -212,7 +213,7 @@ TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1, |
212 | 213 |
|
213 | 214 | #define MED_ENGINES "MRG_MyISAM, MRG_ISAM, CONNECT, OQGRAPH, SPIDER, VP, FEDERATED" |
214 | 215 |
|
215 | | -static HASH ignore_table; |
| 216 | +static HASH ignore_table, ignore_data; |
216 | 217 |
|
217 | 218 | static HASH ignore_database; |
218 | 219 |
|
@@ -383,6 +384,12 @@ static struct my_option my_long_options[] = |
383 | 384 | "use the directive multiple times, once for each database. Only takes effect " |
384 | 385 | "when used together with --all-databases|-A", |
385 | 386 | 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, |
| 387 | + {"ignore-table-data", OPT_IGNORE_DATA, |
| 388 | + "Do not dump the specified table data. To specify more than one table " |
| 389 | + "to ignore, use the directive multiple times, once for each table. " |
| 390 | + "Each table must be specified with both database and table names, e.g., " |
| 391 | + "--ignore-table-data=database.table.", |
| 392 | + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, |
386 | 393 | {"ignore-table", OPT_IGNORE_TABLE, |
387 | 394 | "Do not dump the specified table. To specify more than one table to ignore, " |
388 | 395 | "use the directive multiple times, once for each table. Each table must " |
@@ -911,6 +918,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), |
911 | 918 | if (my_hash_insert(&ignore_database, (uchar*) my_strdup(argument, MYF(0)))) |
912 | 919 | exit(EX_EOM); |
913 | 920 | break; |
| 921 | + case (int) OPT_IGNORE_DATA: |
| 922 | + { |
| 923 | + if (!strchr(argument, '.')) |
| 924 | + { |
| 925 | + fprintf(stderr, |
| 926 | + "Illegal use of option --ignore-table-data=<database>.<table>\n"); |
| 927 | + exit(1); |
| 928 | + } |
| 929 | + if (my_hash_insert(&ignore_data, (uchar*)my_strdup(argument, MYF(0)))) |
| 930 | + exit(EX_EOM); |
| 931 | + break; |
| 932 | + } |
914 | 933 | case (int) OPT_IGNORE_TABLE: |
915 | 934 | { |
916 | 935 | if (!strchr(argument, '.')) |
@@ -1018,6 +1037,10 @@ static int get_options(int *argc, char ***argv) |
1018 | 1037 | (uchar*) my_strdup("mysql.transaction_registry", MYF(MY_WME)))) |
1019 | 1038 | return(EX_EOM); |
1020 | 1039 |
|
| 1040 | + if (my_hash_init(&ignore_data, charset_info, 16, 0, 0, |
| 1041 | + (my_hash_get_key) get_table_key, my_free, 0)) |
| 1042 | + return(EX_EOM); |
| 1043 | + |
1021 | 1044 | if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option))) |
1022 | 1045 | return(ho_error); |
1023 | 1046 |
|
@@ -1674,6 +1697,8 @@ static void free_resources() |
1674 | 1697 | my_hash_free(&ignore_database); |
1675 | 1698 | if (my_hash_inited(&ignore_table)) |
1676 | 1699 | my_hash_free(&ignore_table); |
| 1700 | + if (my_hash_inited(&ignore_data)) |
| 1701 | + my_hash_free(&ignore_data); |
1677 | 1702 | dynstr_free(&extended_row); |
1678 | 1703 | dynstr_free(&dynamic_where); |
1679 | 1704 | dynstr_free(&insert_pat); |
@@ -3678,7 +3703,7 @@ static char *alloc_query_str(size_t size) |
3678 | 3703 | */ |
3679 | 3704 |
|
3680 | 3705 |
|
3681 | | -static void dump_table(char *table, char *db) |
| 3706 | +static void dump_table(char *table, char *db, const uchar *hash_key, size_t len) |
3682 | 3707 | { |
3683 | 3708 | char ignore_flag; |
3684 | 3709 | char buf[200], table_buff[NAME_LEN+3]; |
@@ -3708,7 +3733,7 @@ static void dump_table(char *table, char *db) |
3708 | 3733 | DBUG_VOID_RETURN; |
3709 | 3734 |
|
3710 | 3735 | /* Check --no-data flag */ |
3711 | | - if (opt_no_data) |
| 3736 | + if (opt_no_data || (hash_key && ignore_table_data(hash_key, len))) |
3712 | 3737 | { |
3713 | 3738 | verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n", |
3714 | 3739 | table); |
@@ -4653,10 +4678,14 @@ static int init_dumping(char *database, int init_func(char*)) |
4653 | 4678 |
|
4654 | 4679 | /* Return 1 if we should copy the table */ |
4655 | 4680 |
|
4656 | | -my_bool include_table(const uchar *hash_key, size_t len) |
| 4681 | +static my_bool include_table(const uchar *hash_key, size_t len) |
4657 | 4682 | { |
4658 | 4683 | return ! my_hash_search(&ignore_table, hash_key, len); |
4659 | 4684 | } |
| 4685 | +static my_bool ignore_table_data(const uchar *hash_key, size_t len) |
| 4686 | +{ |
| 4687 | + return my_hash_search(&ignore_data, hash_key, len) != NULL; |
| 4688 | +} |
4660 | 4689 |
|
4661 | 4690 |
|
4662 | 4691 | static int dump_all_tables_in_db(char *database) |
@@ -4722,7 +4751,7 @@ static int dump_all_tables_in_db(char *database) |
4722 | 4751 | char *end= strmov(afterdot, table); |
4723 | 4752 | if (include_table((uchar*) hash_key, end - hash_key)) |
4724 | 4753 | { |
4725 | | - dump_table(table,database); |
| 4754 | + dump_table(table, database, (uchar*) hash_key, end - hash_key); |
4726 | 4755 | my_free(order_by); |
4727 | 4756 | order_by= 0; |
4728 | 4757 | if (opt_dump_triggers && mysql_get_server_version(mysql) >= 50009) |
@@ -5120,7 +5149,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) |
5120 | 5149 | for (pos= dump_tables; pos < end; pos++) |
5121 | 5150 | { |
5122 | 5151 | DBUG_PRINT("info",("Dumping table %s", *pos)); |
5123 | | - dump_table(*pos, db); |
| 5152 | + dump_table(*pos, db, NULL, 0); |
5124 | 5153 | if (opt_dump_triggers && |
5125 | 5154 | mysql_get_server_version(mysql) >= 50009) |
5126 | 5155 | { |
|
0 commit comments