Fix for 996069: Incorrect RES.001 when using aggregate functions

This commit is contained in:
Brian Fraser
2012-11-02 01:18:10 -03:00
parent 4b5c8969f0
commit 1aa154d6c6
3 changed files with 7 additions and 0 deletions

View File

@@ -3815,6 +3815,7 @@ sub get_rules {
return unless scalar %groupby_col; return unless scalar %groupby_col;
my $cols = [ my $cols = [
grep { _looks_like_column($_->{col}) } grep { _looks_like_column($_->{col}) }
grep { ! exists $_->{func} }
@{$event->{query_struct}->{columns}} @{$event->{query_struct}->{columns}}
]; ];
foreach my $col ( @$cols ) { foreach my $col ( @$cols ) {

View File

@@ -344,6 +344,7 @@ sub get_rules {
# Skip non-columns -- NULL, digits, functions, variables # Skip non-columns -- NULL, digits, functions, variables
my $cols = [ my $cols = [
grep { _looks_like_column($_->{col}) } grep { _looks_like_column($_->{col}) }
grep { ! exists $_->{func} }
@{$event->{query_struct}->{columns}} @{$event->{query_struct}->{columns}}
]; ];
# All SELECT cols must be in GROUP BY cols clause. # All SELECT cols must be in GROUP BY cols clause.

View File

@@ -471,6 +471,11 @@ my @cases = (
query => q{select NULL, 1, COUNT(*), @@time_zone, foo as field2 from t1 group by field2}, query => q{select NULL, 1, COUNT(*), @@time_zone, foo as field2 from t1 group by field2},
advice => [qw(CLA.001)], advice => [qw(CLA.001)],
}, },
{
name => 'Bug 996069: wrong RES.001',
query => q{SELECT cola, MAX(colb) FROM table WHERE cola = 123 GROUP BY cola},
advice => [qw()],
},
); );
# Run the test cases. # Run the test cases.