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

Gorm Query Optimization for Intensive or Frequently Used Database Tasks #334

Open
pwdel opened this issue Sep 19, 2024 · 1 comment
Open

Comments

@pwdel
Copy link
Member

pwdel commented Sep 19, 2024

Gorm gives the ability to enable query optimization in a couple of different ways.

When we consider that running a typical Gorm query might look something like this;

// Get the first record ordered by primary key
db.First(&user)
// SELECT * FROM users ORDER BY id LIMIT 1;

What's going on under the hood might be a full table pull, e.g., that * means, "grab the whole table," which increases I/O. This may not matter when the database is small. But if we're talking about having a million bets on a platform (e.g. you have 1000 users making 3 or 4 bets per day on average, so 100 bets per month, for a year, you would have 1.2 million bets), then pulling the whole table becomes horribly intensive.

However, index hints might be a way to just search a single index for something, rather than the entire table.

https://gorm.io/docs/advanced_query.html#Index-Hints

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

No branches or pull requests

2 participants
@pwdel and others