MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:Stewart Smith Date:October 9 2006 2:03pm
Subject:bk commit into 5.1 tree (stewart:1.2305) BUG#20839
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of stewart. When stewart does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2006-10-10 00:03:46+10:00, stewart@willster.(none) +2 -0
  BUG#20839 Illegal error code: 155 returned downgrading from 5.1.12-> 5.1.11
  
  Update mysqldump to dump the needed tablespaces to create the tables
  for either the dbs or tables we're dumping.
  
  With --all-tablespaces, we still dump everything.

  client/mysqldump.c@stripped, 2006-10-10 00:03:40+10:00, stewart@willster.(none) +143 -26
    Add --no-tablespaces to force not dumping any tablespace information
    
    Change behaviour so that:
    If dumping all databases, all tablespaces are dumped
    If dumping with --all-tablespaces, all tablespaces are dumped
    If dumping a set of databases, dump only tablespaces used by tables in that database
    If dumping a set of tables, dump only tablespaces used by those tables
    
    If --no-tablespaces is specified, no tablespaces are dumped.
    
    Default behaviour is to dump a restorable dump - i.e. with the tablespaces.
    
    When connecting to old mysqld, --no-tablespaces should be specified.

  sql/sql_show.cc@stripped, 2006-10-10 00:03:41+10:00, stewart@willster.(none) +16 -5
    Use the TABLESPACE_NAME field of the INFORMATION_SCHEMA.PARTITIONS table.
    
    NOTE: *CHANGE* in behaviour: if no tablespace, TABLESPACE_NAME will be NULL.
    This is to support a tablespace called 'default' (which you can happily create).
    
    It is likely that the other fields with 'default' should change too.
    
    This should also happily continue to work in the future (from a user point of view)
    when we introduce tablespace per partition.

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	stewart
# Host:	willster.(none)
# Root:	/home/stewart/Documents/MySQL/5.1/bug20839

--- 1.252/client/mysqldump.c	2006-10-10 00:03:52 +10:00
+++ 1.253/client/mysqldump.c	2006-10-10 00:03:52 +10:00
@@ -99,7 +99,7 @@
                 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 @@
    "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 @@
 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 <help_start.h>
 
@@ -2746,9 +2754,100 @@
 
 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<tables ; i++)
