Weird behavior with "in:" clause on a findMany() with orderBy + take
See original GitHub issueBug description
Hey all, I hope you are doing well.
I’m running into a strange issue.
It seems like when there is a moderately large amount (12k+) of terms inside an “in:” clause on a findMany, with orderBy and take, it seems to give completely strange results.
But when the in clause is taken out, or the amount of terms inside are decreased; or if the take clause is taken out, it seems to function normally. Will post code examples detailing this.
How to reproduce
We are assuming a collection called “item”, and that this collection has at least 12k+ records.
const allItems = await context.prisma.item.findMany();
const allItemIds = allitems.map(({ id }) => id);
const filteredItems = await context.prisma.item.findMany({
where: {
id: {
in: allItemIds,
},
},
orderBy: {
updatedAt: 'desc',
},
take: 3,
});
return items;
For me, this does not return the items ordered correctly, nor does it return only three records.
Expected behavior
I expect it to return three items sorted in descending order by my updatedAt field.
The three cases in which this works as expected at the moment
-
If the amount of items inside the in: clause is reduced drastically
-
The in clause is dropped
const allItems = await context.prisma.item.findMany();
const allItemIds = allitems.map(({ id }) => id);
const filteredItems = await context.prisma.item.findMany({
//where: {
// id: {
// in: allItemIds,
// },
//},
orderBy: {
updatedAt: 'desc',
},
take: 3,
});
return items;
- The take clause is dropped
const allItems = await context.prisma.item.findMany();
const allItemIds = allitems.map(({ id }) => id);
const filteredItems = await context.prisma.item.findMany({
where: {
id: {
in: allItemIds,
},
},
orderBy: {
updatedAt: 'desc',
},
//take: 3,
});
return items;
Prisma information
Information covered above.
Environment & setup
- OS: MacOS / Ubuntu
- Database: MySQL 8.0.21
- Node.js version: 12.16.1
Prisma Version
prisma : 2.22.1
@prisma/client : 2.22.1
Current platform : darwin
Query Engine : query-engine 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/prisma/node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/prisma/node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/prisma/node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 60cc71d884972ab4e897f0277c4b84383dddaf6c (at node_modules/prisma/node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 60cc71d884972ab4e897f0277c4b84383dddaf6c
Studio : 0.379.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:13 (7 by maintainers)
Top GitHub Comments
I just tested this, enabled NAPI preview, re-generated, and am still running into the issue, thank you!
Hey there janpio!
I’ll check around and see if I am able to share the problematic collection, but I am worried that for reasons I will be unable.
Here is an example of my specified query using