diff --git a/mysql-test/r/ndb_dd_alter.result b/mysql-test/r/ndb_dd_alter.result index cbe8db303b4..d101e6de791 100644 --- a/mysql-test/r/ndb_dd_alter.result +++ b/mysql-test/r/ndb_dd_alter.result @@ -439,7 +439,7 @@ t1 CREATE TABLE `t1` ( `a14` blob, PRIMARY KEY (`a1`), KEY `a3_i` (`a3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 +) /*!50100 TABLESPACE ts STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1 ALTER TABLE test.t1 DROP a14; ALTER TABLE test.t1 DROP a13; ALTER TABLE test.t1 DROP a12; @@ -459,7 +459,7 @@ t1 CREATE TABLE `t1` ( `a4` bit(1) DEFAULT NULL, `a5` tinyint(4) DEFAULT NULL, KEY `a3_i` (`a3`) -) ENGINE=ndbcluster DEFAULT CHARSET=latin1 +) /*!50100 TABLESPACE ts STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1 DROP TABLE test.t1; ALTER TABLESPACE ts DROP DATAFILE './table_space/datafile.dat' diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc index 4cd504d00a6..a666e6b1c34 100644 --- a/sql/ha_ndbcluster.cc +++ b/sql/ha_ndbcluster.cc @@ -4734,6 +4734,7 @@ int ha_ndbcluster::create(const char *name, const void *data, *pack_data; bool create_from_engine= (info->table_options & HA_OPTION_CREATE_FROM_ENGINE); bool is_truncate= (thd->lex->sql_command == SQLCOM_TRUNCATE); + char tablespace[FN_LEN]; DBUG_ENTER("ha_ndbcluster::create"); DBUG_PRINT("enter", ("name: %s", name)); @@ -4742,8 +4743,22 @@ int ha_ndbcluster::create(const char *name, set_dbname(name); set_tabname(name); + if ((my_errno= check_ndb_connection())) + DBUG_RETURN(my_errno); + + Ndb *ndb= get_ndb(); + NDBDICT *dict= ndb->getDictionary(); + if (is_truncate) { + { + Ndb_table_guard ndbtab_g(dict, m_tabname); + if (!(m_table= ndbtab_g.get_table())) + ERR_RETURN(dict->getNdbError()); + if ((get_tablespace_name(thd, tablespace, FN_LEN))) + info->tablespace= tablespace; + m_table= NULL; + } DBUG_PRINT("info", ("Dropping and re-creating table for TRUNCATE")); if ((my_errno= delete_table(name))) DBUG_RETURN(my_errno); @@ -4903,12 +4918,7 @@ int ha_ndbcluster::create(const char *name, DBUG_RETURN(my_errno); } - if ((my_errno= check_ndb_connection())) - DBUG_RETURN(my_errno); - // Create the table in NDB - Ndb *ndb= get_ndb(); - NDBDICT *dict= ndb->getDictionary(); if (dict->createTable(tab) != 0) { const NdbError err= dict->getNdbError(); @@ -8309,15 +8319,6 @@ ha_ndbcluster::setup_recattr(const NdbRecAttr* curr) DBUG_RETURN(0); } -void ha_ndbcluster::update_create_info(HA_CREATE_INFO *create_info) -{ - THD *thd= current_thd; - - if (thd->lex->sql_command == SQLCOM_TRUNCATE && - get_tablespace_name(thd,0,0)) - create_info->storage_media= HA_SM_DISK; -} - char* ha_ndbcluster::update_table_comment( /* out: table comment + additional */ @@ -10016,6 +10017,7 @@ char* ha_ndbcluster::get_tablespace_name(THD *thd, char* name, uint name_len) ndberr= ndbdict->getNdbError(); if(ndberr.classification != NdbError::NoError) goto err; + DBUG_PRINT("info", ("Found tablespace '%s'", ts.getName())); if (name) { strxnmov(name, name_len, ts.getName(), NullS); diff --git a/sql/ha_ndbcluster.h b/sql/ha_ndbcluster.h index 509211014c6..50f24c7a4cf 100644 --- a/sql/ha_ndbcluster.h +++ b/sql/ha_ndbcluster.h @@ -884,7 +884,6 @@ private: ulonglong *nb_reserved_values); bool uses_blob_value(); - void update_create_info(HA_CREATE_INFO *create_info); char *update_table_comment(const char * comment); int write_ndb_file(const char *name);