Fix for 937234: pt-query-advisor issues wrong RES.001

This commit is contained in:
Brian Fraser
2012-11-01 05:33:35 -03:00
parent 64fe380986
commit 4b5c8969f0
3 changed files with 36 additions and 5 deletions

View File

@@ -341,11 +341,16 @@ sub get_rules {
grep { $_->{column} }
@$groupby;
return unless scalar %groupby_col;
my $cols = $event->{query_struct}->{columns};
# Skip non-columns -- NULL, digits, functions, variables
my $cols = [
grep { _looks_like_column($_->{col}) }
@{$event->{query_struct}->{columns}}
];
# All SELECT cols must be in GROUP BY cols clause.
# E.g. select a, b, c from tbl group by a; -- non-deterministic
foreach my $col ( @$cols ) {
return 0 unless $groupby_col{ $col->{col} };
return 0 unless $groupby_col{ $col->{col} }
|| ($col->{alias} && $groupby_col{ $col->{alias} });
}
return;
},
@@ -658,6 +663,14 @@ sub determine_table_for_column {
return;
}
sub _looks_like_column {
my $col = shift;
# NULL, numbers, variables and functions are definitely not columns
return if $col eq '*' || $col eq 'NULL';
return if $col =~ /\A(?:\b[0-9]+\b|[^(]+\(|\@{1,2}.+)/;
return $col;
}
sub _d {
my ($package, undef, $line) = caller 0;
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }