Ruby on Rails Wednesday, March 5, 2014


On Wednesday, March 5, 2014 12:32:04 AM UTC, John Merlino wrote:

    reports = Report.find_by_sql(["SELECT DISTINCT ON (unit_id) r.* 
                                  FROM reports r 
                                  WHERE r.unit_id IN (?) 
                                  ORDER BY unit_id, time DESC", 
                                  units.map(&:id)])

But this is running incredibly slow. In fact, after 15 minutes, I just cancelled the process. 


Any idea why the second query is taking markedly  longer than the first?

Run the query through explain (depending on your rails version, that might get logged for you automatically) and see what your database is doing.

Fred 

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c496c0ce-42fd-46a1-811f-538dc7e471f5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment