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

Prisma relationJoins not being honored #9173

Open
mariomnts opened this issue Jun 14, 2024 · 0 comments
Open

Prisma relationJoins not being honored #9173

mariomnts opened this issue Jun 14, 2024 · 0 comments

Comments

@mariomnts
Copy link

I'm using the Prisma preview feature relationJoins that as the docs say

Uses a database-level LATERAL JOIN (PostgreSQL) or correlated subqueries (MySQL) and fetches all data with a single query to the database.
and I was expecting that when requesting an entity and one of its relation we would be reducing the number of queries dramatically to even just one but that's not being the case.

For example, for the following graphql request:

query keystone($where: SubscriptionContractWhereInput!) {
  author(take: 10, skip: 0) {
    id
    posts {
      id
    }
  }
}

I can see in the console 10 + 1 queries, first getting the Author table, and then querying 10 times the Posts table. I'm also seeing that we include ALL the fields of both tables despite I'm just asking for one field.

If in the same server I use the following Prisma function:

await context.prisma.Author.findMany({
  select: { id: true, posts: { select: { id: true } } },
  take: 10,
  skip: 0,
});

I can see in the logs just one query that uses the LATERAL JOIN.

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

1 participant