Aller au contenu

Select Star Over Fetch (ARCH5066)

Ce contenu n’est pas encore disponible dans votre langue.

Key go.orm.select-star-over-fetch · Severity info · Category orm

Fetching the full entity/all columns when only a few fields are used inflates row width and serialization cost. Use a projection.

var users []User
db.Find(&users) // all columns
for _, u := range users {
fmt.Println(u.Email)
}
var emails []string
db.Model(&User{}).Pluck("email", &emails)

Project only the needed fields with Select/Pluck to reduce the column width fetched.