Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it normal that select queries are so slow? #6797

Closed
EinTim23 opened this issue Jan 16, 2024 · 2 comments
Closed

Is it normal that select queries are so slow? #6797

EinTim23 opened this issue Jan 16, 2024 · 2 comments
Assignees
Labels
type:question general questions

Comments

@EinTim23
Copy link

EinTim23 commented Jan 16, 2024

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:
image

raw:
image

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?

@EinTim23 EinTim23 added the type:question general questions label Jan 16, 2024
@ivila
Copy link
Contributor

ivila commented Jan 17, 2024

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

@EinTim23
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question general questions
Projects
None yet
Development

No branches or pull requests

3 participants