The 30 second answer
I select only the columns I need instead of everything. That means less data read, sent over the network and turned into objects, and it allows index-only scans when the selected columns are in an index. It also protects the API from accidentally exposing new columns and from breaking when someone adds a large text or binary column later.
Could you say this in an interview?
Selecting only the columns you need sends less data and makes index-only scans possible, since an index can only cover the columns you ask for.
Sources (2)
- Use The Index, Luke: Index-Only Scanuse-the-index-luke.com
- PostgreSQL 17: Index-Only Scanspostgresql.org