Comment 4 for bug 1125144

Revision history for this message
Cees de Groot (casedeg) wrote : Re: pt-query-digest wrongly parses queries with C-style comments from the slow query log

Something like the following could do the trick. However, I'm not sure how it would impact the tool in general (quick ugly diff on the binary, but location should be clear).

*** /usr/local/bin/pt-query-digest 2013-02-15 13:13:10.000000000 +0100
--- /tmp/patched 2013-02-15 13:12:37.000000000 +0100
***************
*** 4907,4912 ****
--- 4907,4915 ----
           else {
              PTDEBUG && _d("Got the query/arg line");
              my $arg = substr($stmt, $pos - length($line));
+ # Strip C-style comments
+ $arg =~ s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.[^/"'\\]*)#defined $2 ? $2 : ""#gse;
+ PTDEBUG && _d('Clean query = ', $arg);
              push @properties, 'arg', $arg, 'bytes', length($arg);
              if ( $args{misc} && $args{misc}->{embed}
                 && ( my ($e) = $arg =~ m/($args{misc}->{embed})/)