pt-online-schema-change makes duplicate rows in _t_new for UPDATE t set pk=0 where pk=1

Bug #1646713 reported by Nickolay Ihalainen
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
Fix Released
High
Carlos Salguero

Bug Description

Update trigger is not able to cover primary/unique key change.

CREATE TABLE `t` (
  `id` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB

mysql> select * from t;
+----+
| id |
+----+
| 1 |
+----+
1 row in set (0.00 sec)

mysql> update t set id=0 where id=1;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> select * from t;
+----+
| id |
+----+
| 0 |
+----+
1 row in set (0.00 sec)

mysql> select * from _t_new;
+----+------+
| id | c1 |
+----+------+
| 0 | NULL |
| 1 | NULL |

Expected just
mysql> select * from _t_new;
+----+------+
| id | c1 |
+----+------+
| 0 | NULL |

Changed in percona-toolkit:
status: New → Confirmed
Changed in percona-toolkit:
importance: Undecided → High
assignee: nobody → Carlos Salguero (carlos-salguero)
milestone: none → 2.2.21
Revision history for this message
DONGCHAN SUNG (sdchan1) wrote :

Hi~
---------------------------------------------------------
 +
 + my $upd_index_cols = join(" AND ", map {
 + my $new_col = $_;
 + my $old_col = $old_col_for{$new_col} || $new_col;
 + my $new_qcol = $q->quote($new_col);
 + my $old_qcol = $q->quote($old_col);
 + "OLD.$old_qcol <=> NEW.$new_qcol"
 + } @{$tbl_struct->{keys}->{$del_index}->{cols}} );
 +
     my $update_trigger
        = "CREATE TRIGGER `${prefix}_upd` AFTER UPDATE ON $orig_tbl->{name} "
        . "FOR EACH ROW "
 - . "REPLACE INTO $new_tbl->{name} ($qcols) VALUES ($new_vals)";
 + . "BEGIN "
 + . "DELETE IGNORE FROM $new_tbl->{name} WHERE !($upd_index_cols) AND $del_index_cols;"
 + . "REPLACE INTO $new_tbl->{name} ($qcols) VALUES ($new_vals);"
 + . "END ";
---------------------------------------------------------

Fixed version, you can check here. :-)
>> https://github.com/gywndi/percona-toolkit/commit/7c3c5c9a8e7bdc9fadf047757182f44d6aef4f53

Thanks.
Chan. (Kakaobank)

Changed in percona-toolkit:
milestone: 2.2.21 → 3.0.2
tags: added: pt94
Revision history for this message
Carlos Salguero (carlos-salguero) wrote :
Changed in percona-toolkit:
status: Confirmed → Fix Committed
Changed in percona-toolkit:
status: Fix Committed → Fix Released
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PT-399

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.