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

database query improvement #9

Open
ecshreve opened this issue Jun 26, 2023 · 0 comments
Open

database query improvement #9

ecshreve opened this issue Jun 26, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ecshreve
Copy link
Owner

Screenshot 2023-06-25 at 11 30 25 PM

the /api/clue?random query is the culprit behind the slowest query here.

func GetRandomClue() (*Clue, error) {

SELECT * FROM <table-name> ORDER BY RAND() LIMIT 1 works just fine for small tables, but real bad for this big (~350k row table).

the sqlx documentation helps explain

Select can save you a lot of typing, but beware! It's semantically different from Queryx, 
since it will load the entire result set into memory at once. If that set is not bounded by 
your query to some reasonable size, it might be best to use the classic Queryx/StructScan
 iteration instead.

probably going to do something like picking a random game first, and then a random clue from the game. maybe caching a chunk of random clues when the server starts could work too. haven't given it too much thought yet

@ecshreve ecshreve added the enhancement New feature or request label Jun 26, 2023
@ecshreve ecshreve self-assigned this Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant