prisma: Cannot run queries with small "notIn" or "not: null" on large tables: `Error: Query parameter limit exceeded error: Parameter limits for this database provider require this query to be split into multiple queries, but the negation filters used prevent the query from being split. Please reduce the used values in the query.`
Bug description
When querying the following in large tables, with postgresql, an error is raised by prisma. It says that the negative filter prevents the request from being split.
But the negative filter only contains 1 or 2 parameters (either a “notIn [1,2]” or a “not: null”).
This short filter should not be a problem.
This code was working fine in prisma 3.5.0 and the error raises since 3.6.0
How to reproduce
Run the provided request with large tables with a notIn filter with the provided schema.
The request will fail
Expected behavior
The query should run properly.
Prisma information
Prisma query :
const machines = await prisma.tblMachine.findMany({
select: {
MCH_MACHLINK: true,
parts: {
where: {
PRT_BLOCKED: 'N',
PRT_DELETED: { notIn: [1, 2] }, // the negative filter. also fails if I replace it with "PRT_DELETED: { not: null }",
},
select: {
PRT_PARTLINK: true,
},
},
},
orderBy: [{ MCH_MACHLINK: 'asc' }],
take: 500,
});
Prisma schema :
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model TblMachine {
MCH_MACHLINK Int @id
parts TblPart[]
}
model TblPart {
PRT_PARTLINK Int @id
PRT_MACHLINK Int
PRT_DELETED Int? @db.SmallInt
PRT_BLOCKED String? @db.VarChar(1)
machine TblMachine @relation(fields: [PRT_MACHLINK], references: [MCH_MACHLINK])
}
Prisma logs :
prisma:tryLoadEnv Environment variables loaded from /Users/drico/github/anacApiV2/backend/server/.env +0ms
prisma:tryLoadEnv Environment variables loaded from /Users/drico/github/anacApiV2/backend/server/.env +3ms
prisma:client clientVersion: 3.10.0 +0ms
prisma:client clientEngineType: library +0ms
prisma:client:libraryEngine internalSetup +0ms
prisma:client:libraryEngine Searching for Query Engine Library in /Users/drico/github/anacApiV2/backend/server/node_modules/.prisma/client +10ms
prisma:client:libraryEngine loadEngine using /Users/drico/github/anacApiV2/backend/server/node_modules/.prisma/client/libquery_engine-darwin.dylib.node +0ms
prisma:client Prisma Client call: +960ms
prisma:client prisma.tblMachine.findMany({
prisma:client select: {
prisma:client MCH_MACHLINK: true,
prisma:client parts: {
prisma:client where: {
prisma:client PRT_BLOCKED: 'N',
prisma:client PRT_DELETED: {
prisma:client notIn: [
prisma:client 1,
prisma:client 2
prisma:client ]
prisma:client }
prisma:client },
prisma:client select: {
prisma:client PRT_PARTLINK: true
prisma:client }
prisma:client }
prisma:client },
prisma:client orderBy: [
prisma:client {
prisma:client MCH_MACHLINK: 'asc'
prisma:client }
prisma:client ],
prisma:client take: 500,
prisma:client where: {}
prisma:client }) +1ms
prisma:client Generated request: +1ms
prisma:client query {
prisma:client findManyTblMachine(
prisma:client orderBy: [
prisma:client {
prisma:client MCH_MACHLINK: asc
prisma:client }
prisma:client ]
prisma:client take: 500
prisma:client where: {
prisma:client
prisma:client }
prisma:client ) {
prisma:client MCH_MACHLINK
prisma:client parts(where: {
prisma:client PRT_BLOCKED: "N"
prisma:client PRT_DELETED: {
prisma:client notIn: [1, 2]
prisma:client }
prisma:client }) {
prisma:client PRT_PARTLINK
prisma:client }
prisma:client }
prisma:client }
prisma:client +0ms
prisma:client:libraryEngine sending request, this.libraryStarted: false +951ms
prisma:client:libraryEngine library starting +0ms
prisma:info Starting a postgresql pool with 10 connections.
prisma:client:libraryEngine library started +541ms
prisma:query SELECT "ANAC"."TBLMACHINE"."MCH_MACHLINK" FROM "ANAC"."TBLMACHINE" WHERE 1=1 ORDER BY "ANAC"."TBLMACHINE"."MCH_MACHLINK" ASC LIMIT $1 OFFSET $2
prisma:client:request_handler Error: Query parameter limit exceeded error: Parameter limits for this database provider require this query to be split into multiple queries, but the negation filters used prevent the query from being split. Please reduce the used values in the query..
prisma:client:request_handler at prismaGraphQLToJSError (/Users/drico/github/anacApiV2/backend/server/node_modules/@prisma/client/runtime/index.js:33913:12)
prisma:client:request_handler at Object.request (/Users/drico/github/anacApiV2/backend/server/node_modules/@prisma/client/runtime/index.js:35739:17)
prisma:client:request_handler at Object.request (/Users/drico/github/anacApiV2/backend/server/node_modules/@prisma/client/runtime/index.js:39779:24)
prisma:client:request_handler at PrismaClient._request (/Users/drico/github/anacApiV2/backend/server/node_modules/@prisma/client/runtime/index.js:40637:18)
prisma:client:request_handler at fetchBatch (/Users/drico/github/anacApiV2/backend/server/src/tasks/elastic/syncMachines.ts:154:20)
prisma:client:request_handler at /Users/drico/github/anacApiV2/backend/server/src/tasks/elastic/helpers.ts:83:28 +0ms
Error !
PrismaClientKnownRequestError:
Invalid `prisma.tblMachine.findMany()` invocation in
/Users/drico/github/anacApiV2/backend/server/src/tasks/elastic/syncMachines.ts:154:44
→ 154 const machines = await prisma.tblMachine.findMany(
Query parameter limit exceeded error: Parameter limits for this database provider require this query to be split into multiple queries, but the negation filters used prevent the query from being split. Please reduce the used values in the query..
at Object.request (/Users/drico/github/anacApiV2/backend/server/node_modules/@prisma/client/runtime/index.js:39809:15)
at PrismaClient._request (/Users/drico/github/anacApiV2/backend/server/node_modules/@prisma/client/runtime/index.js:40637:18)
at fetchBatch (/Users/drico/github/anacApiV2/backend/server/src/tasks/elastic/syncMachines.ts:154:20)
at /Users/drico/github/anacApiV2/backend/server/src/tasks/elastic/helpers.ts:83:28 {
code: 'P2029',
clientVersion: '3.10.0',
meta: {
message: 'Parameter limits for this database provider require this query to be split into multiple queries, but the negation filters used prevent the query from being split. Please reduce the used values in the query.'
}
}
prisma:client:libraryEngine hookProcess received: exit +128ms
prisma:client:libraryEngine runBeforeExit +0ms
error Command failed with exit code 1.
Environment & setup
- OS: Mac OS
- Database: PostgreSQL
- Node.js version: 14.17.6
Prisma Version
prisma : 3.10.0
@prisma/client : 3.10.0
Current platform : darwin
Query Engine (Node-API) : libquery-engine 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine : migration-engine-cli 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt 73e60b76d394f8d37d8ebd1f8918c79029f0db86 (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 73e60b76d394f8d37d8ebd1f8918c79029f0db86
Studio : 0.458.0
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 2
- Comments: 16 (6 by maintainers)
@millsp it’s easy to reproduce, just put more than
32767items innotIn, that should trigger this error