Bug #71947 Unexpected change in error code on INSERT .. PARTITION causes replication abort
Submitted: 5 Mar 2014 18:55 Modified: 6 Mar 2014 5:18
Reporter: Elena Stepanova Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Partitions Severity:S3 (Non-critical)
Version:5.6, 5.7 OS:Any
Assigned to: CPU Architecture:Any

[5 Mar 2014 18:55] Elena Stepanova
Description:
In the provided test case, before I run INSERT, I execute a seemingly harmless, albeit useless, ALTER on a non-existent table, which expectedly fails with ER_NO_SUCH_TABLE.

But after that, the next INSERT on the existing table fails with ER_WRONG_PARTITION_NAME. It is expected to fail, but without the previous unrelated ALTER it fails with ER_NO_PARTITION_FOR_GIVEN_VALUE. 

It wouldn't be so bad, but the whole sequence is executed on a master, the failed ALTER isn't written to the binary log, but INSERT might be, for example if it's run on a non-transactional table. In this case INSERT is written with ER_WRONG_PARTITION_NAME, but on a slave it causes ER_NO_PARTITION_FOR_GIVEN_VALUE, and this discrepancy causes replication failure.

How to repeat:
--source include/have_partition.inc
--source include/master-slave.inc
--source include/have_binlog_format_statement.inc

CREATE TABLE IF NOT EXISTS t1 (a INT) 
ENGINE=MyISAM
PARTITION BY LIST(a) ( 
  PARTITION p0 VALUES IN (9, NULL), 
  PARTITION p1 VALUES IN (8, 2, 7), 
  PARTITION p2 VALUES IN (6, 4, 5), 
  PARTITION p3 VALUES IN (3, 1, 0) 
);
ALTER TABLE t1 DROP PARTITION p0;

####### Game changer
--error ER_NO_SUCH_TABLE
ALTER TABLE non_existent TRUNCATE PARTITION p1,p2;
#######

--error ER_NO_PARTITION_FOR_GIVEN_VALUE,ER_WRONG_PARTITION_NAME
INSERT INTO t1 PARTITION (p1,p2,p3) VALUES (0),(9);
SHOW WARNINGS;

--sync_slave_with_master
[6 Mar 2014 5:18] Umesh Shastry
Hello Elena,

Thank you for the bug report and test case.
Verified as described.

Thanks,
Umesh