DEV Community

Discussion on: 1 SQL Query You Should Stop Using

Collapse
 
austingil profile image
Austin Gil

Yeah, this is some good lil tips. I think your "Order Base Pagination" example relies on the ID column being an auto-incrementing index. I've heard this is no longer a best-practice because it would make sharding really hard. So it's better to reach for UUIDs. Do you have a solution for pagination with UUIDs?

Collapse
 
abdisalan_js profile image
Abdisalan

To sort with UUIDs, you'll need to rely on another column that you can order your data by. The 3rd example with created_at is a common solution but you could use anything you can order your data by :)

Collapse
 
austingil profile image
Austin Gil

OK, I figured as much. I wonder if there is a way to do something like DynamoDB where you would pass the ID to start after. So rather than an offset, you tell the DB like "get me the next 10 posts starting after this ID" but the ID is not like an integer.

Thread Thread
 
abdisalan_js profile image
Abdisalan

That would be pretty interesting! I'll have to look up that feature in Dynamo

Thread Thread
 
austingil profile image
Austin Gil

Yeah. Im not sure it's possible with SQL. Part of the reason Dynamo is so fast is due to the way it looks up data, but it also makes it very restricting on how you access that data and plan your primary keys. So far I still prefer SQL, but it's good to know about the strengths and weaknesses