this post was submitted on 24 Dec 2025
22 points (92.3% liked)
Programming
24072 readers
318 users here now
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I'll admit I'm not a database guy, but isn't this inefficient? It looks like it's first querying the DB for all albums, then filtering the results in the interpreter. I assume the db engine has a more optimal implementation for when you do SELECT WHERE query, designed for whatever data structures it's using internally.
Also, minor nitpick but why does it have so many different ways to define a function body?
Two great questions!
First one comes down to how database query optimization and predicate pushdown in particular. In this case,
albumswould probably have an index onalbums.idcolumn, which would optimizeget_album_by_idinto a single index lookup. Ideally, I would want to have an explicit function for this, something likesql::from_index("albums", "id", 3), but there is no such thing as explicit index lookup in PostgreSQL right now.Regarding different function syntaxes:
{ ... }construct a new tuple (think object, struct, record),So: