hugowan / maatkit

Automatically exported from code.google.com/p/maatkit
0 stars 0 forks source link

Index definition parsing is incorrect #146

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
From an email to a mailing list:

I think I've spotted a flaw in it when using it on a table with an index 
on substrings of columns - the column names get split down incorrectly and
it gives an error message "No such column '(100),'". The problem is that
e.g. if the key definition is

 `surname`(20),`firstname`(20)

it first of all splits on "`", which leaves "(20)," as a bogus entry in the
list.

I've attached a patch that seems to work well enough to get me working
again, in case it's useful to anyone. I'm no perl programmer though, so I
wouldn't trust my code.

Tim

*** /home/timmartin/downloads/maatkit-1972/bin/mk-table-sync    2008-06-01
23:24:16.000000000 -0500
--- /home/timmartin/bin/mk-table-sync   2008-06-25 07:38:37.000000000 -0500
***************
*** 1073,1083 ****
          $type = 'HASH'; # MySQL pre-4.1 supports only HASH indexes on HEAP
       }

       my ($name) = $key =~ m/(PRIMARY|`[^`]*`)/;
       my $unique = $key =~ m/PRIMARY|UNIQUE/ ? 1 : 0;
!       my @cols   = grep { m/[^,]/ } split('`', $cols);
       $name      =~ s/`//g;
       $ENV{MKDEBUG} && _d("Index $name columns: " . join(', ', @cols));

       $keys{$name} = {
          colnames    => $cols,
--- 1073,1084 ----
          $type = 'HASH'; # MySQL pre-4.1 supports only HASH indexes on HEAP
       }

       my ($name) = $key =~ m/(PRIMARY|`[^`]*`)/;
       my $unique = $key =~ m/PRIMARY|UNIQUE/ ? 1 : 0;
!       my @cols   = split(',', $cols);
!       for (@cols) {s/`(.*?)`.*/$1/};
       $name      =~ s/`//g;
       $ENV{MKDEBUG} && _d("Index $name columns: " . join(', ', @cols));

       $keys{$name} = {
          colnames    => $cols,

Original issue reported on code.google.com by baron.schwartz on 29 Jun 2008 at 6:05