diff --git a/client/mysqldump.c b/client/mysqldump.c index f1e1d549f6a..21d9d78c6de 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -99,7 +99,7 @@ static my_bool verbose= 0, opt_no_create_info= 0, opt_no_data= 0, opt_replace_into= 0, opt_dump_triggers= 0, opt_routines=0, opt_tz_utc=1, opt_events= 0, - opt_alltspcs=0; + opt_alltspcs=0, opt_notspcs= 0; static ulong opt_max_allowed_packet, opt_net_buffer_length; static MYSQL mysql_connection,*mysql=0; static my_bool insert_pat_inited=0; @@ -170,6 +170,10 @@ static struct my_option my_long_options[] = "Dump all the tablespaces.", (gptr*) &opt_alltspcs, (gptr*) &opt_alltspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"no-tablespaces", 'y', + "Do not dump any tablespace information.", + (gptr*) &opt_notspcs, (gptr*) &opt_notspcs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, + 0, 0}, {"add-drop-database", OPT_DROP_DATABASE, "Add a 'DROP DATABASE' before each create.", (gptr*) &opt_drop_database, (gptr*) &opt_drop_database, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, @@ -446,6 +450,10 @@ char check_if_ignore_table(const char *table_name, char *table_type); static char *primary_key_fields(const char *table_name); static my_bool get_view_structure(char *table, char* db); static my_bool dump_all_views_in_db(char *database); +static int dump_all_tablespaces(); +static int dump_tablespaces_for_tables(char *db, char **table_names, int tables); +static int dump_tablespaces_for_databases(char** databases); +static int dump_tablespaces(char* ts_where); #include @@ -2745,10 +2753,101 @@ static char *getTableName(int reset) */ static int dump_all_tablespaces() +{ + return dump_tablespaces(NULL); +} + +static int dump_tablespaces_for_tables(char *db, char **table_names, int tables) +{ + char *where; + int r; + int i; + + size_t sz= 200+tables*(NAME_LEN*2+3); + where= my_malloc(sz, MYF(MY_WME)); + + if (!where) + return 1; + + char name_buff[NAME_LEN*2+3]; + mysql_real_escape_string(mysql, name_buff, db, strlen(db)); + + snprintf(where,sz-1, + " AND TABLESPACE_NAME IN (" + "SELECT DISTINCT TABLESPACE_NAME FROM" + " INFORMATION_SCHEMA.PARTITIONS" + " WHERE" + " TABLE_SCHEMA='%s'" + " AND TABLE_NAME IN (", name_buff); + + for (i=0 ; i 1 && !opt_databases) { /* Only one database and selected table(s) */ + if (!opt_alltspcs && !opt_notspcs) + dump_tablespaces_for_tables(*argv, (argv + 1), (argc -1)); dump_selected_tables(*argv, (argv + 1), (argc - 1)); } else { /* One or more databases, all tables */ + if (!opt_alltspcs && !opt_notspcs) + dump_tablespaces_for_databases(argv); dump_databases(argv); } #ifdef HAVE_SMEM diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 5fce82d781a..8f3c8236424 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -3889,6 +3889,7 @@ static void collect_partition_expr(List &field_list, String *str) static void store_schema_partitions_record(THD *thd, TABLE *table, + TABLE *show_table, partition_element *part_elem, handler *file, uint part_id) { @@ -3942,11 +3943,21 @@ static void store_schema_partitions_record(THD *thd, TABLE *table, table->field[23]->store((longlong) part_elem->nodegroup_id, TRUE); else table->field[23]->store(STRING_WITH_LEN("default"), cs); + + table->field[24]->set_notnull(); if (part_elem->tablespace_name) table->field[24]->store(part_elem->tablespace_name, strlen(part_elem->tablespace_name), cs); else - table->field[24]->store(STRING_WITH_LEN("default"), cs); + { + DBUG_PRINT("info",("FOO")); + char *ts= show_table->file->get_tablespace_name(thd); + if(ts) + table->field[24]->store(ts, strlen(ts), cs); + else + table->field[24]->set_null(); + my_free(ts, MYF(0)); + } } return; } @@ -4129,7 +4140,7 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables, table->field[6]->store((longlong) ++subpart_pos, TRUE); table->field[6]->set_notnull(); - store_schema_partitions_record(thd, table, subpart_elem, + store_schema_partitions_record(thd, table, show_table, subpart_elem, file, part_id); part_id++; if(schema_table_store_record(thd, table)) @@ -4138,7 +4149,7 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables, } else { - store_schema_partitions_record(thd, table, part_elem, + store_schema_partitions_record(thd, table, show_table, part_elem, file, part_id); part_id++; if(schema_table_store_record(thd, table)) @@ -4150,7 +4161,7 @@ static int get_schema_partitions_record(THD *thd, struct st_table_list *tables, else #endif { - store_schema_partitions_record(thd, table, 0, file, 0); + store_schema_partitions_record(thd, table, show_table, 0, file, 0); if(schema_table_store_record(thd, table)) DBUG_RETURN(1); } @@ -5334,7 +5345,7 @@ ST_FIELD_INFO partitions_fields_info[]= {"CHECKSUM", 21 , MYSQL_TYPE_LONG, 0, 1, 0}, {"PARTITION_COMMENT", 80, MYSQL_TYPE_STRING, 0, 0, 0}, {"NODEGROUP", 12 , MYSQL_TYPE_STRING, 0, 0, 0}, - {"TABLESPACE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, + {"TABLESPACE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 1, 0}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0} };