-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Query for empty relations is very slow for many-to-many relation #25731
Comments
The SQL from prisma is using SELECT COUNT(*)
FROM (
SELECT "public"."Issue"."id"
FROM "public"."Issue"
WHERE ("public"."Issue"."id") NOT IN (
SELECT "t1"."A"
FROM "public"."_IssueToUser" AS "t1"
INNER JOIN "public"."User" AS "j1"
ON ("j1"."id") = ("t1"."B")
WHERE (1=1 AND "t1"."A" IS NOT NULL)
)
) AS "sub" I modified it to use SELECT COUNT(*)
FROM (
SELECT "public"."Issue"."id"
FROM "public"."Issue"
WHERE NOT EXISTS (
SELECT "t1"."A"
FROM "public"."_IssueToUser" AS "t1"
INNER JOIN "public"."User" AS "j1"
ON ("j1"."id") = ("t1"."B")
WHERE ("public"."Issue"."id" = "t1"."A")
)
) AS "sub" |
This issue may be related to #24524. |
Hi @vimutti77, @senorverde-tc and @Sjlver, If you can offer some feedback on it that'd be great. |
Hi @jacek-prisma, thanks so much for working on this! I can give this a try mid next week, around Jan 15. To make sure I understand: I need to specify |
Hi @Sjlver. yes, these are the two NPM packages:
|
@jacek-prisma I have upgraded to the version you mentioned, but it still uses Prisma Version
|
Sorry @vimutti77 , I've listed the wrong version, I just updated the comment with the correct one! |
Thanks @jacek-prisma. I did some initial testing, and the query time was reduced to 0.5 seconds! I haven't encountered any issues yet. |
@jacek-prisma you were faster than I was. If you still need me to look into this, let me know. |
Bug description
I have a schema with many-to-many relation like this
I insert the data to database by using this SQL
I want to count the
Issue
that have emptyassignees
by usingprisma.issue.count({ where: { assignees: { none: {} } } })
But it takes about 1-2 mins to get the result.
How to reproduce
Expected behavior
It should be fast
Prisma information
Environment & setup
Prisma Version
The text was updated successfully, but these errors were encountered: