Bug #32084 | ALTER TABLE ADD PRIMARY KEY auto_increment breaks replication | ||
---|---|---|---|
Submitted: | 3 Nov 2007 23:14 | Modified: | 6 Nov 2007 11:49 |
Reporter: | Grigory Rubtsov | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Replication | Severity: | S3 (Non-critical) |
Version: | 5.1.22 | OS: | Any |
Assigned to: | Assigned Account | CPU Architecture: | Any |
[3 Nov 2007 23:14]
Grigory Rubtsov
[3 Nov 2007 23:15]
Grigory Rubtsov
config.ini is the same for master and slave: [NDBD DEFAULT] DataDir=/cluster NoOfReplicas=2 DataMemory=6M IndexMemory=3M RedoBuffer=3M TransactionBufferMemory=1M [NDB_MGMD] DataDir=/cluster HostName=localhost [NDBD] [NDBD] [MYSQLD]
[6 Nov 2007 11:49]
Tomas Ulin
so this is the same problem with e.g. myisam you have to make sure that the scan order is different on the master and slave (they are always in ndb) example of how to reproduce in myisam master> create table t1 (a int); master> insert into t1 values (1),(2),(3); master> reset master; slave> create table t1 (a int); slave> insert into t1 values (3),(2),(1); slave> start slave; master> alter table t1 add id int primary key auto_increment; master> select * from t1; +------+----+ | a | id | +------+----+ | 1 | 1 | | 2 | 2 | | 3 | 3 | +------+----+ 3 rows in set (0.00 sec) slave> select * from t1; +------+----+ | a | id | +------+----+ | 3 | 1 | | 2 | 2 | | 1 | 3 | +------+----+
[3 Dec 2007 22:39]
Lars Thalmann
REFINED PROBLEM DESCRIPTION --------------------------- The auto inc column on slave can get different initial values than the master SUGGESTED SOLUTIONS ------------------- 1. Prohibit "ALTER TABLE add auto increment column" when binlog is enabled. 2. Make sure that alter table assigns new numbers in a deterministic way. I think alternative 1 is probably best. Then the users will need to do the operation in two steps: 1. alter table add column (without auto inc columns) 2. change column to auto inc column