diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2020-04-01 09:19:37 +0300 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2020-04-01 09:19:37 +0300 |
commit | bc862c4ebeb9d706465d580ed58c235704579c05 (patch) | |
tree | 71a88ec195e4408ecb254040fd365afe820e9086 | |
parent | b1742a5c951633213d756600ee73ba7bfa7800ff (diff) | |
parent | f9639c2d1a5e24f1a1533b6277fe7eca3aa3c3c0 (diff) | |
download | mariadb-git-bc862c4ebeb9d706465d580ed58c235704579c05.tar.gz |
Merge 10.1 into 10.2
-rw-r--r-- | client/client_priv.h | 1 | ||||
-rw-r--r-- | client/mysqldump.c | 42 | ||||
-rw-r--r-- | client/mysqltest.cc | 68 | ||||
-rw-r--r-- | mysql-test/r/mysqldump.result | 21 | ||||
-rw-r--r-- | mysql-test/suite/innodb/r/foreign_key.result | 7 | ||||
-rw-r--r-- | mysql-test/suite/innodb/t/foreign_key.test | 11 | ||||
-rw-r--r-- | mysql-test/t/mysqldump.test | 39 | ||||
-rw-r--r-- | storage/innobase/dict/dict0mem.cc | 7 | ||||
-rw-r--r-- | storage/xtradb/dict/dict0mem.cc | 7 |
9 files changed, 121 insertions, 82 deletions
diff --git a/client/client_priv.h b/client/client_priv.h index 7c16ca17aab..5f2d62024a3 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -98,6 +98,7 @@ enum options_client OPT_REPORT_PROGRESS, OPT_SKIP_ANNOTATE_ROWS_EVENTS, OPT_SSL_CRL, OPT_SSL_CRLPATH, + OPT_IGNORE_DATA, OPT_MAX_CLIENT_OPTION /* should be always the last */ }; diff --git a/client/mysqldump.c b/client/mysqldump.c index f0c53052a1f..bec7fc07b57 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -90,6 +90,7 @@ /* Max length GTID position that we will output. */ #define MAX_GTID_LENGTH 1024 +static my_bool ignore_table_data(const uchar *hash_key, size_t len); static void add_load_option(DYNAMIC_STRING *str, const char *option, const char *option_value); static ulong find_set(TYPELIB *, const char *, size_t, char **, uint *); @@ -211,7 +212,7 @@ TYPELIB compatible_mode_typelib= {array_elements(compatible_mode_names) - 1, #define MED_ENGINES "MRG_MyISAM, MRG_ISAM, CONNECT, OQGRAPH, SPIDER, VP, FEDERATED" -HASH ignore_table; +HASH ignore_table, ignore_data; static struct my_option my_long_options[] = { @@ -375,6 +376,12 @@ static struct my_option my_long_options[] = &opt_hex_blob, &opt_hex_blob, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"host", 'h', "Connect to host.", ¤t_host, ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"ignore-table-data", OPT_IGNORE_DATA, + "Do not dump the specified table data. To specify more than one table " + "to ignore, use the directive multiple times, once for each table. " + "Each table must be specified with both database and table names, e.g., " + "--ignore-table-data=database.table.", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"ignore-table", OPT_IGNORE_TABLE, "Do not dump the specified table. To specify more than one table to ignore, " "use the directive multiple times, once for each table. Each table must " @@ -899,6 +906,18 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case (int) OPT_TABLES: opt_databases=0; break; + case (int) OPT_IGNORE_DATA: + { + if (!strchr(argument, '.')) + { + fprintf(stderr, + "Illegal use of option --ignore-table-data=<database>.<table>\n"); + exit(1); + } + if (my_hash_insert(&ignore_data, (uchar*)my_strdup(argument, MYF(0)))) + exit(EX_EOM); + break; + } case (int) OPT_IGNORE_TABLE: { if (!strchr(argument, '.')) @@ -1001,6 +1020,10 @@ static int get_options(int *argc, char ***argv) (uchar*) my_strdup("mysql.slow_log", MYF(MY_WME)))) return(EX_EOM); + if (my_hash_init(&ignore_data, charset_info, 16, 0, 0, + (my_hash_get_key) get_table_key, my_free, 0)) + return(EX_EOM); + if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option))) return(ho_error); @@ -1648,6 +1671,8 @@ static void free_resources() free_root(&glob_root, MYF(0)); if (my_hash_inited(&ignore_table)) my_hash_free(&ignore_table); + if (my_hash_inited(&ignore_data)) + my_hash_free(&ignore_data); dynstr_free(&extended_row); dynstr_free(&dynamic_where); dynstr_free(&insert_pat); @@ -3622,7 +3647,7 @@ static char *alloc_query_str(ulong size) */ -static void dump_table(char *table, char *db) +static void dump_table(char *table, char *db, const uchar *hash_key, size_t len) { char ignore_flag; char buf[200], table_buff[NAME_LEN+3]; @@ -3650,7 +3675,7 @@ static void dump_table(char *table, char *db) DBUG_VOID_RETURN; /* Check --no-data flag */ - if (opt_no_data) + if (opt_no_data || (hash_key && ignore_table_data(hash_key, len))) { verbose_msg("-- Skipping dump data for table '%s', --no-data was used\n", table); @@ -4578,10 +4603,14 @@ static int init_dumping(char *database, int init_func(char*)) /* Return 1 if we should copy the table */ -my_bool include_table(const uchar *hash_key, size_t len) +static my_bool include_table(const uchar *hash_key, size_t len) { return ! my_hash_search(&ignore_table, hash_key, len); } +static my_bool ignore_table_data(const uchar *hash_key, size_t len) +{ + return my_hash_search(&ignore_data, hash_key, len) != NULL; +} static int dump_all_tables_in_db(char *database) @@ -4646,7 +4675,7 @@ static int dump_all_tables_in_db(char *database) char *end= strmov(afterdot, table); if (include_table((uchar*) hash_key, end - hash_key)) { - dump_table(table,database); + dump_table(table, database, (uchar*) hash_key, end - hash_key); my_free(order_by); order_by= 0; if (opt_dump_triggers && mysql_get_server_version(mysql) >= 50009) @@ -5035,7 +5064,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) for (pos= dump_tables; pos < end; pos++) { DBUG_PRINT("info",("Dumping table %s", *pos)); - dump_table(*pos, db); + dump_table(*pos, db, NULL, 0); if (opt_dump_triggers && mysql_get_server_version(mysql) >= 50009) { @@ -6016,6 +6045,7 @@ int main(int argc, char **argv) compatible_mode_normal_str[0]= 0; default_charset= (char *)mysql_universal_client_charset; bzero((char*) &ignore_table, sizeof(ignore_table)); + bzero((char*) &ignore_data, sizeof(ignore_data)); exit_code= get_options(&argc, &argv); if (exit_code) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 60a203ccedd..1517771e743 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -1155,71 +1155,6 @@ void do_eval(DYNAMIC_STRING *query_eval, const char *query, /* - Run query and dump the result to stderr in vertical format - - NOTE! This function should be safe to call when an error - has occurred and thus any further errors will be ignored (although logged) - - SYNOPSIS - show_query - mysql - connection to use - query - query to run - -*/ - -static void show_query(MYSQL* mysql, const char* query) -{ - MYSQL_RES* res; - DBUG_ENTER("show_query"); - - if (!mysql) - DBUG_VOID_RETURN; - - if (mysql_query(mysql, query)) - { - log_msg("Error running query '%s': %d %s", - query, mysql_errno(mysql), mysql_error(mysql)); - DBUG_VOID_RETURN; - } - - if ((res= mysql_store_result(mysql)) == NULL) - { - /* No result set returned */ - DBUG_VOID_RETURN; - } - - { - MYSQL_ROW row; - unsigned int i; - unsigned int row_num= 0; - unsigned int num_fields= mysql_num_fields(res); - MYSQL_FIELD *fields= mysql_fetch_fields(res); - - fprintf(stderr, "=== %s ===\n", query); - while ((row= mysql_fetch_row(res))) - { - unsigned long *lengths= mysql_fetch_lengths(res); - row_num++; - - fprintf(stderr, "---- %d. ----\n", row_num); - for(i= 0; i < num_fields; i++) - { - fprintf(stderr, "%s\t%.*s\n", - fields[i].name, - (int)lengths[i], row[i] ? row[i] : "NULL"); - } - } - for (i= 0; i < strlen(query)+8; i++) - fprintf(stderr, "="); - fprintf(stderr, "\n\n"); - } - mysql_free_result(res); - - DBUG_VOID_RETURN; -} - - -/* Show any warnings just before the error. Since the last error is added to the warning stack, only print @@warning_count-1 warnings. @@ -4808,9 +4743,6 @@ void do_sync_with_master2(struct st_command *command, long offset, if (!result_str || result < 0) { /* master_pos_wait returned NULL or < 0 */ - show_query(mysql, "SHOW MASTER STATUS"); - show_query(mysql, "SHOW SLAVE STATUS"); - show_query(mysql, "SHOW PROCESSLIST"); fprintf(stderr, "analyze: sync_with_master\n"); if (!result_str) diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index e83edb8c121..e527dbffe43 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -5647,9 +5647,27 @@ count(*) 2 drop tables t2, t1; # -# Test for --add-drop-trigger +# MDEV-22037: Add ability to skip content of some tables +# (work around for MDEV-20939) # +use mysql; +# check that all tables we need are not empty +select count(*) >= 1 from mysql.proc; +count(*) >= 1 +1 +select count(*) >= 1 from mysql.db; +count(*) >= 1 +1 +# for proc we have CREATE and INSERT for all other only CREATE +FOUND 1 /INSERT INTO `proc`/ in MDEV-20939.sql +NOT FOUND /INSERT INTO `db`/ in MDEV-20939.sql +FOUND 1 /CREATE TABLE `db`/ in MDEV-20939.sql +FOUND 1 /CREATE TABLE `proc`/ in MDEV-20939.sql use test; +# End of 10.1 tests +# +# Test for --add-drop-trigger +# CREATE TABLE t1 (a int, b int); CREATE TRIGGER tt1_t1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.b=NEW.a + 10; @@ -5695,3 +5713,4 @@ DELIMITER ; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; DROP TABLE t1; +# End of 10.2 tests diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index 5eb0658bf48..749aa5943d3 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -274,6 +274,13 @@ CREATE TABLE t2 (f INT, KEY(f)) ENGINE=InnoDB; ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t2 (f); ALTER IGNORE TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f1); DROP TABLE t1, t2; +CREATE TABLE t1 (a INT, b INT, KEY idx(a)) ENGINE=InnoDB; +SET FOREIGN_KEY_CHECKS= OFF; +ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES tx(x); +ALTER TABLE t1 DROP KEY idx; +ALTER TABLE t1 CHANGE a c INT; +DROP TABLE t1; +SET FOREIGN_KEY_CHECKS=1; # Start of 10.2 tests # # MDEV-13246 Stale rows despite ON DELETE CASCADE constraint diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index 06cab983656..b5a84756914 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -257,6 +257,17 @@ ALTER TABLE t1 ADD FOREIGN KEY (f2) REFERENCES t2 (f); ALTER IGNORE TABLE t1 ADD FOREIGN KEY (f3) REFERENCES t1 (f1); DROP TABLE t1, t2; +# MDEV-19092 Server crash when renaming the column when +# FOREIGN_KEY_CHECKS is disabled +CREATE TABLE t1 (a INT, b INT, KEY idx(a)) ENGINE=InnoDB; +SET FOREIGN_KEY_CHECKS= OFF; +ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES tx(x); +ALTER TABLE t1 DROP KEY idx; +ALTER TABLE t1 CHANGE a c INT; +# Cleanup +DROP TABLE t1; +SET FOREIGN_KEY_CHECKS=1; + --echo # Start of 10.2 tests --echo # diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test index 34976350c78..4478406b395 100644 --- a/mysql-test/t/mysqldump.test +++ b/mysql-test/t/mysqldump.test @@ -2688,10 +2688,45 @@ select count(*) from t2; --remove_file $MYSQLTEST_VARDIR/tmp/t2.txt drop tables t2, t1; + --echo # ---echo # Test for --add-drop-trigger +--echo # MDEV-22037: Add ability to skip content of some tables +--echo # (work around for MDEV-20939) --echo # + +use mysql; + +--echo # check that all tables we need are not empty + +select count(*) >= 1 from mysql.proc; +select count(*) >= 1 from mysql.db; + + +--exec $MYSQL_DUMP mysql --ignore-table-data=mysql.db >$MYSQLTEST_VARDIR/tmp/MDEV-20939.sql + + +--echo # for proc we have CREATE and INSERT for all other only CREATE + +let SEARCH_RANGE=500000000; +let SEARCH_FILE=$MYSQLTEST_VARDIR/tmp/MDEV-20939.sql; +let SEARCH_PATTERN=INSERT INTO `proc`; +source include/search_pattern_in_file.inc; +let SEARCH_PATTERN=INSERT INTO `db`; +source include/search_pattern_in_file.inc; +let SEARCH_PATTERN=CREATE TABLE `db`; +source include/search_pattern_in_file.inc; +let SEARCH_PATTERN=CREATE TABLE `proc`; +source include/search_pattern_in_file.inc; + +--remove_file $MYSQLTEST_VARDIR/tmp/MDEV-20939.sql use test; + +--echo # End of 10.1 tests + +--echo # +--echo # Test for --add-drop-trigger +--echo # + CREATE TABLE t1 (a int, b int); CREATE TRIGGER tt1_t1 BEFORE INSERT ON t1 FOR EACH ROW SET NEW.b=NEW.a + 10; @@ -2699,3 +2734,5 @@ CREATE TRIGGER tt1_t1 BEFORE INSERT ON t1 FOR EACH ROW INSERT INTO t1 (a) VALUES (1),(2),(3); --exec $MYSQL_DUMP --default-character-set=utf8mb4 --triggers --no-data --no-create-info --add-drop-trigger --skip-comments --databases test DROP TABLE t1; + +--echo # End of 10.2 tests diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index fe01948b70d..9190272a4c5 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -2,7 +2,7 @@ Copyright (c) 1996, 2018, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, Facebook Inc. -Copyright (c) 2013, 2019, MariaDB Corporation. +Copyright (c) 2013, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -564,9 +564,10 @@ dict_mem_table_col_rename_low( foreign->foreign_col_names, foreign->n_fields, NULL, true, false, NULL, NULL, NULL); - /* There must be an equivalent index in this case. */ - ut_ad(new_index != NULL); + /* New index can be null if InnoDB already dropped + the foreign index when FOREIGN_KEY_CHECKS is + disabled */ foreign->foreign_index = new_index; } else { diff --git a/storage/xtradb/dict/dict0mem.cc b/storage/xtradb/dict/dict0mem.cc index f4bbc5c8f06..51ca6de8cd2 100644 --- a/storage/xtradb/dict/dict0mem.cc +++ b/storage/xtradb/dict/dict0mem.cc @@ -2,7 +2,7 @@ Copyright (c) 1996, 2017, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2012, Facebook Inc. -Copyright (c) 2013, 2019, MariaDB Corporation. +Copyright (c) 2013, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -421,9 +421,10 @@ dict_mem_table_col_rename_low( foreign->foreign_col_names, foreign->n_fields, NULL, true, false, NULL, NULL, NULL); - /* There must be an equivalent index in this case. */ - ut_ad(new_index != NULL); + /* New index can be null if XtraDB already dropped + the foreign index when FOREIGN_KEY_CHECKS is + disabled */ foreign->foreign_index = new_index; } else { |