From de2c7c72d92319bb59a5044921381d724611718e Mon Sep 17 00:00:00 2001 From: "tomas@poseidon.ndb.mysql.com" <> Date: Wed, 1 Feb 2006 11:56:20 +0100 Subject: [PATCH] MySQL Bugs: #16466: DD: SHOW CREATE TABLE does not show TABLESPACE table_space1 STORAGE DISK --- mysql-test/r/ndb_dd_basic.result | 8 ++++ mysql-test/t/ndb_dd_basic.test | 2 + sql/ha_ndbcluster.cc | 43 ++++++++++++------- sql/ha_ndbcluster.h | 2 +- sql/handler.h | 4 +- sql/sql_show.cc | 4 +- storage/ndb/include/ndbapi/NdbDictionary.hpp | 3 +- storage/ndb/src/ndbapi/NdbDictionary.cpp | 21 +++++++-- .../ndb/tools/restore/consumer_restore.cpp | 6 +-- 9 files changed, 67 insertions(+), 26 deletions(-) diff --git a/mysql-test/r/ndb_dd_basic.result b/mysql-test/r/ndb_dd_basic.result index e2ca4e8185e..c0f20f1aee9 100644 --- a/mysql-test/r/ndb_dd_basic.result +++ b/mysql-test/r/ndb_dd_basic.result @@ -21,6 +21,14 @@ CREATE TABLE t1 (pk1 INT NOT NULL PRIMARY KEY, b INT NOT NULL, c INT NOT NULL) TABLESPACE ts1 STORAGE DISK ENGINE=NDB; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `pk1` int(11) NOT NULL, + `b` int(11) NOT NULL, + `c` int(11) NOT NULL, + PRIMARY KEY (`pk1`) +) TABLESPACE ts1 STORAGE DISK ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY () INSERT INTO t1 VALUES (0, 0, 0); SELECT * FROM t1; pk1 b c diff --git a/mysql-test/t/ndb_dd_basic.test b/mysql-test/t/ndb_dd_basic.test index d9e7fcc7ca7..0bc0e07fad8 100644 --- a/mysql-test/t/ndb_dd_basic.test +++ b/mysql-test/t/ndb_dd_basic.test @@ -54,6 +54,8 @@ CREATE TABLE t1 TABLESPACE ts1 STORAGE DISK ENGINE=NDB; +SHOW CREATE TABLE t1; + INSERT INTO t1 VALUES (0, 0, 0); SELECT * FROM t1; diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index a7579c7b465..7fa69d8e59c 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -8905,28 +8905,41 @@ ha_ndbcluster::generate_scan_filter(Ndb_cond_stack *ndb_cond_stack, /* get table space info for SHOW CREATE TABLE */ -char* ha_ndbcluster::get_tablespace_create_info() +char* ha_ndbcluster::get_tablespace_name() { - const char tablespace_key[]= " TABLESPACE "; - const char storage_key[]= " STORAGE DISK"; - char* str= 0; - Ndb *ndb= get_ndb(); NDBDICT *ndbdict= ndb->getDictionary(); + NdbError ndberr; + Uint32 id; ndb->setDatabaseName(m_dbname); const NDBTAB *ndbtab= ndbdict->getTable(m_tabname); if (ndbtab == 0) - return 0; - - // TODO retrieve table space name if there is one + { + ndberr= ndbdict->getNdbError(); + goto err; + } + if (!ndbtab->getTablespace(&id)) + { + ndberr= ndbdict->getNdbError(); + goto err; + } + { + NdbDictionary::Tablespace ts= ndbdict->getTablespace(id); + ndberr= ndbdict->getNdbError(); + if(ndberr.classification != ndberror_cl_none) + goto err; + return (my_strdup(ts.getName(), MYF(0))); + } +err: + if (ndberr.status == NdbError::TemporaryError) + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_GET_TEMPORARY_ERRMSG, ER(ER_GET_TEMPORARY_ERRMSG), + ndberr.code, ndberr.message, "NDB"); + else + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_ERROR, + ER_GET_ERRMSG, ER(ER_GET_ERRMSG), + ndberr.code, ndberr.message, "NDB"); return 0; - - const char *tablespace_name= ""; - - uint len= sizeof(tablespace_key) + strlen(tablespace_name) + sizeof(storage_key); - str= my_malloc(len, MYF(0)); - strxnmov(str, len, tablespace_key, tablespace_name, storage_key, NullS); - return(str); } /* diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index 2a5e3eaee3a..3f34db85246 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -701,7 +701,7 @@ private: uint set_up_partition_info(partition_info *part_info, TABLE *table, void *tab); - char* get_tablespace_create_info(); + char* get_tablespace_name(); int set_range_data(void *tab, partition_info* part_info); int set_list_data(void *tab, partition_info* part_info); int complemented_pk_read(const byte *old_data, byte *new_data, diff --git a/sql/handler.h b/sql/handler.h index 83dbdb19545..2702044e082 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1713,8 +1713,8 @@ public: { return FALSE; } virtual char* get_foreign_key_create_info() { return(NULL);} /* gets foreign key create string from InnoDB */ - virtual char* get_tablespace_create_info() - { return(NULL);} /* gets tablespace create string from handler */ + virtual char* get_tablespace_name() + { return(NULL);} /* gets tablespace name from handler */ /* used in ALTER TABLE; 1 if changing storage engine is allowed */ virtual bool can_switch_engines() { return 1; } /* used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */ diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6f8072f1b9f..6e1dbc37d11 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -1140,9 +1140,11 @@ store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, to the CREATE TABLE statement */ - if ((for_str= file->get_tablespace_create_info())) + if ((for_str= file->get_tablespace_name())) { + packet->append(" TABLESPACE "); packet->append(for_str, strlen(for_str)); + packet->append(" STORAGE DISK"); my_free(for_str, MYF(0)); } diff --git a/storage/ndb/include/ndbapi/NdbDictionary.hpp b/storage/ndb/include/ndbapi/NdbDictionary.hpp index 4196328976a..4ad3d6cbfb0 100644 --- a/storage/ndb/include/ndbapi/NdbDictionary.hpp +++ b/storage/ndb/include/ndbapi/NdbDictionary.hpp @@ -783,7 +783,7 @@ public: void setTablespace(const char * name); void setTablespace(const class Tablespace &); const char * getTablespace() const; - Uint32 getTablespaceId() const; + bool getTablespace(Uint32 *id= 0, Uint32 *version= 0) const; /** * Get table object type @@ -1736,6 +1736,7 @@ public: int createTablespace(const Tablespace &); int dropTablespace(const Tablespace&); Tablespace getTablespace(const char * name); + Tablespace getTablespace(Uint32 tablespaceId); int createDatafile(const Datafile &, bool overwrite_existing = false); int dropDatafile(const Datafile&); diff --git a/storage/ndb/src/ndbapi/NdbDictionary.cpp b/storage/ndb/src/ndbapi/NdbDictionary.cpp index 3dd73a57346..e8cc6cdfab4 100644 --- a/storage/ndb/src/ndbapi/NdbDictionary.cpp +++ b/storage/ndb/src/ndbapi/NdbDictionary.cpp @@ -600,10 +600,16 @@ NdbDictionary::Table::createTableInDb(Ndb* pNdb, bool equalOk) const { return pNdb->getDictionary()->createTable(* this); } -Uint32 -NdbDictionary::Table::getTablespaceId() const +bool +NdbDictionary::Table::getTablespace(Uint32 *id, Uint32 *version) const { - return m_impl.m_tablespace_id; + if (m_impl.m_tablespace_id == RNIL) + return false; + if (id) + *id= m_impl.m_tablespace_id; + if (version) + *version= m_impl.m_version; + return true; } void @@ -1687,6 +1693,15 @@ NdbDictionary::Dictionary::getTablespace(const char * name){ return tmp; } +NdbDictionary::Tablespace +NdbDictionary::Dictionary::getTablespace(Uint32 tablespaceId){ + NdbDictionary::Tablespace tmp; + m_impl.m_receiver.get_filegroup(NdbTablespaceImpl::getImpl(tmp), + NdbDictionary::Object::Tablespace, + tablespaceId); + return tmp; +} + int NdbDictionary::Dictionary::createDatafile(const Datafile & df, bool force){ return m_impl.createDatafile(NdbDatafileImpl::getImpl(df), force); diff --git a/storage/ndb/tools/restore/consumer_restore.cpp b/storage/ndb/tools/restore/consumer_restore.cpp index 0d177366a57..ad33cbe7b85 100644 --- a/storage/ndb/tools/restore/consumer_restore.cpp +++ b/storage/ndb/tools/restore/consumer_restore.cpp @@ -658,11 +658,11 @@ BackupRestore::table(const TableS & table){ NdbDictionary::Table copy(*table.m_dictTable); copy.setName(split[2].c_str()); - if (copy.getTablespaceId() != RNIL) + Uint32 id; + if (copy.getTablespace(&id)) { - Uint32 id = copy.getTablespaceId(); debug << "Connecting " << name << " to tablespace oldid: " << id << flush; - NdbDictionary::Tablespace* ts = m_tablespaces[copy.getTablespaceId()]; + NdbDictionary::Tablespace* ts = m_tablespaces[id]; debug << " newid: " << ts->getObjectId() << endl; copy.setTablespace(* ts); }