Description:
In some applications, the InnoDB tables grow rapidly. If the tablespace can be extended beforehand, the tps can be benefit.
How to repeat:
decribed as above
Suggested fix:
diff -Nur a/mysql-test/r/innodb_extent_tablespace.result b/mysql-test/r/innodb_extent_tablespace.result
--- a/mysql-test/r/innodb_extent_tablespace.result 1970-01-01 08:00:00.000000000 +0800
+++ b/mysql-test/r/innodb_extent_tablespace.result 2011-12-27 10:47:31.000000000 +0800
@@ -0,0 +1,7 @@
+set @@global.innodb_file_per_table = ON;
+drop table if exists test.t;
+create table t(c int) engine=innodb;
+alter tablespace `test/t` set extent_SIZE =1024;
+16777216
+drop table test.t;
+set @@global.innodb_file_per_table = OFF;
diff -Nur a/mysql-test/t/innodb_extent_tablespace.test b/mysql-test/t/innodb_extent_tablespace.test
--- a/mysql-test/t/innodb_extent_tablespace.test 1970-01-01 08:00:00.000000000 +0800
+++ b/mysql-test/t/innodb_extent_tablespace.test 2011-12-27 10:47:31.000000000 +0800
@@ -0,0 +1,13 @@
+--source include/have_innodb.inc
+
+set @@global.innodb_file_per_table = ON;
+--disable_warnings
+drop table if exists test.t;
+--enable_warnings
+
+create table t(c int) engine=innodb;
+ alter tablespace `test/t` set extent_SIZE =1024;
+--exec find ./ -name "t.ibd" | xargs ls -al | grep -o 16777216
+
+drop table test.t;
+set @@global.innodb_file_per_table = OFF;
diff -Nur a/sql/handler.h b/sql/handler.h
--- a/sql/handler.h 2011-12-27 09:19:25.000000000 +0800
+++ b/sql/handler.h 2011-12-27 10:47:31.000000000 +0800
@@ -495,7 +495,8 @@
{
TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1,
ALTER_TABLESPACE_ADD_FILE = 1,
- ALTER_TABLESPACE_DROP_FILE = 2
+ ALTER_TABLESPACE_DROP_FILE = 2,
+ ALTER_TABLESPACE_ALTER_FILE = 3
};
enum tablespace_access_mode
diff -Nur a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c
--- a/storage/innobase/fil/fil0fil.c 2011-12-27 09:19:26.000000000 +0800
+++ b/storage/innobase/fil/fil0fil.c 2011-12-27 10:47:52.000000000 +0800
@@ -358,7 +358,7 @@
Checks if a single-table tablespace for a given table name exists in the
tablespace memory cache.
@return space id, ULINT_UNDEFINED if not found */
-static
+UNIV_INTERN
ulint
fil_get_space_id_for_table(
/*=======================*/
@@ -3844,7 +3844,7 @@
Checks if a single-table tablespace for a given table name exists in the
tablespace memory cache.
@return space id, ULINT_UNDEFINED if not found */
-static
+UNIV_INTERN
ulint
fil_get_space_id_for_table(
/*=======================*/
diff -Nur a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
--- a/storage/innobase/handler/ha_innodb.cc 2011-12-27 09:19:26.000000000 +0800
+++ b/storage/innobase/handler/ha_innodb.cc 2011-12-27 10:47:31.000000000 +0800
@@ -393,6 +393,11 @@
/*=======================*/
uint flags);
+/****************************************************************//**
+Alter tablespace supported in an InnoDB table. Allow setting extent space. */
+int innobase_alter_tablespace(handlerton *hton,
+ THD* thd, st_alter_tablespace *alter_info);
+
static const char innobase_hton_name[]= "InnoDB";
/*************************************************************//**
@@ -2242,6 +2247,7 @@
innobase_hton->flags=HTON_NO_FLAGS;
innobase_hton->release_temporary_latches=innobase_release_temporary_latches;
innobase_hton->alter_table_flags = innobase_alter_table_flags;
+ innobase_hton->alter_tablespace= innobase_alter_tablespace;
ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR);
@@ -2662,6 +2668,32 @@
| HA_INPLACE_ADD_PK_INDEX_NO_READ_WRITE);
}
+/****************************************************************//**
+Alter tablespace supported in an InnoDB table. Allow setting extent space. */
+int innobase_alter_tablespace(handlerton *hton,
+ THD* thd, st_alter_tablespace *alter_info)
+{
+ if (alter_info->ts_alter_tablespace_type != ALTER_TABLESPACE_ALTER_FILE)
+ {
+ return HA_ADMIN_NOT_IMPLEMENTED;
+ }
+
+ ulint table_space= fil_get_space_id_for_table(alter_info->tablespace_name);
+
+ if (table_space == ULINT_UNDEFINED)
+ {
+ my_error(ER_WRONG_TABLE_NAME, MYF(0), alter_info->tablespace_name);
+ return EE_FILENOTFOUND;
+ }
+
+ ulint extent_size= alter_info->extent_size;
+
+ ulint actual_size=0;
+ fil_extend_space_to_desired_size(&actual_size, table_space, extent_size);
+
+ return 0;
+}
+
/*****************************************************************//**
Commits a transaction in an InnoDB database. */
static
diff -Nur a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h
--- a/storage/innobase/include/fil0fil.h 2011-12-27 09:19:26.000000000 +0800
+++ b/storage/innobase/include/fil0fil.h 2011-12-27 10:47:31.000000000 +0800
@@ -725,6 +725,16 @@
fil_tablespace_is_being_deleted(
/*============================*/
ulint id); /*!< in: space id */
+/*******************************************************************//**
+Checks if a single-table tablespace for a given table name exists in the
+tablespace memory cache.
+@return space id, ULINT_UNDEFINED if not found */
+UNIV_INTERN
+ulint
+fil_get_space_id_for_table(
+/*=======================*/
+ const char* name); /*!< in: table name in the standard
+ 'databasename/tablename' format */
typedef struct fil_space_struct fil_space_t;
Description: In some applications, the InnoDB tables grow rapidly. If the tablespace can be extended beforehand, the tps can be benefit. How to repeat: decribed as above Suggested fix: diff -Nur a/mysql-test/r/innodb_extent_tablespace.result b/mysql-test/r/innodb_extent_tablespace.result --- a/mysql-test/r/innodb_extent_tablespace.result 1970-01-01 08:00:00.000000000 +0800 +++ b/mysql-test/r/innodb_extent_tablespace.result 2011-12-27 10:47:31.000000000 +0800 @@ -0,0 +1,7 @@ +set @@global.innodb_file_per_table = ON; +drop table if exists test.t; +create table t(c int) engine=innodb; +alter tablespace `test/t` set extent_SIZE =1024; +16777216 +drop table test.t; +set @@global.innodb_file_per_table = OFF; diff -Nur a/mysql-test/t/innodb_extent_tablespace.test b/mysql-test/t/innodb_extent_tablespace.test --- a/mysql-test/t/innodb_extent_tablespace.test 1970-01-01 08:00:00.000000000 +0800 +++ b/mysql-test/t/innodb_extent_tablespace.test 2011-12-27 10:47:31.000000000 +0800 @@ -0,0 +1,13 @@ +--source include/have_innodb.inc + +set @@global.innodb_file_per_table = ON; +--disable_warnings +drop table if exists test.t; +--enable_warnings + +create table t(c int) engine=innodb; + alter tablespace `test/t` set extent_SIZE =1024; +--exec find ./ -name "t.ibd" | xargs ls -al | grep -o 16777216 + +drop table test.t; +set @@global.innodb_file_per_table = OFF; diff -Nur a/sql/handler.h b/sql/handler.h --- a/sql/handler.h 2011-12-27 09:19:25.000000000 +0800 +++ b/sql/handler.h 2011-12-27 10:47:31.000000000 +0800 @@ -495,7 +495,8 @@ { TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1, ALTER_TABLESPACE_ADD_FILE = 1, - ALTER_TABLESPACE_DROP_FILE = 2 + ALTER_TABLESPACE_DROP_FILE = 2, + ALTER_TABLESPACE_ALTER_FILE = 3 }; enum tablespace_access_mode diff -Nur a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c --- a/storage/innobase/fil/fil0fil.c 2011-12-27 09:19:26.000000000 +0800 +++ b/storage/innobase/fil/fil0fil.c 2011-12-27 10:47:52.000000000 +0800 @@ -358,7 +358,7 @@ Checks if a single-table tablespace for a given table name exists in the tablespace memory cache. @return space id, ULINT_UNDEFINED if not found */ -static +UNIV_INTERN ulint fil_get_space_id_for_table( /*=======================*/ @@ -3844,7 +3844,7 @@ Checks if a single-table tablespace for a given table name exists in the tablespace memory cache. @return space id, ULINT_UNDEFINED if not found */ -static +UNIV_INTERN ulint fil_get_space_id_for_table( /*=======================*/ diff -Nur a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc --- a/storage/innobase/handler/ha_innodb.cc 2011-12-27 09:19:26.000000000 +0800 +++ b/storage/innobase/handler/ha_innodb.cc 2011-12-27 10:47:31.000000000 +0800 @@ -393,6 +393,11 @@ /*=======================*/ uint flags); +/****************************************************************//** +Alter tablespace supported in an InnoDB table. Allow setting extent space. */ +int innobase_alter_tablespace(handlerton *hton, + THD* thd, st_alter_tablespace *alter_info); + static const char innobase_hton_name[]= "InnoDB"; /*************************************************************//** @@ -2242,6 +2247,7 @@ innobase_hton->flags=HTON_NO_FLAGS; innobase_hton->release_temporary_latches=innobase_release_temporary_latches; innobase_hton->alter_table_flags = innobase_alter_table_flags; + innobase_hton->alter_tablespace= innobase_alter_tablespace; ut_a(DATA_MYSQL_TRUE_VARCHAR == (ulint)MYSQL_TYPE_VARCHAR); @@ -2662,6 +2668,32 @@ | HA_INPLACE_ADD_PK_INDEX_NO_READ_WRITE); } +/****************************************************************//** +Alter tablespace supported in an InnoDB table. Allow setting extent space. */ +int innobase_alter_tablespace(handlerton *hton, + THD* thd, st_alter_tablespace *alter_info) +{ + if (alter_info->ts_alter_tablespace_type != ALTER_TABLESPACE_ALTER_FILE) + { + return HA_ADMIN_NOT_IMPLEMENTED; + } + + ulint table_space= fil_get_space_id_for_table(alter_info->tablespace_name); + + if (table_space == ULINT_UNDEFINED) + { + my_error(ER_WRONG_TABLE_NAME, MYF(0), alter_info->tablespace_name); + return EE_FILENOTFOUND; + } + + ulint extent_size= alter_info->extent_size; + + ulint actual_size=0; + fil_extend_space_to_desired_size(&actual_size, table_space, extent_size); + + return 0; +} + /*****************************************************************//** Commits a transaction in an InnoDB database. */ static diff -Nur a/storage/innobase/include/fil0fil.h b/storage/innobase/include/fil0fil.h --- a/storage/innobase/include/fil0fil.h 2011-12-27 09:19:26.000000000 +0800 +++ b/storage/innobase/include/fil0fil.h 2011-12-27 10:47:31.000000000 +0800 @@ -725,6 +725,16 @@ fil_tablespace_is_being_deleted( /*============================*/ ulint id); /*!< in: space id */ +/*******************************************************************//** +Checks if a single-table tablespace for a given table name exists in the +tablespace memory cache. +@return space id, ULINT_UNDEFINED if not found */ +UNIV_INTERN +ulint +fil_get_space_id_for_table( +/*=======================*/ + const char* name); /*!< in: table name in the standard + 'databasename/tablename' format */ typedef struct fil_space_struct fil_space_t;