Merge mronstrom@bk-internal.mysql.com:/home/bk/mysql-5.1-new

into  c-8808e253.1238-1-64736c10.cust.bredbandsbolaget.se:/home/pappa/bug18198
parents 4cdb80a8 1608452d
...@@ -165,3 +165,21 @@ ENGINE=NDB ...@@ -165,3 +165,21 @@ ENGINE=NDB
PARTITION BY KEY(c3) PARTITIONS 5; PARTITION BY KEY(c3) PARTITIONS 5;
ALTER TABLE t1 COALESCE PARTITION 4; ALTER TABLE t1 COALESCE PARTITION 4;
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 (
c1 MEDIUMINT NOT NULL AUTO_INCREMENT,
c2 TEXT NOT NULL,
c3 INT NOT NULL,
PRIMARY KEY(c1,c3))
ENGINE=NDB
PARTITION BY KEY(c3) PARTITIONS 5;
ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1;
DROP TABLE t1;
CREATE TABLE t1 (
c1 MEDIUMINT NOT NULL AUTO_INCREMENT,
c2 TEXT NOT NULL,
c3 INT NOT NULL,
PRIMARY KEY(c1,c3))
ENGINE=NDB
PARTITION BY KEY(c3);
ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1;
DROP TABLE t1;
...@@ -153,3 +153,28 @@ b'0', ...@@ -153,3 +153,28 @@ b'0',
ALTER TABLE t1 COALESCE PARTITION 4; ALTER TABLE t1 COALESCE PARTITION 4;
DROP TABLE t1; DROP TABLE t1;
#
# BUG 16806: ALTER TABLE fails
#
CREATE TABLE t1 (
c1 MEDIUMINT NOT NULL AUTO_INCREMENT,
c2 TEXT NOT NULL,
c3 INT NOT NULL,
PRIMARY KEY(c1,c3))
ENGINE=NDB
PARTITION BY KEY(c3) PARTITIONS 5;
ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1;
DROP TABLE t1;
CREATE TABLE t1 (
c1 MEDIUMINT NOT NULL AUTO_INCREMENT,
c2 TEXT NOT NULL,
c3 INT NOT NULL,
PRIMARY KEY(c1,c3))
ENGINE=NDB
PARTITION BY KEY(c3);
ALTER TABLE t1 ADD COLUMN c4 INT AFTER c1;
DROP TABLE t1;
...@@ -199,13 +199,15 @@ bool is_name_in_list(char *name, ...@@ -199,13 +199,15 @@ bool is_name_in_list(char *name,
*/ */
bool partition_default_handling(TABLE *table, partition_info *part_info, bool partition_default_handling(TABLE *table, partition_info *part_info,
bool is_create_table_ind,
const char *normalized_path) const char *normalized_path)
{ {
DBUG_ENTER("partition_default_handling"); DBUG_ENTER("partition_default_handling");
if (part_info->use_default_no_partitions) if (part_info->use_default_no_partitions)
{ {
if (table->file->get_no_parts(normalized_path, &part_info->no_parts)) if (!is_create_table_ind &&
table->file->get_no_parts(normalized_path, &part_info->no_parts))
{ {
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
...@@ -214,7 +216,8 @@ bool partition_default_handling(TABLE *table, partition_info *part_info, ...@@ -214,7 +216,8 @@ bool partition_default_handling(TABLE *table, partition_info *part_info,
part_info->use_default_no_subpartitions) part_info->use_default_no_subpartitions)
{ {
uint no_parts; uint no_parts;
if (table->file->get_no_parts(normalized_path, &no_parts)) if (!is_create_table_ind &&
(table->file->get_no_parts(normalized_path, &no_parts)))
{ {
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
...@@ -1737,9 +1740,12 @@ bool fix_partition_func(THD *thd, const char* name, TABLE *table, ...@@ -1737,9 +1740,12 @@ bool fix_partition_func(THD *thd, const char* name, TABLE *table,
db_name= &db_name_string[home_dir_length]; db_name= &db_name_string[home_dir_length];
tables.db= db_name; tables.db= db_name;
if (!is_create_table_ind) if (!is_create_table_ind ||
(is_create_table_ind &&
thd->lex->sql_command != SQLCOM_CREATE_TABLE))
{ {
if (partition_default_handling(table, part_info, if (partition_default_handling(table, part_info,
is_create_table_ind,
table->s->normalized_path.str)) table->s->normalized_path.str))
{ {
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
...@@ -3742,7 +3748,7 @@ bool mysql_unpack_partition(THD *thd, const uchar *part_buf, ...@@ -3742,7 +3748,7 @@ bool mysql_unpack_partition(THD *thd, const uchar *part_buf,
DBUG_PRINT("info", ("default engine = %d, default_db_type = %d", DBUG_PRINT("info", ("default engine = %d, default_db_type = %d",
ha_legacy_type(part_info->default_engine_type), ha_legacy_type(part_info->default_engine_type),
ha_legacy_type(default_db_type))); ha_legacy_type(default_db_type)));
if (is_create_table_ind) if (is_create_table_ind && old_lex->sql_command == SQLCOM_CREATE_TABLE)
{ {
if (old_lex->like_name) if (old_lex->like_name)
{ {
...@@ -3756,7 +3762,8 @@ bool mysql_unpack_partition(THD *thd, const uchar *part_buf, ...@@ -3756,7 +3762,8 @@ bool mysql_unpack_partition(THD *thd, const uchar *part_buf,
char *src_table= table_ident->table.str; char *src_table= table_ident->table.str;
char buf[FN_REFLEN]; char buf[FN_REFLEN];
build_table_filename(buf, sizeof(buf), src_db, src_table, ""); build_table_filename(buf, sizeof(buf), src_db, src_table, "");
if (partition_default_handling(table, part_info, buf)) if (partition_default_handling(table, part_info,
FALSE, buf))
{ {
result= TRUE; result= TRUE;
goto end; goto end;
......
...@@ -2130,15 +2130,6 @@ bool mysql_create_table_internal(THD *thd, ...@@ -2130,15 +2130,6 @@ bool mysql_create_table_internal(THD *thd,
goto err; goto err;
part_info->part_info_string= part_syntax_buf; part_info->part_info_string= part_syntax_buf;
part_info->part_info_len= syntax_len; part_info->part_info_len= syntax_len;
if (create_info->db_type != engine_type)
{
delete file;
if (!(file= get_new_handler((TABLE_SHARE*) 0, thd->mem_root, engine_type)))
{
mem_alloc_error(sizeof(handler));
DBUG_RETURN(TRUE);
}
}
if ((!(engine_type->partition_flags && if ((!(engine_type->partition_flags &&
engine_type->partition_flags() & HA_CAN_PARTITION)) || engine_type->partition_flags() & HA_CAN_PARTITION)) ||
create_info->db_type == &partition_hton) create_info->db_type == &partition_hton)
...@@ -2155,6 +2146,43 @@ bool mysql_create_table_internal(THD *thd, ...@@ -2155,6 +2146,43 @@ bool mysql_create_table_internal(THD *thd,
{ {
DBUG_RETURN(TRUE); DBUG_RETURN(TRUE);
} }
/*
If we have default number of partitions or subpartitions we
might require to set-up the part_info object such that it
creates a proper .par file. The current part_info object is
only used to create the frm-file and .par-file.
*/
if (part_info->use_default_no_partitions &&
part_info->no_parts &&
part_info->no_parts != file->get_default_no_partitions(0ULL))
{
uint i= 0;
bool first= TRUE;
List_iterator<partition_element> part_it(part_info->partitions);
do
{
partition_element *part_elem= part_it++;
if (!first)
part_elem->part_state= PART_TO_BE_DROPPED;
first= FALSE;
} while (++i < part_info->partitions.elements);
}
else if (part_info->is_sub_partitioned() &&
part_info->use_default_no_subpartitions &&
part_info->no_subparts &&
part_info->no_subparts != file->get_default_no_partitions(0ULL))
{
part_info->no_subparts= file->get_default_no_partitions(0ULL);
}
}
else if (create_info->db_type != engine_type)
{
delete file;
if (!(file= get_new_handler((TABLE_SHARE*) 0, thd->mem_root, engine_type)))
{
mem_alloc_error(sizeof(handler));
DBUG_RETURN(TRUE);
}
} }
} }
#endif #endif
......
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