You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@s2graph.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2018/04/17 07:35:00 UTC
[jira] [Commented] (S2GRAPH-204) Avoid N + 1 queries in GraphQL
[ https://issues.apache.org/jira/browse/S2GRAPH-204?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16440530#comment-16440530 ]
ASF GitHub Bot commented on S2GRAPH-204:
----------------------------------------
GitHub user daewon opened a pull request:
https://github.com/apache/incubator-s2graph/pull/157
[S2GRAPH-204] Avoid N + 1 queries in GraphQL
I removed the part where 'N + 1' queries occur in queries that fetch Vertices and Edges using 'DeferredResolver' provided by sangria framework.
http://sangria-graphql.org/learn/#deferred-value-resolution
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/daewon/incubator-s2graph S2GRAPH-204
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-s2graph/pull/157.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #157
----
commit 69ca2787fb2f863a1c383b55e62798e0cd62b305
Author: daewon <da...@...>
Date: 2018-04-10T10:25:14Z
resolve n+1 query
----
> Avoid N + 1 queries in GraphQL
> -------------------------------
>
> Key: S2GRAPH-204
> URL: https://issues.apache.org/jira/browse/S2GRAPH-204
> Project: S2Graph
> Issue Type: Improvement
> Components: s2graphql
> Reporter: Daewon Jeong
> Assignee: Daewon Jeong
> Priority: Minor
>
> h1. Avoid N + 1 queries in GraphQL
> Let's look at the query below.
> {noformat}
> query {
> User(id: 1) {
> name
> Like(limit: 5) { # fetch edge (has sourceVertex id == 1)
> Movie { # fetch vertex every edges, N + 1 query for fetch vertex info
> title
> }
> }
> }
> }
> {noformat}
> The query retrieves the User(id: 1)'s name and 10 movie titles the user likes.
> In this case, the query that occurs internally in S2Graph is as follows
> # Fetch a vertex to resolving the 'name' field (1 IO)
> # fetch 5 edges to resolving the 'Like' field (1 IO)
> # fetch 5 vertices for each Edge to resolving the movie 'title' (10 IO)
> Assuming that the Movie ID of the edge returned in step.2 is [e1..e5], the query executed to get Movie title is as follows.
> {noformat}
> getVertices(e1)
> getVertices(e2)
> getVertices(e3)
> getVertices(e4)
> getVertices(e5)
> {noformat}
> Retrieving every vertices one-by-one would be very inefficient
> In this case, you can query the Movie Vertex of the edge by collecting 5 IDs without querying each one.
> {noformat}
> ex) getVertices([e1, e2, e3, e4, e5])
> {noformat}
> Which of these two approaches Whether it is more efficient depends on the internal implementation of S2Graph.
> But here we are considering the GraphQL implementation.
> Follow the instructions below to resolve the issue.
> Reference:
> [http://sangria-graphql.org/learn/#deferred-value-resolution]
> [https://github.com/sangria-graphql/sangria/issues/63]
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)