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

Too many queries are executed #22

Open
havotto opened this issue Feb 24, 2020 · 3 comments
Open

Too many queries are executed #22

havotto opened this issue Feb 24, 2020 · 3 comments

Comments

@havotto
Copy link

havotto commented Feb 24, 2020

Looks good, but just executing the query

query {
  conferences{
    id
    name
  }
}

results in a lot of additional queries, with many joins and subselects, only the first one is neccesary:

Hibernate: select conference0_.id as id1_1_, conference0_.version as version2_1_, conference0_.city as city3_1_, conference0_.name as name4_1_ from conference conference0_
Hibernate: select talks0_.conferences_id as conferen2_4_0_, talks0_.talks_id as talks_id1_4_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?
Hibernate: select speakers0_.talks_id as talks_id1_5_1_, speakers0_.speakers_id as speakers2_5_1_, person1_.id as id1_2_0_, person1_.version as version2_2_0_, person1_.blog as blog3_2_0_, person1_.github_account as github_a4_2_0_, person1_.name as name5_2_0_ from talk_speakers speakers0_ inner join person person1_ on speakers0_.speakers_id=person1_.id where speakers0_.talks_id in (select talk1_.id from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?)
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select speakers0_.talks_id as talks_id1_5_1_, speakers0_.speakers_id as speakers2_5_1_, person1_.id as id1_2_0_, person1_.version as version2_2_0_, person1_.blog as blog3_2_0_, person1_.github_account as github_a4_2_0_, person1_.name as name5_2_0_ from talk_speakers speakers0_ inner join person person1_ on speakers0_.speakers_id=person1_.id where speakers0_.talks_id in (select talk1_.id from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?)
Hibernate: select conference0_.talks_id as talks_id1_4_1_, conference0_.conferences_id as conferen2_4_1_, conference1_.id as id1_1_0_, conference1_.version as version2_1_0_, conference1_.city as city3_1_0_, conference1_.name as name4_1_0_ from talk_conferences conference0_ inner join conference conference1_ on conference0_.conferences_id=conference1_.id where conference0_.talks_id in (select talk1_.id from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?)
Hibernate: select conference0_.talks_id as talks_id1_4_1_, conference0_.conferences_id as conferen2_4_1_, conference1_.id as id1_1_0_, conference1_.version as version2_1_0_, conference1_.city as city3_1_0_, conference1_.name as name4_1_0_ from talk_conferences conference0_ inner join conference conference1_ on conference0_.conferences_id=conference1_.id where conference0_.talks_id in (select talk1_.id from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?)
Hibernate: select talks0_.conferences_id as conferen2_4_0_, talks0_.talks_id as talks_id1_4_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?
Hibernate: select talks0_.conferences_id as conferen2_4_0_, talks0_.talks_id as talks_id1_4_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?
Hibernate: select talks0_.conferences_id as conferen2_4_0_, talks0_.talks_id as talks_id1_4_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?
Hibernate: select speakers0_.talks_id as talks_id1_5_1_, speakers0_.speakers_id as speakers2_5_1_, person1_.id as id1_2_0_, person1_.version as version2_2_0_, person1_.blog as blog3_2_0_, person1_.github_account as github_a4_2_0_, person1_.name as name5_2_0_ from talk_speakers speakers0_ inner join person person1_ on speakers0_.speakers_id=person1_.id where speakers0_.talks_id in (select talk1_.id from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?)
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select conference0_.talks_id as talks_id1_4_1_, conference0_.conferences_id as conferen2_4_1_, conference1_.id as id1_1_0_, conference1_.version as version2_1_0_, conference1_.city as city3_1_0_, conference1_.name as name4_1_0_ from talk_conferences conference0_ inner join conference conference1_ on conference0_.conferences_id=conference1_.id where conference0_.talks_id in (select talk1_.id from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?)
Hibernate: select talks0_.conferences_id as conferen2_4_0_, talks0_.talks_id as talks_id1_4_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?
Hibernate: select talks0_.conferences_id as conferen2_4_0_, talks0_.talks_id as talks_id1_4_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_conferences talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.conferences_id=?
Hibernate: select speakers0_.talks_id as talks_id1_5_0_, speakers0_.speakers_id as speakers2_5_0_, person1_.id as id1_2_1_, person1_.version as version2_2_1_, person1_.blog as blog3_2_1_, person1_.github_account as github_a4_2_1_, person1_.name as name5_2_1_ from talk_speakers speakers0_ inner join person person1_ on speakers0_.speakers_id=person1_.id where speakers0_.talks_id=?
Hibernate: select talks0_.speakers_id as speakers2_5_0_, talks0_.talks_id as talks_id1_5_0_, talk1_.id as id1_3_1_, talk1_.version as version2_3_1_, talk1_.summary as summary3_3_1_, talk1_.title as title4_3_1_ from talk_speakers talks0_ inner join talk talk1_ on talks0_.talks_id=talk1_.id where talks0_.speakers_id=?
Hibernate: select conference0_.talks_id as talks_id1_4_0_, conference0_.conferences_id as conferen2_4_0_, conference1_.id as id1_1_1_, conference1_.version as version2_1_1_, conference1_.city as city3_1_1_, conference1_.name as name4_1_1_ from talk_conferences conference0_ inner join conference conference1_ on conference0_.conferences_id=conference1_.id where conference0_.talks_id=?
@npalm
Copy link
Owner

npalm commented Feb 28, 2020

@havotto thanks for creating the issue. I fully agree to your point. I have created this application only as example for exampling the usage of graphql with spring. I did not focussed at all on the implication of the load on the db. Do you have a suggestion for a solution?

@havotto
Copy link
Author

havotto commented Feb 28, 2020

I don't have a solution unfortunately, but I suspect that this is due to the EAGER loading setting. I modified all EAGER to LAZY, but in that case 3 tests failed, and I have not investigated it further since that.
In another Spring-Hibernate-GraphQL example I also saw the same issues. I also would like to know what is a reliable solution for this kind of issue.

@sebastienvermeille
Copy link

@havotto I also start working with spring graphql and found this it might interest you: https://medium.com/evooq-engineering/graphql-demystified-the-n-1-problem-a455e717de4d

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

No branches or pull requests

3 participants