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

into  c-8808e253.1238-1-64736c10.cust.bredbandsbolaget.se:/home/pappa/bug17754
parents 95242e71 bd77396a
......@@ -89,6 +89,69 @@ ALTER TABLE t1
PARTITION BY KEY(a)
(PARTITION p0 ENGINE = NDB, PARTITION p1 ENGINE = NDB);
drop table t1;
create table t1 (a int)
engine=ndb
partition by key(a)
(partition p0, partition p1);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster)
alter table t1 engine=heap;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MEMORY, PARTITION p1 ENGINE = MEMORY)
alter table t1 engine=ndb;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster)
alter table t1 engine=heap remove partitioning;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1
alter table t1 engine=ndb
partition by key(a)
(partition p0, partition p1 engine = ndb);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster)
alter table t1
partition by key (a)
(partition p0 engine=ndb, partition p1 engine=ndb);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster)
alter table t1 remove partitioning;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY ()
alter table t1
partition by key(a)
(partition p0 engine=ndb, partition p1);
ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MySQL
alter table t1
engine=ndb
partition by key(a)
(partition p0 engine=ndb, partition p1 engine = ndb);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=ndbcluster DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = ndbcluster, PARTITION p1 ENGINE = ndbcluster)
drop table t1;
CREATE TABLE t1 (
c1 MEDIUMINT NOT NULL AUTO_INCREMENT,
c2 TEXT NOT NULL,
......
......@@ -315,6 +315,135 @@ drop table t1;
create table t1 (s1 int, unique (s1)) partition by list (s1) (partition x1 VALUES in (10), partition x2 values in (20));
alter table t1 add partition (partition x3 values in (30));
drop table t1;
create table t1 (a int)
partition by key(a)
partitions 2
(partition p0 engine=myisam, partition p1 engine=myisam);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MyISAM, PARTITION p1 ENGINE = MyISAM)
alter table t1;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MyISAM, PARTITION p1 ENGINE = MyISAM)
alter table t1 engine=myisam;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MyISAM, PARTITION p1 ENGINE = MyISAM)
alter table t1 engine=heap;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MEMORY, PARTITION p1 ENGINE = MEMORY)
alter table t1 remove partitioning;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1
drop table t1;
create table t1 (a int)
engine=myisam
partition by key(a)
partitions 2
(partition p0 engine=myisam, partition p1 engine=myisam);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MyISAM, PARTITION p1 ENGINE = MyISAM)
alter table t1 add column b int remove partitioning;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL,
`b` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
alter table t1
engine=myisam
partition by key(a)
(partition p0 engine=myisam, partition p1);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL,
`b` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MyISAM, PARTITION p1 ENGINE = MyISAM)
alter table t1
engine=heap
partition by key(a)
(partition p0, partition p1 engine=heap);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL,
`b` int(11) default NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MEMORY, PARTITION p1 ENGINE = MEMORY)
alter table t1 engine=myisam, add column c int remove partitioning;
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL,
`b` int(11) default NULL,
`c` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
alter table t1
engine=heap
partition by key (a)
(partition p0, partition p1);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL,
`b` int(11) default NULL,
`c` int(11) default NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MEMORY, PARTITION p1 ENGINE = MEMORY)
alter table t1
partition by key (a)
(partition p0, partition p1);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL,
`b` int(11) default NULL,
`c` int(11) default NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MEMORY, PARTITION p1 ENGINE = MEMORY)
alter table t1
engine=heap
partition by key (a)
(partition p0, partition p1);
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) default NULL,
`b` int(11) default NULL,
`c` int(11) default NULL
) ENGINE=MEMORY DEFAULT CHARSET=latin1 PARTITION BY KEY (a) (PARTITION p0 ENGINE = MEMORY, PARTITION p1 ENGINE = MEMORY)
alter table t1
partition by key(a)
(partition p0, partition p1 engine=heap);
ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MySQL
alter table t1
partition by key(a)
(partition p0 engine=heap, partition p1);
ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MySQL
alter table t1
engine=heap
partition by key (a)
(partition p0 engine=heap, partition p1 engine=myisam);
ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MySQL
alter table t1
partition by key (a)
(partition p0 engine=heap, partition p1 engine=myisam);
ERROR HY000: The mix of handlers in the partitions is not allowed in this version of MySQL
drop table t1;
CREATE TABLE t1 (
f_int1 INTEGER, f_int2 INTEGER,
f_char1 CHAR(10), f_char2 CHAR(10), f_charbig VARCHAR(1000)
......
......@@ -80,6 +80,51 @@ PARTITION BY KEY(a)
drop table t1;
#
# Bug #17754 Improper handling of removal of partitioning in ALTER TABLE
# Also added a number of general test cases in the same area
#
create table t1 (a int)
engine=ndb
partition by key(a)
(partition p0, partition p1);
show create table t1;
alter table t1 engine=heap;
show create table t1;
alter table t1 engine=ndb;
show create table t1;
alter table t1 engine=heap remove partitioning;
show create table t1;
alter table t1 engine=ndb
partition by key(a)
(partition p0, partition p1 engine = ndb);
show create table t1;
alter table t1
partition by key (a)
(partition p0 engine=ndb, partition p1 engine=ndb);
show create table t1;
alter table t1 remove partitioning;
show create table t1;
--error ER_MIX_HANDLER_ERROR
alter table t1
partition by key(a)
(partition p0 engine=ndb, partition p1);
alter table t1
engine=ndb
partition by key(a)
(partition p0 engine=ndb, partition p1 engine = ndb);
show create table t1;
drop table t1;
#
# BUG 16810 Out of memory when coalesce partition
#
......
......@@ -409,6 +409,96 @@ alter table t1 add partition (partition x3 values in (30));
drop table t1;
#
# Bug #17754 Change to explicit removal of partitioning scheme
# Also added a number of tests to ensure that proper engine is
# choosen in all kinds of scenarios.
#
create table t1 (a int)
partition by key(a)
partitions 2
(partition p0 engine=myisam, partition p1 engine=myisam);
show create table t1;
alter table t1;
show create table t1;
alter table t1 engine=myisam;
show create table t1;
alter table t1 engine=heap;
show create table t1;
alter table t1 remove partitioning;
show create table t1;
drop table t1;
create table t1 (a int)
engine=myisam
partition by key(a)
partitions 2
(partition p0 engine=myisam, partition p1 engine=myisam);
show create table t1;
alter table t1 add column b int remove partitioning;
show create table t1;
alter table t1
engine=myisam
partition by key(a)
(partition p0 engine=myisam, partition p1);
show create table t1;
alter table t1
engine=heap
partition by key(a)
(partition p0, partition p1 engine=heap);
show create table t1;
alter table t1 engine=myisam, add column c int remove partitioning;
show create table t1;
alter table t1
engine=heap
partition by key (a)
(partition p0, partition p1);
show create table t1;
alter table t1
partition by key (a)
(partition p0, partition p1);
show create table t1;
alter table t1
engine=heap
partition by key (a)
(partition p0, partition p1);
show create table t1;
--error ER_MIX_HANDLER_ERROR
alter table t1
partition by key(a)
(partition p0, partition p1 engine=heap);
--error ER_MIX_HANDLER_ERROR
alter table t1
partition by key(a)
(partition p0 engine=heap, partition p1);
--error ER_MIX_HANDLER_ERROR
alter table t1
engine=heap
partition by key (a)
(partition p0 engine=heap, partition p1 engine=myisam);
--error ER_MIX_HANDLER_ERROR
alter table t1
partition by key (a)
(partition p0 engine=heap, partition p1 engine=myisam);
drop table t1;
# Bug #17432: Partition functions containing NULL values should return
# LONGLONG_MIN
#
......
......@@ -391,6 +391,7 @@ static SYMBOL symbols[] = {
{ "PARSER", SYM(PARSER_SYM)},
{ "PARTIAL", SYM(PARTIAL)},
{ "PARTITION", SYM(PARTITION_SYM)},
{ "PARTITIONING", SYM(PARTITIONING_SYM)},
{ "PARTITIONS", SYM(PARTITIONS_SYM)},
{ "PASSWORD", SYM(PASSWORD)},
{ "PHASE", SYM(PHASE_SYM)},
......@@ -428,6 +429,7 @@ static SYMBOL symbols[] = {
{ "RELAY_THREAD", SYM(RELAY_THREAD)},
{ "RELEASE", SYM(RELEASE_SYM)},
{ "RELOAD", SYM(RELOAD)},
{ "REMOVE", SYM(REMOVE_SYM)},
{ "RENAME", SYM(RENAME)},
{ "REORGANIZE", SYM(REORGANIZE_SYM)},
{ "REPAIR", SYM(REPAIR)},
......
......@@ -705,6 +705,7 @@ typedef class st_select_lex SELECT_LEX;
#define ALTER_ANALYZE_PARTITION (1L << 22)
#define ALTER_CHECK_PARTITION (1L << 23)
#define ALTER_REPAIR_PARTITION (1L << 24)
#define ALTER_REMOVE_PARTITIONING (1L << 25)
typedef struct st_alter_info
{
......
......@@ -3816,6 +3816,42 @@ bool mysql_unpack_partition(THD *thd, const uchar *part_buf,
}
/*
Set engine type on all partition element objects
SYNOPSIS
set_engine_all_partitions()
part_info Partition info
engine_type Handlerton reference of engine
RETURN VALUES
NONE
*/
static
void
set_engine_all_partitions(partition_info *part_info,
handlerton *engine_type)
{
uint i= 0;
List_iterator<partition_element> part_it(part_info->partitions);
do
{
partition_element *part_elem= part_it++;
part_elem->engine_type= engine_type;
if (part_info->is_sub_partitioned())
{
List_iterator<partition_element> sub_it(part_elem->subpartitions);
uint j= 0;
do
{
partition_element *sub_elem= sub_it++;
sub_elem->engine_type= engine_type;
} while (++j < part_info->no_subparts);
}
} while (++i < part_info->no_parts);
}
/*
SYNOPSIS
fast_alter_partition_error_handler()
......@@ -3918,17 +3954,34 @@ static bool check_engine_condition(partition_element *p_elem,
handlerton **engine_type,
bool *first)
{
DBUG_ENTER("check_engine_condition");
DBUG_PRINT("enter", ("def_eng = %u, first = %u", default_engine, *first));
if (*engine_type)
DBUG_PRINT("info", ("engine_type = %s", (*engine_type)->name));
else
DBUG_PRINT("info", ("engine_type = NULL"));
if (*first && default_engine)
{
*engine_type= p_elem->engine_type;
if (*engine_type)
DBUG_PRINT("info", ("engine_type changed to = %s", (*engine_type)->name));
else
DBUG_PRINT("info", ("engine_type changed to = NULL"));
}
*first= FALSE;
if ((!default_engine &&
(p_elem->engine_type != *engine_type &&
!p_elem->engine_type)) ||
(p_elem->engine_type != (*engine_type) &&
p_elem->engine_type)) ||
(default_engine &&
p_elem->engine_type != *engine_type))
return TRUE;
p_elem->engine_type != (*engine_type)))
{
DBUG_RETURN(TRUE);
}
else
return FALSE;
{
DBUG_RETURN(FALSE);
}
}
/*
......@@ -3965,8 +4018,8 @@ static bool check_native_partitioned(HA_CREATE_INFO *create_info,bool *ret_val,
uint no_parts= part_info->partitions.elements;
DBUG_ENTER("check_native_partitioned");
default_engine= (create_info->used_fields | HA_CREATE_USED_ENGINE) ?
TRUE : FALSE;
default_engine= (create_info->used_fields & HA_CREATE_USED_ENGINE) ?
FALSE : TRUE;
DBUG_PRINT("info", ("engine_type = %u, default = %u",
ha_legacy_type(engine_type),
default_engine));
......@@ -4025,6 +4078,7 @@ static bool check_native_partitioned(HA_CREATE_INFO *create_info,bool *ret_val,
Mixed engines not yet supported but when supported it will need
the partition handler
*/
my_error(ER_MIX_HANDLER_ERROR, MYF(0));
*ret_val= FALSE;
DBUG_RETURN(TRUE);
}
......@@ -4803,7 +4857,7 @@ the generated partition syntax in a correct manner.
Case IIa:
There was a partitioning before and there is no new one defined.
Also the user has not specified an explicit engine to use.
Also the user has not specified to remove partitioning explicitly.
We use the old partitioning also for the new table. We do this
by assigning the partition_info from the table loaded in
......@@ -4812,12 +4866,11 @@ the generated partition syntax in a correct manner.
Case IIb:
There was a partitioning before and there is no new one defined.
The user has specified an explicit engine to use.
The user has specified explicitly to remove partitioning
Since the user has specified an explicit engine to use we override
the old partitioning info and create a new table using the specified
engine. This is the reason for the extra check if old and new engine
is equal.
Since the user has specified explicitly to remove partitioning
we override the old partitioning info and create a new table using
the specified engine.
In this case the partition also is changed.
Case III:
......@@ -4840,12 +4893,41 @@ the generated partition syntax in a correct manner.
*/
if (table->part_info)
{
if (!thd->lex->part_info &&
create_info->db_type == old_db_type)
if (thd->lex->alter_info.flags & ALTER_REMOVE_PARTITIONING)
{
DBUG_PRINT("info", ("Remove partitioning"));
if (!(thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE))
{
DBUG_PRINT("info", ("No explicit engine used"));
create_info->db_type= table->part_info->default_engine_type;
}
DBUG_PRINT("info", ("New engine type = %s",
create_info->db_type->name));
thd->lex->part_info= NULL;
*partition_changed= TRUE;
}
else if (!thd->lex->part_info)
{
/*
Retain partitioning but possibly with a new storage engine
beneath.
*/
thd->lex->part_info= table->part_info;
if (thd->lex->create_info.used_fields & HA_CREATE_USED_ENGINE &&
create_info->db_type != table->part_info->default_engine_type)
{
/*
Make sure change of engine happens to all partitions.
*/
set_engine_all_partitions(thd->lex->part_info, create_info->db_type);
*partition_changed= TRUE;
}
}
}
if (thd->lex->part_info)
{
partition_info *part_info= thd->lex->part_info;
bool is_native_partitioned= FALSE;
/*
Need to cater for engine types that can handle partition without
using the partition handler.
......@@ -4853,22 +4935,8 @@ the generated partition syntax in a correct manner.
if (thd->lex->part_info != table->part_info)
*partition_changed= TRUE;
if (create_info->db_type == &partition_hton)
{
if (table->part_info)
{
thd->lex->part_info->default_engine_type=
table->part_info->default_engine_type;
}
part_info->default_engine_type= table->part_info->default_engine_type;
else
{
thd->lex->part_info->default_engine_type=
ha_checktype(thd, DB_TYPE_DEFAULT, FALSE, FALSE);
}
}
else
{
bool is_native_partitioned= FALSE;
partition_info *part_info= thd->lex->part_info;
part_info->default_engine_type= create_info->db_type;
if (check_native_partitioned(create_info, &is_native_partitioned,
part_info, thd))
......@@ -4880,8 +4948,7 @@ the generated partition syntax in a correct manner.
DBUG_ASSERT(create_info->db_type != &default_hton);
create_info->db_type= &partition_hton;
}
}
DBUG_PRINT("info", ("default_db_type = %s",
DBUG_PRINT("info", ("default_engine_type = %s",
thd->lex->part_info->default_engine_type->name));
}
}
......
......@@ -2053,6 +2053,7 @@ bool mysql_create_table_internal(THD *thd,
DBUG_RETURN(TRUE);
}
file->set_auto_partitions(part_info);
part_info->default_engine_type= create_info->db_type;
}
if (part_info)
{
......
......@@ -495,6 +495,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token PARSER_SYM
%token PARTIAL
%token PARTITION_SYM
%token PARTITIONING_SYM
%token PARTITIONS_SYM
%token PASSWORD
%token PARAM_MARKER
......@@ -537,6 +538,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
%token RELAY_THREAD
%token RELEASE_SYM
%token RELOAD
%token REMOVE_SYM
%token RENAME
%token REORGANIZE_SYM
%token REPAIR
......@@ -4908,6 +4910,9 @@ alter_commands:
| IMPORT TABLESPACE { Lex->alter_info.tablespace_op= IMPORT_TABLESPACE; }
| alter_list
opt_partitioning
| alter_list
remove_partitioning
| remove_partitioning
| partitioning
/*
This part was added for release 5.1 by Mikael Ronström.
......@@ -4973,6 +4978,13 @@ alter_commands:
| reorg_partition_rule
;
remove_partitioning:
REMOVE_SYM PARTITIONING_SYM
{
Lex->alter_info.flags|= ALTER_REMOVE_PARTITIONING;
}
;
all_or_alt_part_name_list:
ALL
{
......@@ -9326,6 +9338,7 @@ keyword:
| PARTITION_SYM {}
| PLUGIN_SYM {}
| PREPARE_SYM {}
| REMOVE_SYM {}
| REPAIR {}
| RESET_SYM {}
| RESTORE_SYM {}
......@@ -9500,6 +9513,7 @@ keyword_sp:
| ONE_SYM {}
| PACK_KEYS_SYM {}
| PARTIAL {}
| PARTITIONING_SYM {}
| PARTITIONS_SYM {}
| PASSWORD {}
| PHASE_SYM {}
......
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