+  {
+    mysql_real_escape_string(mysql, name_buff,
+                             table_names[i], strlen(table_names[i]));
+    strncat(where,"'",sz-3);
+    strncat(where,name_buff,sz-3);
+    strncat(where,"'",sz-3);
+    strncat(where,",",sz-3);
+  }
+  sz= strlen(where);
+  where[sz-1]= ')';
+  where[sz]= ')';
+  where[sz+1]= '\0';
+
+  DBUG_PRINT("info",("Dump TS for Tables where: %s",where));
+  r= dump_tablespaces(where);
+  my_free(where, MYF(0));
+  return r;
+}
+
+static int dump_tablespaces_for_databases(char** databases)
+{
+  char *where;
+  int r;
+  int i;
+
+  size_t sz= 150;
+  for (i=0 ; databases[i]!=NULL ; i++)
+    sz+=(strlen(databases[i])*2)+3+1;
+
+  where= my_malloc(sz, MYF(MY_WME));
+  if(!where)
+    return 1;
+
+  strncpy(where,
+          " AND TABLESPACE_NAME IN ("
+          "SELECT DISTINCT TABLESPACE_NAME FROM"
+          " INFORMATION_SCHEMA.PARTITIONS"
+          " WHERE"
+          " TABLE_SCHEMA IN (", sz-1);
+
+  for (i=0 ; databases[i]!=NULL ; i++)
+  {
+    char db_name_buff[NAME_LEN*2+3];
+    mysql_real_escape_string(mysql, db_name_buff,
+                             databases[i], strlen(databases[i]));
+    strncat(where,"'",sz-3);
+    strncat(where,db_name_buff,sz-3);
+    strncat(where,"'",sz-3);
+    strncat(where,",",sz-3);
+  }
+  sz= strlen(where);
+  where[sz-1]= ')';
+  where[sz]= ')';
+  where[sz+1]= '\0';
+
+  DBUG_PRINT("info",("Dump TS for DBs where: %s",where));
+  r= dump_tablespaces(where);
+  my_free(where, MYF(0));
+  return r;
+}
+
+static int dump_tablespaces(char* ts_where)
+{
   MYSQL_ROW row;
   MYSQL_RES *tableres;
   char buf[FN_REFLEN];
+  char sqlbuf[1024];
   int first;
   /*
     The following are used for parsing the EXTRA field
@@ -2757,20 +2856,28 @@
   char *ubs;
   char *endsemi;
 
-  if (mysql_query_with_error_report(mysql, &tableres,
-                                    "SELECT"
-                                    " LOGFILE_GROUP_NAME,"
-                                    " FILE_NAME,"
-                                    " TOTAL_EXTENTS,"
-                                    " INITIAL_SIZE,"
-                                    " ENGINE,"
-                                    " EXTRA"
-                                    " FROM INFORMATION_SCHEMA.FILES"
-                                    " WHERE FILE_TYPE = \"UNDO LOG\""
-                                    " AND FILE_NAME IS NOT NULL"
-                                    " GROUP BY LOGFILE_GROUP_NAME, FILE_NAME"
-                                    ", ENGINE"
-                                    " ORDER BY LOGFILE_GROUP_NAME"))
+  snprintf(sqlbuf,sizeof(sqlbuf),"%s%s%s%s%s",
+           "SELECT LOGFILE_GROUP_NAME,"
+           " FILE_NAME,"
+           " TOTAL_EXTENTS,"
+           " INITIAL_SIZE,"
+           " ENGINE,"
+           " EXTRA"
+           " FROM INFORMATION_SCHEMA.FILES"
+           " WHERE FILE_TYPE = 'UNDO LOG'"
+           " AND FILE_NAME IS NOT NULL",
+           (ts_where)?
+           " AND LOGFILE_GROUP_NAME IN ("
+           "SELECT DISTINCT LOGFILE_GROUP_NAME"
+           " FROM INFORMATION_SCHEMA.FILES WHERE FILE_TYPE = 'DATAFILE'"
+           :"",
+           (ts_where)?ts_where:"",
+           (ts_where)?")":"",
+           " GROUP BY LOGFILE_GROUP_NAME, FILE_NAME"
+           ", ENGINE"
+           " ORDER BY LOGFILE_GROUP_NAME");
+
+  if (mysql_query_with_error_report(mysql, &tableres,sqlbuf))
     return 1;
 
   buf[0]= 0;
@@ -2822,17 +2929,19 @@
     }
   }
 
-  if (mysql_query_with_error_report(mysql, &tableres,
-                                    "SELECT DISTINCT"
-                                    " TABLESPACE_NAME,"
-                                    " FILE_NAME,"
-                                    " LOGFILE_GROUP_NAME,"
-                                    " EXTENT_SIZE,"
-                                    " INITIAL_SIZE,"
-                                    " ENGINE"
-                                    " FROM INFORMATION_SCHEMA.FILES"
-                                    " WHERE FILE_TYPE = \"DATAFILE\""
-                                    " ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME"))
+  snprintf(sqlbuf,sizeof(sqlbuf),"%s%s%s",
+           "SELECT DISTINCT TABLESPACE_NAME,"
+           " FILE_NAME,"
+           " LOGFILE_GROUP_NAME,"
+           " EXTENT_SIZE,"
+           " INITIAL_SIZE,"
+           " ENGINE"
+           " FROM INFORMATION_SCHEMA.FILES"
+           " WHERE FILE_TYPE = 'DATAFILE'",
+           (ts_where)?ts_where:"",
+           " ORDER BY TABLESPACE_NAME, LOGFILE_GROUP_NAME");
+
+  if (mysql_query_with_error_report(mysql, &tableres,sqlbuf))
     return 1;
 
   buf[0]= 0;
@@ -3924,15 +4033,23 @@
     dump_all_tablespaces();
 
   if (opt_alldbs)
+  {
+    if (!opt_alltspcs && !opt_notspcs)
+      dump_all_tablespaces();
     dump_all_databases();
+  }
   else if (argc > 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

--- 1.362/sql/sql_show.cc	2006-10-10 00:03:52 +10:00
+++ 1.363/sql/sql_show.cc	2006-10-10 00:03:52 +10:00
@@ -3889,6 +3889,7 @@
 
 
 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 @@
       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 @@
           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 @@
       }
       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 @@
   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 @@
   {"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}
 };
 
Thread
bk commit into 5.1 tree (stewart:1.2305) BUG#20839Stewart Smith9 Oct