Home Sequel gem reorder postgres database?
Reply: 1

Sequel gem reorder postgres database?

Max
1#
Max Published in 2018-02-14 02:36:58Z

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].first and 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).first and 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?

Pablo
2#
Pablo Reply to 2018-02-14 03:02:01Z

If you want to get record in a specific order you must use an order clause. Most databases do not guarantee the order if no sort clause is provided.

You should index your table by the fields you will use to sort.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.300602 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO