From 602c1f0ea2cde9cc7344358fa18b3ce478c13b38 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Thu, 14 Jun 2018 14:15:20 -0300 Subject: [PATCH 1/2] PT-1570 pt-archiver fails to detect columns with the word GENERATED as part of the comment --- Changelog | 1 + bin/pt-archiver | 5 ++ lib/TableParser.pm | 2 +- t/lib/TableParser.t | 79 +++++++++++++++++++++++ t/lib/samples/generated_cols_comments.sql | 6 ++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 t/lib/samples/generated_cols_comments.sql diff --git a/Changelog b/Changelog index dde4a8c2..b2894c9b 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,6 @@ Changelog for Percona Toolkit + * Fixed bug PT-1570 : pt-archiver fails to detect columns with the word GENERATED as part of the comment * Fixed bug PT-1563 : Fixed pt-show-grants for MySQL 5.6 * Improvement PT-1562 : pt-mysql-summary: Fix mysqld command for Travis * Improvement PT-242 : (pt-stalk) Include SHOW SLAVE STATUS on 5.7 (Thanks Marcelo Altmann) diff --git a/bin/pt-archiver b/bin/pt-archiver index c4031df7..2954deee 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -6240,6 +6240,11 @@ sub main { . "$src->{db_tbl} does not have a PRIMARY KEY"; } + warn "===================================================================================================="; + warn Data::Dumper::Dumper($src); + warn "===================================================================================================="; + warn Data::Dumper::Dumper($dst); + warn "===================================================================================================="; if ( $dst && $o->get('check-columns') ) { my @not_in_src = grep { !$src->{info}->{is_col}->{$_} diff --git a/lib/TableParser.pm b/lib/TableParser.pm index 511c5c67..c2e3501f 100644 --- a/lib/TableParser.pm +++ b/lib/TableParser.pm @@ -220,7 +220,7 @@ sub remove_quoted_text { my ($string) = @_; $string =~ s/[^\\]`[^`]*[^\\]`//g; $string =~ s/[^\\]"[^"]*[^\\]"//g; - $string =~ s/[^\\]"[^"]*[^\\]"//g; + $string =~ s/[^\\]'[^']*[^\\]'//g; return $string; } diff --git a/t/lib/TableParser.t b/t/lib/TableParser.t index 235db7f8..57772ada 100644 --- a/t/lib/TableParser.t +++ b/t/lib/TableParser.t @@ -1188,6 +1188,85 @@ SKIP: { ) or die Data::Dumper::Dumper($tbl); } +# Test that the GENERATED word in a column comment doesn't make that column +# to be detected as a MySQL 5.7+ generated column. +$tbl = $tp->parse( load_file('t/lib/samples/generated_cols_comments.sql') ); +is_deeply( + $tbl, + { + charset => 'latin1', + clustered_key => 'PRIMARY', + col_posn => { + id => 0, + source => 1, + tso_id => 2 + }, + cols => [ + 'id', + 'source', + 'tso_id' + ], + defs => { + id => ' `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT \'The unique id of the audit record.\'', + source => ' `source` enum(\'val1\',\'val2\') NOT NULL COMMENT \'Transaction originator\'', + tso_id => ' `tso_id` int(11) unsigned NOT NULL DEFAULT \'0\' COMMENT \'An internally generated transaction.\'' + }, + engine => 'InnoDB', + is_autoinc => { + id => 1, + source => 0, + tso_id => 0 + }, + is_col => { + id => 1, + source => 1, + tso_id => 1 + }, + is_generated => {}, + is_nullable => {}, + is_numeric => { + id => 1, + tso_id => 1 + }, + keys => { + PRIMARY => { + col_prefixes => [ + undef + ], + colnames => '`id`', + cols => [ + 'id' + ], + ddl => 'PRIMARY KEY (`id`),', + is_col => { + id => 1 + }, + is_nullable => 0, + is_unique => 1, + name => 'PRIMARY', + type => 'BTREE' + } + }, + name => 't1', + non_generated_cols => [ + 'id', + 'source', + 'tso_id' + ], + null_cols => [], + numeric_cols => [ + 'id', + 'tso_id' + ], + type_for => { + id => 'int', + source => 'enum', + tso_id => 'int' + } + }, + 'Column having the word "generated" as part of the comment is OK', +) or diag Data::Dumper::Dumper($tbl); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/lib/samples/generated_cols_comments.sql b/t/lib/samples/generated_cols_comments.sql new file mode 100644 index 00000000..bfa7b405 --- /dev/null +++ b/t/lib/samples/generated_cols_comments.sql @@ -0,0 +1,6 @@ +CREATE TABLE `t1` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'The unique id of the audit record.', + `source` enum('val1','val2') NOT NULL COMMENT 'Transaction originator', + `tso_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'An internally generated transaction.', + PRIMARY KEY (`id`), +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COMMENT='some comment here generated' From ed4268836fcd0a504a7d3f70220798e77ef28612 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Thu, 14 Jun 2018 14:17:30 -0300 Subject: [PATCH 2/2] PT-1570 Removed debugging code --- bin/pt-archiver | 5 ----- 1 file changed, 5 deletions(-) diff --git a/bin/pt-archiver b/bin/pt-archiver index 2954deee..c4031df7 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -6240,11 +6240,6 @@ sub main { . "$src->{db_tbl} does not have a PRIMARY KEY"; } - warn "===================================================================================================="; - warn Data::Dumper::Dumper($src); - warn "===================================================================================================="; - warn Data::Dumper::Dumper($dst); - warn "===================================================================================================="; if ( $dst && $o->get('check-columns') ) { my @not_in_src = grep { !$src->{info}->{is_col}->{$_}