Skip to content

Commit a04a136

Browse files
Dmitry LenevDmitry Lenev
authored andcommitted
Merged recent changes from mysql-5.5-bugteam
into mysql-trunk-bugfixing tree.
2 parents 1fed48d + 41af8df commit a04a136

4 files changed

Lines changed: 114 additions & 2 deletions

File tree

mysql-test/r/partition_innodb.result

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,3 +489,31 @@ Warning 1265 Data truncated for column 'b' at row 1
489489
Error 1067 Invalid default value for 'b'
490490
SET SESSION sql_mode = @old_mode;
491491
DROP TABLE t1;
492+
#
493+
# Bug#57985 "ONLINE/FAST ALTER PARTITION can fail and leave the
494+
# table unusable".
495+
#
496+
DROP TABLE IF EXISTS t1;
497+
CREATE TABLE t1 (a bigint not null, b int not null, PRIMARY KEY (a))
498+
ENGINE = InnoDB PARTITION BY KEY(a) PARTITIONS 2;
499+
INSERT INTO t1 values (0,1), (1,2);
500+
# The below ALTER should fail. It should leave the
501+
# table in its original, non-corrupted, usable state.
502+
ALTER TABLE t1 ADD UNIQUE KEY (b);
503+
ERROR HY000: A UNIQUE INDEX must include all columns in the table's partitioning function
504+
# The below statements should succeed, as ALTER should
505+
# have left table intact.
506+
SHOW CREATE TABLE t1;
507+
Table Create Table
508+
t1 CREATE TABLE `t1` (
509+
`a` bigint(20) NOT NULL,
510+
`b` int(11) NOT NULL,
511+
PRIMARY KEY (`a`)
512+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
513+
/*!50100 PARTITION BY KEY (a)
514+
PARTITIONS 2 */
515+
SELECT * FROM t1;
516+
a b
517+
1 2
518+
0 1
519+
DROP TABLE t1;

mysql-test/t/partition_innodb.test

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,3 +569,24 @@ SET SESSION sql_mode = 'NO_ZERO_DATE';
569569
OPTIMIZE TABLE t1;
570570
SET SESSION sql_mode = @old_mode;
571571
DROP TABLE t1;
572+
573+
574+
--echo #
575+
--echo # Bug#57985 "ONLINE/FAST ALTER PARTITION can fail and leave the
576+
--echo # table unusable".
577+
--echo #
578+
--disable_warnings
579+
DROP TABLE IF EXISTS t1;
580+
--enable_warnings
581+
CREATE TABLE t1 (a bigint not null, b int not null, PRIMARY KEY (a))
582+
ENGINE = InnoDB PARTITION BY KEY(a) PARTITIONS 2;
583+
INSERT INTO t1 values (0,1), (1,2);
584+
--echo # The below ALTER should fail. It should leave the
585+
--echo # table in its original, non-corrupted, usable state.
586+
--error ER_UNIQUE_KEY_NEED_ALL_FIELDS_IN_PF
587+
ALTER TABLE t1 ADD UNIQUE KEY (b);
588+
--echo # The below statements should succeed, as ALTER should
589+
--echo # have left table intact.
590+
SHOW CREATE TABLE t1;
591+
SELECT * FROM t1;
592+
DROP TABLE t1;

sql/event_queue.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ Event_queue::get_top_for_execution_if_time(THD *thd,
568568
{
569569
bool ret= FALSE;
570570
*event_name= NULL;
571-
my_time_t last_executed;
572-
int status;
571+
my_time_t UNINIT_VAR(last_executed);
572+
int UNINIT_VAR(status);
573573
DBUG_ENTER("Event_queue::get_top_for_execution_if_time");
574574

575575
LOCK_QUEUE_DATA();

sql/sql_table.cc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4003,6 +4003,46 @@ void sp_prepare_create_field(THD *thd, Create_field *sql_field)
40034003
(void) prepare_blob_field(thd, sql_field);
40044004
}
40054005

4006+
4007+
/**
4008+
Auxiliary function which allows to check if freshly created .FRM
4009+
file for table can be opened.
4010+
4011+
@retval FALSE - Success.
4012+
@retval TRUE - Failure.
4013+
*/
4014+
4015+
static bool check_if_created_table_can_be_opened(THD *thd,
4016+
const char *path,
4017+
const char *db,
4018+
const char *table_name,
4019+
HA_CREATE_INFO *create_info,
4020+
handler *file)
4021+
{
4022+
TABLE table;
4023+
TABLE_SHARE share;
4024+
bool result;
4025+
4026+
/*
4027+
It is impossible to open definition of partitioned table without .par file.
4028+
*/
4029+
if (file->ha_create_handler_files(path, NULL, CHF_CREATE_FLAG, create_info))
4030+
return TRUE;
4031+
4032+
init_tmp_table_share(thd, &share, db, 0, table_name, path);
4033+
4034+
result= (open_table_def(thd, &share, 0) ||
4035+
open_table_from_share(thd, &share, "", 0, (uint) READ_ALL,
4036+
0, &table, TRUE));
4037+
if (! result)
4038+
(void) closefrm(&table, 0);
4039+
4040+
free_table_share(&share);
4041+
(void) file->ha_create_handler_files(path, NULL, CHF_DELETE_FLAG, create_info);
4042+
return result;
4043+
}
4044+
4045+
40064046
/*
40074047
Create a table
40084048
@@ -4429,6 +4469,29 @@ bool mysql_create_table_no_lock(THD *thd,
44294469

44304470
thd->thread_specific_used= TRUE;
44314471
}
4472+
#ifdef WITH_PARTITION_STORAGE_ENGINE
4473+
else if (part_info && create_info->frm_only)
4474+
{
4475+
/*
4476+
For partitioned tables we can't find some problems with table
4477+
until table is opened. Therefore in order to disallow creation
4478+
of corrupted tables we have to try to open table as the part
4479+
of its creation process.
4480+
In cases when both .FRM and SE part of table are created table
4481+
is implicitly open in ha_create_table() call.
4482+
In cases when we create .FRM without SE part we have to open
4483+
table explicitly.
4484+
*/
4485+
if (check_if_created_table_can_be_opened(thd, path, db, table_name,
4486+
create_info, file))
4487+
{
4488+
char frm_name[FN_REFLEN];
4489+
strxmov(frm_name, path, reg_ext, NullS);
4490+
(void) mysql_file_delete(key_file_frm, frm_name, MYF(0));
4491+
goto err;
4492+
}
4493+
}
4494+
#endif
44324495

44334496
error= FALSE;
44344497
err:

0 commit comments

Comments
 (0)