bug#24667 After ALTER TABLE operation ndb_dd table becomes regular ndb: ALTER...

bug#24667  After ALTER TABLE operation ndb_dd table becomes regular ndb: ALTER TABLE must specify STORAGE explicitely to change it, + post review changes
parent dab48d5d
...@@ -96,6 +96,14 @@ enum ha_key_alg { ...@@ -96,6 +96,14 @@ enum ha_key_alg {
HA_KEY_ALG_FULLTEXT= 4 /* FULLTEXT (MyISAM tables) */ HA_KEY_ALG_FULLTEXT= 4 /* FULLTEXT (MyISAM tables) */
}; };
/* Storage media types */
enum ha_storage_media {
HA_SM_DEFAULT= 0, /* Not specified (engine default) */
HA_SM_DISK= 1, /* DISK storage */
HA_SM_MEMORY= 2 /* MAIN MEMORY storage */
};
/* The following is parameter to ha_extra() */ /* The following is parameter to ha_extra() */
enum ha_extra_function { enum ha_extra_function {
......
...@@ -237,7 +237,7 @@ t2 CREATE TABLE `t2` ( ...@@ -237,7 +237,7 @@ t2 CREATE TABLE `t2` (
`c2` int(11) NOT NULL, `c2` int(11) NOT NULL,
PRIMARY KEY (`pk2`) PRIMARY KEY (`pk2`)
) /*!50100 TABLESPACE table_space1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) /*!50100 TABLESPACE table_space1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
ALTER TABLE test.t1 ENGINE=NDBCLUSTER; ALTER TABLE test.t1 STORAGE MEMORY ENGINE=NDBCLUSTER;
SHOW CREATE TABLE test.t1; SHOW CREATE TABLE test.t1;
Table Create Table Table Create Table
t1 CREATE TABLE `t1` ( t1 CREATE TABLE `t1` (
...@@ -341,7 +341,7 @@ t1 CREATE TABLE `t1` ( ...@@ -341,7 +341,7 @@ t1 CREATE TABLE `t1` (
KEY `a2` (`a2`), KEY `a2` (`a2`),
KEY `a3` (`a3`), KEY `a3` (`a3`),
KEY `a8` (`a8`) KEY `a8` (`a8`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) /*!50100 TABLESPACE table_space1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( t2 CREATE TABLE `t2` (
`b1` smallint(6) NOT NULL, `b1` smallint(6) NOT NULL,
......
...@@ -70,7 +70,7 @@ t1 CREATE TABLE `t1` ( ...@@ -70,7 +70,7 @@ t1 CREATE TABLE `t1` (
PRIMARY KEY (`c1`), PRIMARY KEY (`c1`),
KEY `t1_i` (`c2`,`c3`), KEY `t1_i` (`c2`,`c3`),
KEY `c5` (`c5`) KEY `c5` (`c5`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) /*!50100 TABLESPACE ts1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
**** Show first set of ALTERs on SLAVE **** **** Show first set of ALTERs on SLAVE ****
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
...@@ -83,7 +83,7 @@ t1 CREATE TABLE `t1` ( ...@@ -83,7 +83,7 @@ t1 CREATE TABLE `t1` (
PRIMARY KEY (`c1`), PRIMARY KEY (`c1`),
KEY `t1_i` (`c2`,`c3`), KEY `t1_i` (`c2`,`c3`),
KEY `c5` (`c5`) KEY `c5` (`c5`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) /*!50100 TABLESPACE ts1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
**** Second set of alters test 1 **** **** Second set of alters test 1 ****
ALTER TABLE t1 RENAME t2; ALTER TABLE t1 RENAME t2;
ALTER TABLE t2 DROP INDEX c5; ALTER TABLE t2 DROP INDEX c5;
...@@ -102,7 +102,7 @@ t1 CREATE TABLE `t1` ( ...@@ -102,7 +102,7 @@ t1 CREATE TABLE `t1` (
`c5` double DEFAULT NULL, `c5` double DEFAULT NULL,
PRIMARY KEY (`c1`), PRIMARY KEY (`c1`),
KEY `t1_i` (`c2`,`c3`) KEY `t1_i` (`c2`,`c3`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) /*!50100 TABLESPACE ts1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
**** Show second set of ALTERs on SLAVE **** **** Show second set of ALTERs on SLAVE ****
SHOW CREATE TABLE t1; SHOW CREATE TABLE t1;
Table Create Table Table Create Table
...@@ -114,7 +114,7 @@ t1 CREATE TABLE `t1` ( ...@@ -114,7 +114,7 @@ t1 CREATE TABLE `t1` (
`c5` double DEFAULT NULL, `c5` double DEFAULT NULL,
PRIMARY KEY (`c1`), PRIMARY KEY (`c1`),
KEY `t1_i` (`c2`,`c3`) KEY `t1_i` (`c2`,`c3`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) /*!50100 TABLESPACE ts1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
**** Third and last set of alters for test1 **** **** Third and last set of alters for test1 ****
ALTER TABLE t1 CHANGE c1 c1 DOUBLE; ALTER TABLE t1 CHANGE c1 c1 DOUBLE;
ALTER TABLE t1 CHANGE c2 c2 DECIMAL(10,2); ALTER TABLE t1 CHANGE c2 c2 DECIMAL(10,2);
...@@ -136,7 +136,7 @@ t1 CREATE TABLE `t1` ( ...@@ -136,7 +136,7 @@ t1 CREATE TABLE `t1` (
`c5` double DEFAULT NULL, `c5` double DEFAULT NULL,
PRIMARY KEY (`c1`), PRIMARY KEY (`c1`),
KEY `t1_i` (`c2`) KEY `t1_i` (`c2`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) /*!50100 TABLESPACE ts1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
SELECT * FROM t1 ORDER BY c1 LIMIT 5; SELECT * FROM t1 ORDER BY c1 LIMIT 5;
c1 c2 c3 c5 c1 c2 c3 c5
1 2.00 b1b1b1b1b1b1b1b1b1b1 NULL 1 2.00 b1b1b1b1b1b1b1b1b1b1 NULL
...@@ -154,7 +154,7 @@ t1 CREATE TABLE `t1` ( ...@@ -154,7 +154,7 @@ t1 CREATE TABLE `t1` (
`c5` double DEFAULT NULL, `c5` double DEFAULT NULL,
PRIMARY KEY (`c1`), PRIMARY KEY (`c1`),
KEY `t1_i` (`c2`) KEY `t1_i` (`c2`)
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 ) /*!50100 TABLESPACE ts1 STORAGE DISK */ ENGINE=ndbcluster DEFAULT CHARSET=latin1
SELECT * FROM t1 where c1 = 1; SELECT * FROM t1 where c1 = 1;
c1 c2 c3 c5 c1 c2 c3 c5
1 2.00 b1b1b1b1b1b1b1b1b1b1 NULL 1 2.00 b1b1b1b1b1b1b1b1b1b1 NULL
......
...@@ -111,7 +111,7 @@ SHOW CREATE TABLE test.t1; ...@@ -111,7 +111,7 @@ SHOW CREATE TABLE test.t1;
ALTER TABLE test.t2 TABLESPACE table_space1 STORAGE DISK ALTER TABLE test.t2 TABLESPACE table_space1 STORAGE DISK
ENGINE=NDB; ENGINE=NDB;
SHOW CREATE TABLE test.t2; SHOW CREATE TABLE test.t2;
ALTER TABLE test.t1 ENGINE=NDBCLUSTER; ALTER TABLE test.t1 STORAGE MEMORY ENGINE=NDBCLUSTER;
SHOW CREATE TABLE test.t1; SHOW CREATE TABLE test.t1;
--echo --echo
######################### End Test Section 2 ################# ######################### End Test Section 2 #################
......
...@@ -4807,7 +4807,7 @@ int ha_ndbcluster::create(const char *name, ...@@ -4807,7 +4807,7 @@ int ha_ndbcluster::create(const char *name,
if ((my_errno= create_ndb_column(col, field, info))) if ((my_errno= create_ndb_column(col, field, info)))
DBUG_RETURN(my_errno); DBUG_RETURN(my_errno);
if (info->store_on_disk || getenv("NDB_DEFAULT_DISK")) if (info->storage_media == HA_SM_DISK || getenv("NDB_DEFAULT_DISK"))
col.setStorageType(NdbDictionary::Column::StorageTypeDisk); col.setStorageType(NdbDictionary::Column::StorageTypeDisk);
else else
col.setStorageType(NdbDictionary::Column::StorageTypeMemory); col.setStorageType(NdbDictionary::Column::StorageTypeMemory);
...@@ -4827,7 +4827,7 @@ int ha_ndbcluster::create(const char *name, ...@@ -4827,7 +4827,7 @@ int ha_ndbcluster::create(const char *name,
NdbDictionary::Column::StorageTypeMemory); NdbDictionary::Column::StorageTypeMemory);
} }
if (info->store_on_disk) if (info->storage_media == HA_SM_DISK)
{ {
if (info->tablespace) if (info->tablespace)
tab.setTablespace(info->tablespace); tab.setTablespace(info->tablespace);
...@@ -4837,7 +4837,7 @@ int ha_ndbcluster::create(const char *name, ...@@ -4837,7 +4837,7 @@ int ha_ndbcluster::create(const char *name,
else if (info->tablespace) else if (info->tablespace)
{ {
tab.setTablespace(info->tablespace); tab.setTablespace(info->tablespace);
info->store_on_disk = true; //if use tablespace, that also means store on disk info->storage_media = HA_SM_DISK; //if use tablespace, that also means store on disk
} }
// No primary key, create shadow key as 64 bit, auto increment // No primary key, create shadow key as 64 bit, auto increment
...@@ -9949,7 +9949,7 @@ int ha_ndbcluster::generate_scan_filter_from_key(NdbScanOperation *op, ...@@ -9949,7 +9949,7 @@ int ha_ndbcluster::generate_scan_filter_from_key(NdbScanOperation *op,
/* /*
get table space info for SHOW CREATE TABLE get table space info for SHOW CREATE TABLE
*/ */
char* ha_ndbcluster::get_tablespace_name(THD *thd, char* name) char* ha_ndbcluster::get_tablespace_name(THD *thd, char* name, uint name_len)
{ {
Ndb *ndb= check_ndb_in_thd(thd); Ndb *ndb= check_ndb_in_thd(thd);
NDBDICT *ndbdict= ndb->getDictionary(); NDBDICT *ndbdict= ndb->getDictionary();
...@@ -9969,7 +9969,7 @@ char* ha_ndbcluster::get_tablespace_name(THD *thd, char* name) ...@@ -9969,7 +9969,7 @@ char* ha_ndbcluster::get_tablespace_name(THD *thd, char* name)
goto err; goto err;
if (name) if (name)
{ {
strxnmov(name, FN_LEN, ts.getName(), NullS); strxnmov(name, name_len, ts.getName(), NullS);
return name; return name;
} }
else else
......
...@@ -824,7 +824,7 @@ private: ...@@ -824,7 +824,7 @@ private:
uint set_up_partition_info(partition_info *part_info, uint set_up_partition_info(partition_info *part_info,
TABLE *table, TABLE *table,
void *tab); void *tab);
char* get_tablespace_name(THD *thd, char *name); char* get_tablespace_name(THD *thd, char *name, uint name_len);
int set_range_data(void *tab, partition_info* part_info); int set_range_data(void *tab, partition_info* part_info);
int set_list_data(void *tab, partition_info* part_info); int set_list_data(void *tab, partition_info* part_info);
int complemented_read(const byte *old_data, byte *new_data, int complemented_read(const byte *old_data, byte *new_data,
......
...@@ -764,7 +764,7 @@ typedef struct st_ha_create_information ...@@ -764,7 +764,7 @@ typedef struct st_ha_create_information
bool table_existed; /* 1 in create if table existed */ bool table_existed; /* 1 in create if table existed */
bool frm_only; /* 1 if no ha_create_table() */ bool frm_only; /* 1 if no ha_create_table() */
bool varchar; /* 1 if table has a VARCHAR */ bool varchar; /* 1 if table has a VARCHAR */
bool store_on_disk; /* 1 if table stored on disk */ enum ha_storage_media storage_media; /* DEFAULT, DISK or MEMORY */
} HA_CREATE_INFO; } HA_CREATE_INFO;
...@@ -1410,7 +1410,7 @@ public: ...@@ -1410,7 +1410,7 @@ public:
{ return FALSE; } { return FALSE; }
virtual char* get_foreign_key_create_info() virtual char* get_foreign_key_create_info()
{ return(NULL);} /* gets foreign key create string from InnoDB */ { return(NULL);} /* gets foreign key create string from InnoDB */
virtual char* get_tablespace_name(THD *thd, char *name) virtual char* get_tablespace_name(THD *thd, char *name, uint name_len)
{ return(NULL);} /* gets tablespace name from handler */ { return(NULL);} /* gets tablespace name from handler */
/* used in ALTER TABLE; 1 if changing storage engine is allowed */ /* used in ALTER TABLE; 1 if changing storage engine is allowed */
virtual bool can_switch_engines() { return 1; } virtual bool can_switch_engines() { return 1; }
......
...@@ -1267,7 +1267,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet, ...@@ -1267,7 +1267,7 @@ int store_create_info(THD *thd, TABLE_LIST *table_list, String *packet,
to the CREATE TABLE statement to the CREATE TABLE statement
*/ */
if ((for_str= file->get_tablespace_name(thd,0))) if ((for_str= file->get_tablespace_name(thd,0,0)))
{ {
packet->append(STRING_WITH_LEN(" /*!50100 TABLESPACE ")); packet->append(STRING_WITH_LEN(" /*!50100 TABLESPACE "));
packet->append(for_str, strlen(for_str)); packet->append(for_str, strlen(for_str));
...@@ -3974,7 +3974,7 @@ static void store_schema_partitions_record(THD *thd, TABLE *schema_table, ...@@ -3974,7 +3974,7 @@ static void store_schema_partitions_record(THD *thd, TABLE *schema_table,
strlen(part_elem->tablespace_name), cs); strlen(part_elem->tablespace_name), cs);
else else
{ {
char *ts= showing_table->file->get_tablespace_name(thd,0); char *ts= showing_table->file->get_tablespace_name(thd,0,0);
if(ts) if(ts)
{ {
table->field[24]->store(ts, strlen(ts), cs); table->field[24]->store(ts, strlen(ts), cs);
......
...@@ -5630,14 +5630,14 @@ view_err: ...@@ -5630,14 +5630,14 @@ view_err:
if (!(used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE)) if (!(used_fields & HA_CREATE_USED_KEY_BLOCK_SIZE))
create_info->key_block_size= table->s->key_block_size; create_info->key_block_size= table->s->key_block_size;
if (!create_info->tablespace) if (!create_info->tablespace && create_info->storage_media != HA_SM_MEMORY)
{ {
/* /*
Regular alter table of disk stored table (no tablespace change) Regular alter table of disk stored table (no tablespace/storage change)
Copy tablespace name Copy tablespace name
*/ */
if (table->file->get_tablespace_name(thd, (char *) &tablespace)) if ((table->file->get_tablespace_name(thd, tablespace, FN_LEN)))
create_info->tablespace= (char *) &tablespace; create_info->tablespace= tablespace;
} }
restore_record(table, s->default_values); // Empty record for DEFAULT restore_record(table, s->default_values); // Empty record for DEFAULT
List_iterator<Alter_drop> drop_it(alter_info->drop_list); List_iterator<Alter_drop> drop_it(alter_info->drop_list);
......
...@@ -3947,8 +3947,8 @@ create_table_option: ...@@ -3947,8 +3947,8 @@ create_table_option:
| DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.data_file_name= $4.str; Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR; } | DATA_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.data_file_name= $4.str; Lex->create_info.used_fields|= HA_CREATE_USED_DATADIR; }
| INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR; } | INDEX_SYM DIRECTORY_SYM opt_equal TEXT_STRING_sys { Lex->create_info.index_file_name= $4.str; Lex->create_info.used_fields|= HA_CREATE_USED_INDEXDIR; }
| TABLESPACE ident {Lex->create_info.tablespace= $2.str;} | TABLESPACE ident {Lex->create_info.tablespace= $2.str;}
| STORAGE_SYM DISK_SYM {Lex->create_info.store_on_disk= TRUE;} | STORAGE_SYM DISK_SYM {Lex->create_info.storage_media= HA_SM_DISK;}
| STORAGE_SYM MEMORY_SYM {Lex->create_info.store_on_disk= FALSE;} | STORAGE_SYM MEMORY_SYM {Lex->create_info.storage_media= HA_SM_MEMORY;}
| CONNECTION_SYM opt_equal TEXT_STRING_sys { Lex->create_info.connect_string.str= $3.str; Lex->create_info.connect_string.length= $3.length; Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION; } | CONNECTION_SYM opt_equal TEXT_STRING_sys { Lex->create_info.connect_string.str= $3.str; Lex->create_info.connect_string.length= $3.length; Lex->create_info.used_fields|= HA_CREATE_USED_CONNECTION; }
| KEY_BLOCK_SIZE opt_equal ulong_num | KEY_BLOCK_SIZE opt_equal ulong_num
{ {
...@@ -4690,6 +4690,7 @@ alter: ...@@ -4690,6 +4690,7 @@ alter:
lex->alter_info.reset(); lex->alter_info.reset();
lex->alter_info.flags= 0; lex->alter_info.flags= 0;
lex->no_write_to_binlog= 0; lex->no_write_to_binlog= 0;
lex->create_info.storage_media= HA_SM_DEFAULT;
} }
alter_commands alter_commands
{} {}
...@@ -8342,6 +8343,7 @@ show_param: ...@@ -8342,6 +8343,7 @@ show_param:
if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0)) if (!lex->select_lex.add_table_to_list(YYTHD, $3, NULL,0))
YYABORT; YYABORT;
lex->only_view= 0; lex->only_view= 0;
lex->create_info.storage_media= HA_SM_DEFAULT;
} }
| CREATE VIEW_SYM table_ident | CREATE VIEW_SYM table_ident
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment