Skip to content

Commit b4fde50

Browse files
committed
MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION
The partitioning error handling code was looking at thd->lex->alter_info.partition_flags in non-alter-table cases, in which cases the value is stale and contains whatever was set by any earlier ALTER TABLE. This could cause the wrong error code to be generated, which then in some cases can cause replication to break with "different errorcode" error. Signed-off-by: Kristian Nielsen <knielsen@knielsen-hq.org>
1 parent 5a3a161 commit b4fde50

File tree

7 files changed

+116
-1
lines changed

7 files changed

+116
-1
lines changed

mysql-test/suite/rpl/include/rpl_partition.inc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,38 @@ SELECT * FROM test.regular_tbl ORDER BY fkid LIMIT 2;
9595
--replace_column 2 date-time 3 USER 4 UUID
9696
SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2;
9797

98+
99+
--echo *** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION
100+
--connection master
101+
eval CREATE TABLE t1 (a INT)
102+
ENGINE=$engine_type
103+
PARTITION BY LIST(a) (
104+
PARTITION p0 VALUES IN (9, NULL),
105+
PARTITION p1 VALUES IN (8, 2, 7),
106+
PARTITION p2 VALUES IN (6, 4, 5),
107+
PARTITION p3 VALUES IN (3, 1, 0)
108+
);
109+
ALTER TABLE t1 DROP PARTITION p0;
110+
111+
# This failed statement leaves ALTER_PARTITION_TRUNCATE set in
112+
# thd->lex->alter_info.partition_flags
113+
--error ER_NO_SUCH_TABLE
114+
ALTER TABLE non_existent TRUNCATE PARTITION p1,p2;
115+
116+
# The bug was that the code would wrongly look at the (now stale) value of
117+
# thd->lex->alter_info.partition_flags and give the wrong error code
118+
# ER_WRONG_PARTITION_NAME.
119+
--error ER_NO_PARTITION_FOR_GIVEN_VALUE
120+
INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9);
121+
122+
--sync_slave_with_master
123+
124+
98125
###### CLEAN UP SECTION ##############
99126

100127
connection master;
101128
DROP PROCEDURE test.proc_norm;
102129
DROP PROCEDURE test.proc_byrange;
103130
DROP TABLE test.regular_tbl;
104131
DROP TABLE test.byrange_tbl;
132+
DROP TABLE test.t1;

mysql-test/suite/rpl/r/rpl_partition_archive.result

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2;
140140
id dt user uuidf fkid filler
141141
1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL
142142
2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL
143+
*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION
144+
connection master;
145+
CREATE TABLE t1 (a INT)
146+
ENGINE='Archive'
147+
PARTITION BY LIST(a) (
148+
PARTITION p0 VALUES IN (9, NULL),
149+
PARTITION p1 VALUES IN (8, 2, 7),
150+
PARTITION p2 VALUES IN (6, 4, 5),
151+
PARTITION p3 VALUES IN (3, 1, 0)
152+
);
153+
ALTER TABLE t1 DROP PARTITION p0;
154+
ALTER TABLE non_existent TRUNCATE PARTITION p1,p2;
155+
ERROR 42S02: Table 'test.non_existent' doesn't exist
156+
INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9);
157+
ERROR HY000: Table has no partition for value 9
158+
connection slave;
159+
connection master;
143160
DROP PROCEDURE test.proc_norm;
144161
DROP PROCEDURE test.proc_byrange;
145162
DROP TABLE test.regular_tbl;
146163
DROP TABLE test.byrange_tbl;
164+
DROP TABLE test.t1;
147165
include/rpl_end.inc

mysql-test/suite/rpl/r/rpl_partition_innodb.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2;
142142
id dt user uuidf fkid filler
143143
1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL
144144
2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL
145+
*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION
146+
connection master;
147+
CREATE TABLE t1 (a INT)
148+
ENGINE='InnoDB'
149+
PARTITION BY LIST(a) (
150+
PARTITION p0 VALUES IN (9, NULL),
151+
PARTITION p1 VALUES IN (8, 2, 7),
152+
PARTITION p2 VALUES IN (6, 4, 5),
153+
PARTITION p3 VALUES IN (3, 1, 0)
154+
);
155+
ALTER TABLE t1 DROP PARTITION p0;
156+
ALTER TABLE non_existent TRUNCATE PARTITION p1,p2;
157+
ERROR 42S02: Table 'test.non_existent' doesn't exist
158+
INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9);
159+
ERROR HY000: Table has no partition for value 9
160+
connection slave;
145161
connection master;
146162
DROP PROCEDURE test.proc_norm;
147163
DROP PROCEDURE test.proc_byrange;
148164
DROP TABLE test.regular_tbl;
149165
DROP TABLE test.byrange_tbl;
166+
DROP TABLE test.t1;
150167
include/rpl_end.inc

mysql-test/suite/rpl/r/rpl_partition_memory.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2;
142142
id dt user uuidf fkid filler
143143
1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL
144144
2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL
145+
*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION
146+
connection master;
147+
CREATE TABLE t1 (a INT)
148+
ENGINE='Memory'
149+
PARTITION BY LIST(a) (
150+
PARTITION p0 VALUES IN (9, NULL),
151+
PARTITION p1 VALUES IN (8, 2, 7),
152+
PARTITION p2 VALUES IN (6, 4, 5),
153+
PARTITION p3 VALUES IN (3, 1, 0)
154+
);
155+
ALTER TABLE t1 DROP PARTITION p0;
156+
ALTER TABLE non_existent TRUNCATE PARTITION p1,p2;
157+
ERROR 42S02: Table 'test.non_existent' doesn't exist
158+
INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9);
159+
ERROR HY000: Table has no partition for value 9
160+
connection slave;
145161
connection master;
146162
DROP PROCEDURE test.proc_norm;
147163
DROP PROCEDURE test.proc_byrange;
148164
DROP TABLE test.regular_tbl;
149165
DROP TABLE test.byrange_tbl;
166+
DROP TABLE test.t1;
150167
include/rpl_end.inc

mysql-test/suite/rpl/r/rpl_partition_myisam.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2;
142142
id dt user uuidf fkid filler
143143
1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL
144144
2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL
145+
*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION
146+
connection master;
147+
CREATE TABLE t1 (a INT)
148+
ENGINE='MyISAM'
149+
PARTITION BY LIST(a) (
150+
PARTITION p0 VALUES IN (9, NULL),
151+
PARTITION p1 VALUES IN (8, 2, 7),
152+
PARTITION p2 VALUES IN (6, 4, 5),
153+
PARTITION p3 VALUES IN (3, 1, 0)
154+
);
155+
ALTER TABLE t1 DROP PARTITION p0;
156+
ALTER TABLE non_existent TRUNCATE PARTITION p1,p2;
157+
ERROR 42S02: Table 'test.non_existent' doesn't exist
158+
INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9);
159+
ERROR HY000: Table has no partition for value 9
160+
connection slave;
145161
connection master;
146162
DROP PROCEDURE test.proc_norm;
147163
DROP PROCEDURE test.proc_byrange;
148164
DROP TABLE test.regular_tbl;
149165
DROP TABLE test.byrange_tbl;
166+
DROP TABLE test.t1;
150167
include/rpl_end.inc

sql/ha_partition.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10143,7 +10143,8 @@ void ha_partition::print_error(int error, myf errflag)
1014310143

1014410144
/* Should probably look for my own errors first */
1014510145
if ((error == HA_ERR_NO_PARTITION_FOUND) &&
10146-
! (thd->lex->alter_info.partition_flags & ALTER_PARTITION_TRUNCATE))
10146+
! (thd->lex->sql_command == SQLCOM_ALTER_TABLE &&
10147+
(thd->lex->alter_info.partition_flags & ALTER_PARTITION_TRUNCATE)))
1014710148
{
1014810149
m_part_info->print_no_partition_found(table, errflag);
1014910150
DBUG_VOID_RETURN;

storage/tokudb/mysql-test/rpl/r/rpl_partition_tokudb.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,26 @@ SELECT * FROM test.regular_tbl ORDER BY fkid DESC LIMIT 2;
142142
id dt user uuidf fkid filler
143143
1 date-time USER UUID 300 Partitioned table! Going to test replication for MySQL
144144
2 date-time USER UUID 299 Partitioned table! Going to test replication for MySQL
145+
*** MDEV-5798: Wrong errorcode for missing partition after TRUNCATE PARTITION
146+
connection master;
147+
CREATE TABLE t1 (a INT)
148+
ENGINE=TokuDB;
149+
PARTITION BY LIST(a) (
150+
PARTITION p0 VALUES IN (9, NULL),
151+
PARTITION p1 VALUES IN (8, 2, 7),
152+
PARTITION p2 VALUES IN (6, 4, 5),
153+
PARTITION p3 VALUES IN (3, 1, 0)
154+
);
155+
ALTER TABLE t1 DROP PARTITION p0;
156+
ALTER TABLE non_existent TRUNCATE PARTITION p1,p2;
157+
ERROR 42S02: Table 'test.non_existent' doesn't exist
158+
INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9);
159+
ERROR HY000: Table has no partition for value 9
160+
connection slave;
145161
connection master;
146162
DROP PROCEDURE test.proc_norm;
147163
DROP PROCEDURE test.proc_byrange;
148164
DROP TABLE test.regular_tbl;
149165
DROP TABLE test.byrange_tbl;
166+
DROP TABLE test.t1;
150167
include/rpl_end.inc

0 commit comments

Comments
 (0)