> > >> >> SELECT count(*) > > >> >> FROM bayes_token > > >> >> WHERE id = '4' > > >> >> AND ('1190846660' - atime) > '345600'; > > >> > Who the hell wrote *that* query? Is MySQL smart enough to rearrange > > >> > that equation to give an indexable comparison?
It doesn't seem to make any difference in timing, seems the expression optimizer is smart enough. But it is ugly indeed. On Thursday September 27 2007 07:22:31 Henrik Krohns wrote: > > > I think you mean: > > > AND atime < ? - ? Actually both parameters are constants during execution of a select, so the following would do just fine: Index: lib/Mail/SpamAssassin/BayesStore/SQL.pm =================================================================== --- lib/Mail/SpamAssassin/BayesStore/SQL.pm (revision 579950) +++ lib/Mail/SpamAssassin/BayesStore/SQL.pm (working copy) @@ -241,7 +241,7 @@ my $sql = "SELECT count(*) FROM bayes_token WHERE id = ? - AND (? - atime) > ?"; + AND atime < ?"; my $sth = $self->{_dbh}->prepare_cached($sql); @@ -251,7 +251,7 @@ } for (my $i = 1; $i <= $max_expire_mult; $i<<=1) { - my $rc = $sth->execute($self->{_userid}, $newest_atime, $start * $i); + my $rc = $sth->execute($self->{_userid}, $newest_atime - $start * $i); unless ($rc) { dbg("bayes: calculate_expire_delta: SQL error: ".$self->{_dbh}->errstr()); Mark