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

Queryset Preload Methods Repeat Keys #23

Closed
DazedNConfused- opened this issue Feb 6, 2018 · 2 comments
Closed

Queryset Preload Methods Repeat Keys #23

DazedNConfused- opened this issue Feb 6, 2018 · 2 comments
Labels

Comments

@DazedNConfused-
Copy link

When writing a Query that involves preloading a foreign-key object (for example: DBModel.NewObjectQuerySet(DBConn).PrimaryKeyEq(pk).PreloadNestedObject()), the Nested Objects are fetched in a query that has a WHERE clause with all the foreign-key IDs.

The problem arises when said Nested Objects are the same for multiple instances of Object (a many-to-one relationship); the underlying query repeats the key. For example:

Object PK Nested Object FK
1 1
2 2
3 1
4 1
5 1

Results in the following query when using PreloadNestedObject():

SELECT * FROM NestedObject WHERE pk IN (1, 1, 1, 1, 2);

This massively slows down the underlying queries when fetching fairly average resultsets (tens of seconds every 30000 simple records).

@jirfag
Copy link
Owner

jirfag commented Feb 8, 2018

@DazedNConfused- thank you for issue and nice formatting, but I can't control this behaviour in go-queryset. It's a gorm issue. As I understood it was fixed in this commit, please try updating gorm

@jirfag jirfag added the wontfix label Feb 8, 2018
@DazedNConfused-
Copy link
Author

Thank you for the heads-up! I have updated gorm but the behaviour persists. Perhaps it wasn't pushed to upstream yet.

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

No branches or pull requests

2 participants