pt-archiver不会迁移max(id)那条数据的问题

pt-archiver不会迁移max(id)那条数据的问题

严少安 Lv.6

To be is to be perceived.

  • 现象描述

pt-archiver迁移数据时,发现原表中总会留有一条数据,即max(id)那条数据,修正方案如下。

pt-archiver源码

1
2
3
4
5
6
7
8
9
10
11
if ( $o->get('safe-auto-increment')
&& $sel_stmt->{index}
&& scalar(@{$src->{info}->{keys}->{$sel_stmt->{index}}->{cols}}) == 1
&& $src->{info}->{is_autoinc}->{
$src->{info}->{keys}->{$sel_stmt->{index}}->{cols}->[0]
}
) {
my $col = $q->quote($sel_stmt->{scols}->[0]);
my ($val) = $dbh->selectrow_array("SELECT MAX($col) FROM $src->{db_tbl}");
$first_sql .= " AND ($col < " . $q->quote_val($val) . ")";
}

第 6348 行改为小于等于

1
2
3
4
5
6
7
8
9
10
11
6339    if ( $o->get('safe-auto-increment')
6340 && $sel_stmt->{index}
6341 && scalar(@{$src->{info}->{keys}->{$sel_stmt->{index}}->{cols}}) == 1
6342 && $src->{info}->{is_autoinc}->{
6343 $src->{info}->{keys}->{$sel_stmt->{index}}->{cols}->[0]
6344 }
6345 ) {
6346 my $col = $q->quote($sel_stmt->{scols}->[0]);
6347 my ($val) = $dbh->selectrow_array("SELECT MAX($col) FROM $src->{db_tbl}");
6348 $first_sql .= " AND ($col <= " . $q->quote_val($val) . ")";
6349 }

Reference

  • Title: pt-archiver不会迁移max(id)那条数据的问题
  • Author: 严少安
  • Created at: 2018-02-23 21:31:01
  • Updated at: 2018-02-23 21:31:01
  • Link: https://shawnyan.cn/2018/mysql/pt-archiver-maxid/
  • License: This work is licensed under CC BY-NC-SA 4.0.
if (hexo-config('comment.enable') == true && hexo-config('comment.system') != "") { if (hexo-config('comment.system') == "waline") { @require "./waline.styl" } else if (hexo-config('comment.system') == "gitalk") { @require "./gitalk.styl" } else if (hexo-config('comment.system') == "twikoo") { @require "./twikoo.styl" } } .comments-container display inline-block margin-top $spacing-unit width 100% #comment-anchor width 100% height 10px .comment-area-title width 100% margin 10px 0 font-size 1.38rem color var(--default-text-color) font-family 'Consolas', '宋体', sans-serif font-weight bold i color var(--default-text-color) +redefine-tablet() margin 5px 0 font-size 1.2rem
On this page