Ruby on Rails
Sunday, July 28, 2013
Postgres documentation for LIMIT: http://www.postgresql.org/docs/9.2/static/queries- limit.html I should look at the postgres/rails documentation more to see how limit and pluck actually work! From what I see, my method orders all the rows within postgres, postgres gets the ID column, and then rails throws out everything except the last 200 rows. Frederick's method does the same, but the extra rows are thrown out within postgres instead. I assume that the speed bump is because postgres handles the disposal of the extra rails?
Pluck is a rails thing. But yes the difference is that your code fetches 14000 ids and then ruby picks the last 200 of those, whereas by using limit postgres only returns 200 rows. In addition because it's sorting on an indexed column it's very quick for it to find the last 200 rows - it doesn't have to find all 14000 first.
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/99a4f9e9-905e-4b76-8831-a39ff0189b05%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment