BUG#18618561: FAILED ALTER TABLE ENGINE CHANGE WITH PARTITIONS
CORRUPTS FRM Analysis: --------- ALTER TABLE on a partitioned table resulted in the wrong engine being written into the table's FRM file and displayed in SHOW CREATE TABLE. The prep_alter_part_table() modifies the partition_info object for TABLE instance representing the old version of table. If the ALTER TABLE ENGINE statement fails, the partition_info object for the TABLE contains the altered storage engine name. The SHOW CREATE TABLE uses the TABLE object to display the table information, hence displays incorrect storage engine for the table. Also a subsequent successful ALTER TABLE operation will write the incorrect engine information into the FRM file. Fix: --- A copy of the partition_info object is created before modification so that any changes would not cause the the original partition_info object to be modified if the ALTER TABLE fails.(Backported part of the code provided as fix for bug#14156617 in mysql-5.6.6).
This commit is contained in:
parent
01fd5d0d0e
commit
24756e8e3f
@ -126,3 +126,29 @@ select count(*) from t1;
|
||||
count(*)
|
||||
100
|
||||
drop table t1;
|
||||
#
|
||||
#BUG 18618561: FAILED ALTER TABLE ENGINE CHANGE WITH PARTITIONS
|
||||
# CORRUPTS FRM
|
||||
CREATE TABLE t1 (fld1 INT PRIMARY KEY) ENGINE= MYISAM PARTITION BY HASH(fld1)
|
||||
PARTITIONS 5;
|
||||
SHOW CREATE TABLE t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`fld1` int(11) NOT NULL,
|
||||
PRIMARY KEY (`fld1`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
/*!50100 PARTITION BY HASH (fld1)
|
||||
PARTITIONS 5 */
|
||||
ALTER TABLE t1 ENGINE= ARCHIVE;
|
||||
ERROR HY000: Can't create table 'test.#sql-temporary' (errno: 1)
|
||||
#After the patch, the ENGINE is correctly displayed as MyISAM
|
||||
SHOW CREATE TABLE t1;
|
||||
Table Create Table
|
||||
t1 CREATE TABLE `t1` (
|
||||
`fld1` int(11) NOT NULL,
|
||||
PRIMARY KEY (`fld1`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||
/*!50100 PARTITION BY HASH (fld1)
|
||||
PARTITIONS 5 */
|
||||
#Cleanup.
|
||||
DROP TABLE t1;
|
||||
|
@ -126,3 +126,21 @@ show create table t1;
|
||||
select count(*) from t1;
|
||||
drop table t1;
|
||||
|
||||
|
||||
--echo #
|
||||
--echo #BUG 18618561: FAILED ALTER TABLE ENGINE CHANGE WITH PARTITIONS
|
||||
--echo # CORRUPTS FRM
|
||||
|
||||
CREATE TABLE t1 (fld1 INT PRIMARY KEY) ENGINE= MYISAM PARTITION BY HASH(fld1)
|
||||
PARTITIONS 5;
|
||||
SHOW CREATE TABLE t1;
|
||||
|
||||
--replace_regex /#sql-[0-9a-f_]*/#sql-temporary/
|
||||
--error ER_CANT_CREATE_TABLE
|
||||
ALTER TABLE t1 ENGINE= ARCHIVE;
|
||||
|
||||
--echo #After the patch, the ENGINE is correctly displayed as MyISAM
|
||||
SHOW CREATE TABLE t1;
|
||||
|
||||
--echo #Cleanup.
|
||||
DROP TABLE t1;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
/* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -5573,7 +5573,9 @@ the generated partition syntax in a correct manner.
|
||||
There was no partitioning before and no partitioning defined.
|
||||
Obviously no work needed.
|
||||
*/
|
||||
if (table->part_info)
|
||||
partition_info *tab_part_info= table->part_info;
|
||||
|
||||
if (tab_part_info)
|
||||
{
|
||||
if (alter_info->flags & ALTER_REMOVE_PARTITIONING)
|
||||
{
|
||||
@ -5581,7 +5583,7 @@ the generated partition syntax in a correct manner.
|
||||
if (!(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;
|
||||
create_info->db_type= tab_part_info->default_engine_type;
|
||||
}
|
||||
DBUG_PRINT("info", ("New engine type: %s",
|
||||
ha_resolve_storage_engine_name(create_info->db_type)));
|
||||
@ -5593,16 +5595,20 @@ the generated partition syntax in a correct manner.
|
||||
/*
|
||||
Retain partitioning but possibly with a new storage engine
|
||||
beneath.
|
||||
|
||||
Create a copy of TABLE::part_info to be able to modify it freely.
|
||||
*/
|
||||
thd->work_part_info= table->part_info;
|
||||
if (!(tab_part_info= tab_part_info->get_clone()))
|
||||
DBUG_RETURN(TRUE);
|
||||
thd->work_part_info= tab_part_info;
|
||||
if (create_info->used_fields & HA_CREATE_USED_ENGINE &&
|
||||
create_info->db_type != table->part_info->default_engine_type)
|
||||
create_info->db_type != tab_part_info->default_engine_type)
|
||||
{
|
||||
/*
|
||||
Make sure change of engine happens to all partitions.
|
||||
*/
|
||||
DBUG_PRINT("info", ("partition changed"));
|
||||
if (table->part_info->is_auto_partitioned)
|
||||
if (tab_part_info->is_auto_partitioned)
|
||||
{
|
||||
/*
|
||||
If the user originally didn't specify partitioning to be
|
||||
@ -5630,7 +5636,7 @@ the generated partition syntax in a correct manner.
|
||||
Need to cater for engine types that can handle partition without
|
||||
using the partition handler.
|
||||
*/
|
||||
if (part_info != table->part_info)
|
||||
if (part_info != tab_part_info)
|
||||
{
|
||||
if (part_info->fix_parser_data(thd))
|
||||
{
|
||||
@ -5658,8 +5664,8 @@ the generated partition syntax in a correct manner.
|
||||
part_info->default_engine_type= create_info->db_type;
|
||||
else
|
||||
{
|
||||
if (table->part_info)
|
||||
part_info->default_engine_type= table->part_info->default_engine_type;
|
||||
if (tab_part_info)
|
||||
part_info->default_engine_type= tab_part_info->default_engine_type;
|
||||
else
|
||||
part_info->default_engine_type= create_info->db_type;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user