Commit 07e9a6dc authored by Mattias Jonsson's avatar Mattias Jonsson
Browse files

Bug#20129: ALTER TABLE ... REPAIR PARTITION ... complains that

partition is corrupt

The main problem was that ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR
PARTITION took another code path (over mysql_alter_table instead of
mysql_admin_table) which differs in two ways:
1) alter table opens the tables in a different way than admin tables do
   resulting in returning with error before it tried the command
2) alter table does not start to send any diagnostic rows to the client
   which the lower admin functions continue to use -> resulting in
   assertion crash

The fix:
Remapped ALTER TABLE t ANALYZE/CHECK/OPTIMIZE/REPAIR PARTITION to use
the same code path as ANALYZE/CHECK/OPTIMIZE/REPAIR TABLE t.
Adding check in mysql_admin_table to setup the partition list for
which partitions that should be used.


Partitioned tables will still not work with
REPAIR TABLE/PARTITION USE_FRM, since that requires moving partitions
to tables, REPAIR TABLE t USE_FRM, and check that the data still
fulfills the partitioning function and then move the table back to
being a partition.

NOTE: I have removed the following functions from the handler
interface:
analyze_partitions, check_partitions, optimize_partitions,
repair_partitions
Since they are not longer needed.
THIS ALTERS THE STORAGE ENGINE API
parent 44a16259
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -484,6 +484,7 @@ c1
handler t1 close;
read the result from the other connection
Table	Op	Msg_type	Msg_text
test.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
test.t1	optimize	status	OK
proceed with the normal connection
drop table t1;
@@ -698,6 +699,7 @@ handler a2 read a first;
a
optimize table t1;
Table	Op	Msg_type	Msg_text
test.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
test.t1	optimize	status	OK
handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
+4 −0
Original line number Diff line number Diff line
@@ -166,6 +166,7 @@ level id parent_id
1	1007	101
optimize table t1;
Table	Op	Msg_type	Msg_text
test.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
test.t1	optimize	status	OK
show keys from t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment
@@ -190,6 +191,7 @@ create table t1 (a int) engine=innodb;
insert into t1 values (1), (2);
optimize table t1;
Table	Op	Msg_type	Msg_text
test.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
test.t1	optimize	status	OK
delete from t1 where a = 1;
select * from t1;
@@ -738,6 +740,7 @@ world 2
hello	1
optimize table t1;
Table	Op	Msg_type	Msg_text
test.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
test.t1	optimize	status	OK
show keys from t1;
Table	Non_unique	Key_name	Seq_in_index	Column_name	Collation	Cardinality	Sub_part	Packed	Null	Index_type	Comment
@@ -3109,6 +3112,7 @@ BEGIN;
INSERT INTO t1 VALUES (1);
OPTIMIZE TABLE t1;
Table	Op	Msg_type	Msg_text
test.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
test.t1	optimize	status	OK
DROP TABLE t1;
CREATE TABLE t1 (id int PRIMARY KEY, f int NOT NULL, INDEX(f)) ENGINE=InnoDB;
+1 −0
Original line number Diff line number Diff line
@@ -577,6 +577,7 @@ id select_type table type possible_keys key key_len ref rows Extra
INSERT INTO t2 SELECT * FROM t1;
OPTIMIZE TABLE t2;
Table	Op	Msg_type	Msg_text
test.t2	optimize	note	Table does not support optimize, doing recreate + analyze instead
test.t2	optimize	status	OK
EXPLAIN SELECT COUNT(*) FROM t2 WHERE stat_id IN (1,3) AND acct_id=785;
id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
+14 −6
Original line number Diff line number Diff line
@@ -538,7 +538,7 @@ PARTITION BY LIST (a)
(PARTITION x1 VALUES IN (10), PARTITION x2 VALUES IN (20));
analyze table t1;
Table	Op	Msg_type	Msg_text
test.t1	analyze	note	The storage engine for the table doesn't support analyze
test.t1	analyze	status	OK
drop table t1;
create table t1
(a int)
@@ -1239,7 +1239,11 @@ SHOW TABLE STATUS;
Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
t1	MyISAM	10	Fixed	1	14	14	0	0	7	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
ALTER TABLE t1 OPTIMIZE PARTITION p0;
ERROR 42000: The storage engine for the table doesn't support optimize partition
Table	Op	Msg_type	Msg_text
test.t1	optimize	status	OK
SHOW TABLE STATUS;
Name	Engine	Version	Row_format	Rows	Avg_row_length	Data_length	Max_data_length	Index_length	Data_free	Auto_increment	Create_time	Update_time	Check_time	Collation	Checksum	Create_options	Comment
t1	MyISAM	10	Fixed	1	7	7	0	1024	0	NULL	NULL	NULL	NULL	latin1_swedish_ci	NULL	partitioned	
DROP TABLE t1;
CREATE TABLE t1 (a int, index(a)) PARTITION BY KEY(a);
ALTER TABLE t1 DISABLE KEYS;
@@ -1499,13 +1503,17 @@ ERROR 42000: You have an error in your SQL syntax; check the manual that corresp
ALTER TABLE t1 ANALYZE PARTITION p1 EXTENDED;
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'EXTENDED' at line 1
ALTER TABLE t1 ANALYZE PARTITION p1;
ERROR 42000: The storage engine for the table doesn't support analyze partition
Table	Op	Msg_type	Msg_text
test.t1	analyze	status	OK
ALTER TABLE t1 CHECK PARTITION p1;
ERROR 42000: The storage engine for the table doesn't support check partition
Table	Op	Msg_type	Msg_text
test.t1	check	status	OK
ALTER TABLE t1 REPAIR PARTITION p1;
ERROR 42000: The storage engine for the table doesn't support repair partition
Table	Op	Msg_type	Msg_text
test.t1	repair	status	OK
ALTER TABLE t1 OPTIMIZE PARTITION p1;
ERROR 42000: The storage engine for the table doesn't support optimize partition
Table	Op	Msg_type	Msg_text
test.t1	optimize	status	OK
DROP TABLE t1;
CREATE TABLE t1 (s1 BIGINT UNSIGNED)
PARTITION BY RANGE (s1) (
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ a b
THE LION	13
optimize table t1;
Table	Op	Msg_type	Msg_text
test.t1	optimize	note	Table does not support optimize, doing recreate + analyze instead
test.t1	optimize	status	OK
select trigger_schema, trigger_name, event_object_schema,
event_object_table, action_statement from information_schema.triggers
Loading