Add func to col ident struct to fix QueryAdvisorRules.t.

This commit is contained in:
Daniel Nichter
2012-04-03 11:03:17 -06:00
parent dcec863988
commit c3b99d17a1
3 changed files with 8 additions and 3 deletions

View File

@@ -251,7 +251,7 @@ sub get_rules {
my $cols = $event->{query_struct}->{columns}; my $cols = $event->{query_struct}->{columns};
return unless $cols; return unless $cols;
foreach my $col ( @$cols ) { foreach my $col ( @$cols ) {
return 0 if $col->{col} eq '*'; return 0 if $col->{col} eq '*' && !$col->{func};
} }
return; return;
}, },

View File

@@ -1299,8 +1299,9 @@ sub parse_identifier {
return unless $type && $ident; return unless $type && $ident;
PTDEBUG && _d("Parsing", $type, "identifier:", $ident); PTDEBUG && _d("Parsing", $type, "identifier:", $ident);
my ($func, $expr);
if ( $ident =~ m/^\w+\(/ ) { # Function like MIN(col) if ( $ident =~ m/^\w+\(/ ) { # Function like MIN(col)
my ($func, $expr) = $ident =~ m/^(\w+)\(([^\)]*)\)/; ($func, $expr) = $ident =~ m/^(\w+)\(([^\)]*)\)/;
PTDEBUG && _d('Function', $func, 'arg', $expr); PTDEBUG && _d('Function', $func, 'arg', $expr);
return { col => $ident } unless $expr; # NOW() return { col => $ident } unless $expr; # NOW()
$ident = $expr; # col from MAX(col) $ident = $expr; # col from MAX(col)
@@ -1340,6 +1341,10 @@ sub parse_identifier {
} }
} }
if ( $func ) {
$ident_struct{func} = uc $func;
}
PTDEBUG && _d($type, "identifier struct:", Dumper(\%ident_struct)); PTDEBUG && _d($type, "identifier struct:", Dumper(\%ident_struct));
return \%ident_struct; return \%ident_struct;
} }

View File

@@ -2065,7 +2065,7 @@ my @cases = (
from => 'l ', from => 'l ',
where => 'col<100' where => 'col<100'
}, },
columns => [ { col => 'max(col)' } ], columns => [ { col => 'col', func => 'MAX' } ],
context => 'scalar', context => 'scalar',
from => [ { tbl => 'l' } ], from => [ { tbl => 'l' } ],
nested => 1, nested => 1,