Your Question

While using gorm a select of a small struct(29 members) takes almost 400ms, When using phpmyadmin, database/sql or the mysql cli it's only around 6ms. Every table has a primary key as index. Is there something wrong with my setup?

using gorm: Gorm Is it normal that select queries are so slow?

raw: Gorm Is it normal that select queries are so slow?

my gorm function:

func GetUserById(id int) User {
    var ret User
    db.Preload(clause.Associations).First(&ret, "id = ?", id)
    return ret
}

my gorm config:

&gorm.Config{ 
            Logger:                 logger.Default.LogMode(logger.Warn),
            CreateBatchSize:        4000,
            SkipDefaultTransaction: true,
            PrepareStmt:            true,
})

Expected answer

Is this expected/normal behaviour? If no, what are possible solutions to this?

Comment From: ivila

Maybe you should check the SQL of preload, I guess that some associations with your User model is loading slowly.

Comment From: EinTim23

Yep, that solved the issue thanks. I thought that the time that gorm shows me is only for the single query and doesnt include the time taken to fetch the associations.