I have a 10,000+ row table that I am trying to query in Rails 4. Let's call it events
and there are many, many years of past events still in the database. I need to grab only the events with a date
of today or in the future. I could do something like:
@events = Event.where('date >= ?', todays_date)
but this still takes a long time as it has to go through every record. Is there a simple way to speed this up? I've even considered that starting from the most recent rows, moving backwards, and limiting to say 1,000 total would be "good enough", although it could potentially leave out an event created a long time ago but with a date in the near future. I'm not even sure how to go about starting from the last row, however. And I feel like there has to be a better solution anyhow.
Any ideas? Thank you in advance!