In the process of altering a big table with pt-online-schema-change, I updated the PRIMARY KEY of one record. When pt-online-schema-change reported it has successfully altered the table, I found the record that I have just updated still existed. It is because the update trigger pt-online-schema-change create replaces the new record into the new table. The test procedure is as follows:
- Create a table.
CREATE TABLE ord
(
id
int(11) NOT NULL AUTO_INCREMENT,
customer_id
int(11) DEFAULT NULL,
good_id
int(11) DEFAULT NULL,
create_time
datetime DEFAULT NULL,
datetime_lastchanged
datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id
)
) ENGINE=InnoDB;
- Insert 17000000+ rows into the table.
The first 20 records are as follows:
mysql> select * from ord limit 20;
±—±------------±--------±--------------------±---------------------+
| id | customer_id | good_id | create_time | datetime_lastchanged |
±—±------------±--------±--------------------±---------------------+
| 1 | 6 | 1 | 2015-06-15 14:46:03 | 2015-06-26 15:52:47 |
| 10 | 7 | 2 | 2015-06-15 14:46:14 | 2015-06-26 15:52:52 |
| 11 | 3 | 5 | 2015-06-15 14:14:05 | 2015-06-26 15:53:47 |
| 12 | 1 | 2 | 2015-06-26 16:40:54 | 2015-06-26 16:40:54 |
| 13 | 6 | 1 | 2015-06-15 14:46:03 | 2015-06-26 15:52:47 |
| 14 | 7 | 2 | 2015-06-15 14:46:14 | 2015-06-26 15:52:52 |
| 15 | 3 | 5 | 2015-06-15 14:14:05 | 2015-06-26 15:53:47 |
| 16 | 1 | 2 | 2015-06-26 16:40:54 | 2015-06-26 16:40:54 |
| 20 | 6 | 1 | 2015-06-15 14:46:03 | 2015-06-26 15:52:47 |
| 21 | 7 | 2 | 2015-06-15 14:46:14 | 2015-06-26 15:52:52 |
| 22 | 3 | 5 | 2015-06-15 14:14:05 | 2015-06-26 15:53:47 |
| 23 | 1 | 2 | 2015-06-26 16:40:54 | 2015-06-26 16:40:54 |
| 24 | 6 | 1 | 2015-06-15 14:46:03 | 2015-06-26 15:52:47 |
| 25 | 7 | 2 | 2015-06-15 14:46:14 | 2015-06-26 15:52:52 |
| 26 | 3 | 5 | 2015-06-15 14:14:05 | 2015-06-26 15:53:47 |
| 27 | 1 | 2 | 2015-06-26 16:40:54 | 2015-06-26 16:40:54 |
| 35 | 6 | 1 | 2015-06-15 14:46:03 | 2015-06-26 15:52:47 |
| 36 | 7 | 2 | 2015-06-15 14:46:14 | 2015-06-26 15:52:52 |
| 37 | 3 | 5 | 2015-06-15 14:14:05 | 2015-06-26 15:53:47 |
| 38 | 1 | 2 | 2015-06-26 16:40:54 | 2015-06-26 16:40:54 |
±—±------------±--------±--------------------±---------------------+
20 rows in set (0.00 sec)
- Altering the table with pt-online-schema-change.
[admin@CentOS6 ~]$ pt-online-schema-change u=root,p=pass,D=db1,t=ord --alter=“add name varchar(20)” --statistics --execute
No slaves found. See --recursion-method if host CentOS6.4study has slaves.
Not checking slave lag because no slaves were found and --check-slave-lag was not specified.
Operation, tries, wait:
copy_rows, 10, 0.25
create_triggers, 10, 1
drop_triggers, 10, 1
swap_tables, 10, 1
update_foreign_keys, 10, 1
Altering db1
.ord
…
Creating new table…
Created new table db1._ord_new OK.
Altering new table…
Altered db1
._ord_new
OK.
2015-08-10T10:35:59 Creating triggers…
2015-08-10T10:35:59 Created triggers OK.
2015-08-10T10:35:59 Copying approximately 16312164 rows…
Copying db1
.ord
: 8% 05:45 remain
##########################################################
#######pt-online-schema-change is still running!!!########
##########################################################
- When pt-online-schema-change is still running, update the PRIMARY KEY of one record.
mysql> update ord set id=5 where id=17235885;
Query OK, 1 row affected (0.80 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from ord where id=17235885;
Empty set (0.07 sec)
mysql> select * from ord where id=5;
±—±------------±--------±--------------------±---------------------+
| id | customer_id | good_id | create_time | datetime_lastchanged |
±—±------------±--------±--------------------±---------------------+
| 5 | 1 | 2 | 2015-06-26 16:40:54 | 2015-08-10 10:36:38 |
±—±------------±--------±--------------------±---------------------+
- When pt-online-schema-change reports it has successfully altered the table, I find the record id=17235885 still exists, and the record id=5 exists too.
mysql> select * from ord where id=17235885;
±---------±------------±--------±--------------------±---------------------±-----+
| id | customer_id | good_id | create_time | datetime_lastchanged | name |
±---------±------------±--------±--------------------±---------------------±-----+
| 17235885 | 1 | 2 | 2015-06-26 16:40:54 | 2015-08-10 10:36:38 | NULL |
±---------±------------±--------±--------------------±---------------------±-----+
1 row in set (0.03 sec)
mysql> select * from ord where id=5;
±—±------------±--------±--------------------±---------------------±-----+
| id | customer_id | good_id | create_time | datetime_lastchanged | name |
±—±------------±--------±--------------------±---------------------±-----+
| 5 | 1 | 2 | 2015-06-26 16:40:54 | 2015-08-10 10:36:38 | NULL |
±—±------------±--------±--------------------±---------------------±-----+
1 row in set (0.03 sec)
Because of this problem, I dare NOT use pt-online-schema-change because I cannot gurantee the application never updates PRIMARY KEY. Can anybody solve the problem and give me any help? Thank you very much, and I hope percona team can solve this problem completely.