Re: Slow ActiveRecord - MySQL

Jeremy Kemper
Thu, 09 Nov 2006 22:11:19 -0000

On 11/9/06, HeistTheAlmighty-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
<HeistTheAlmighty-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
>
> I use find_by_sql to execute a query which takes around 120 seconds to
> execute in Ruby. When I execute the same request using SQLyog (GUI),
> the requests takes around 15 seconds to execute.
>
> Here''s roughly what the query looks like:
>
> SELECT DAY(date_time) "day", COUNT( * ) "count"
> FROM table
> WHERE (id = some_id)
> AND(YEAR(date_time) = 2006)
> AND(MONTH(date_time) = 8)
> AND(some_string IN (''some short string'') )
> GROUP BY DAY( date_time );
>
> I''m querying about a million records.


How many results?  Compare find_by_sql with connection.select_all timing.

An index such as (id, YEAR(date_time), MONTH(date_time)) would really help,
in any case.

jeremy