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.
Incorrect
Section titled “Incorrect”var users []Userdb.Find(&users) // all columnsfor _, u := range users { fmt.Println(u.Email)}Correct
Section titled “Correct”var emails []stringdb.Model(&User{}).Pluck("email", &emails)Project only the needed fields with Select/Pluck to reduce the column width fetched.