Our ads table contains JSONB fields, long text, contact data, timestamps, and other detail-page fields. A catalog card needs only a small subset. Loading that subset keeps the list query and its data contract lean.
The Problem
The default GORM pattern loads all columns:
var ads []model.Ad db.Where("marketplace_category_id = ?", categoryID).Find(&ads) // SELECT * FROM ads WHERE marketplace_category_id = ... That transfers and scans fields the card never reads. Large text and JSONB values can make the waste more visible, but the effect depends on row width, PostgreSQL TOAST behavior, the query plan, and network latency.
The Fix: Explicit Selection
A simplified version of our list query explicitly selects the fields needed by catalog cards:
var ads []*model.Ad db.Model(&model.Ad{}). Select( "ads.catalog_id", "ads.title", "ads.currency", "ads.price", "ads.image", ). Where("ads.is_published = ? AND ads.marketplace_category_id = ?", true, categoryID). Order("created_at DESC"). Limit(24). Find(&ads) Fields that were not selected keep their Go zero values, so the returned model must not escape into code that assumes it is fully populated. A dedicated projection struct makes that contract more explicit:
type CatalogCard struct { CatalogID uint `gorm:"column:catalog_id"` Title string `gorm:"column:title"` Currency string `gorm:"column:currency"` Price string `gorm:"column:price"` Image string `gorm:"column:image"` } var cards []CatalogCard db.Model(&model.Ad{}). Select("catalog_id", "title", "currency", "price", "image"). Where("is_published = ? AND marketplace_category_id = ?", true, categoryID). Find(&cards) GORM can infer a smaller projection when querying a model into a smaller struct, but an explicit Select is easier to audit and remains clear if the destination changes.
Measure the Impact
Selective loading reduces bytes sent to Go and avoids scanning or unmarshalling omitted fields. It does not guarantee a particular latency improvement: PostgreSQL may still need to visit the same heap pages, and another part of the query may dominate.
Use EXPLAIN (ANALYZE, BUFFERS) for the database plan and a Go benchmark or production trace for allocations and end-to-end latency. Compare representative data, not estimates based only on Go struct sizes.
Index Strategy
Selective columns only help if the query itself is fast. Our catalog's common predicates and sort order have a matching composite index:
CREATE INDEX idx_ads_marketplace_list ON ads ( country_id, is_published, is_owner_active, marketplace_category_id, offer_type, created_at DESC ); Column order and optional filters must follow real query patterns. Adding every filter to one index creates a large index that may not help. Confirm usage with the query plan, and remember that an index can speed reads while making writes and maintenance more expensive. On a busy existing table, assess lock impact and consider CREATE INDEX CONCURRENTLY; it cannot run inside a transaction block and can leave an invalid index after failure.
The Rule
Our convention is:
- list methods explicitly select card fields;
- detail and edit methods may load the full model;
- a partially loaded model should stay inside the read path that created it.
Find vs. Scan
Scan() is not required for a non-model projection. With Model(&model.Ad{}), GORM can use Find(&cards) and still retain the model context, including its table and applicable scopes. Scan(&cards) is also useful for custom projections and aggregate queries.
The important part is to inspect the generated SQL and understand which GORM scopes you intend to apply. The GORM query documentation shows the smart-select behavior.
This article is based on lessons from building Towami, a multi-country marketplace and white-label storefront platform. Follow for more practical notes on Go, HTMX, infrastructure, and SaaS.