I'm using the Sequel gem with a postgres database which has a 300k+ entries. I'm trying to get the earliest and latest entry by time, however I migrated the db and some entries got out of order time-wise.
If I use
mydb[:items].last it takes a fraction of a second for the query. However, like I said, they aren't fully in order of time, so that can get messed up. If I run
mydb[:items].order(:time).last, it works but it takes FAR longer (roughly six seconds) to complete each query.
Is there a way to reorder the database so it's naturally in order of time, so I don't have to run the order command? Or am I just doing something wrong?