We have two model
1. Foo
a. id
b. name
2. Bar
a. id
b. foo = FK (A)
c. status
We are trying to run a query which required to found count of Foo where status of Bar in ["pending", "inprogress"]
So technically query should be in postgres is
select count (*) from A INNER JOIN ON Foo.id = Bar.foo_id where Bar.status in ('pending', 'inprogress');
So here is our ORM query
await prisma.Foo.count({
Bars: {
some: {
status: {
in: ['pending', 'inprogress'],
},
}
}
})
The query looks like following
SELECT count (*) from (select Foo.id From Foo where (Foo.id IN (select id from Foo INNER JOIN Bar on Foo.id = Bar.foo_id where Bar.status in ('inprogress', 'pending')) ))
This query is unnecessary adding the In Clause within the query which leads to unwanted Parallel hash join and have high impact in our response time.