Skip to content

Bug: findMany() with two large in filters with arrays of 32767 items each fails with Assertion violation, too many bind variables in prepared statement #21802

Open

Description

@jkomyno

Consider the following query when using the postgresql provider with Rust drivers:

const n = 32767
const ids = Array.from({ length }, (_, i) => i + 1)

await prisma.tag.findMany({
  where: {
    OR: [
      {
        id: { in: ids },
      },
      {
        id: { in: ids },
      },
    ],
  },
})

This results in an error with code: "P2035" and message:

Assertion violation on the database: `too many bind variables in prepared statement, expected maximum of 32767, received 65534`

This is a bug, as we would expect the corresponding SQL query to be chunked into smaller SELECT queries using at most 32767 parameters each, and with a combined result set matching:

SELECT "public"."tag"."id" FROM "public"."tag"
WHERE ("public"."tag"."id"
  IN ($1, $2, ..., $32767)
OR "public"."tag"."id"
  IN ($32768, $32769, ..., ,$65533)
)
OFFSET $65534

Note: the same issue arises if one uses AND rather than OR in the Prisma query above.


Prisma schema:

  generator client {
    provider = "prisma-client-js"
    previewFeatures = ["driverAdapters"]
  }
  
  datasource db {
    provider = "${provider}"
    url      = env("DATABASE_URL")
  }

  model Tag {
    id Int  @id
  }

Prisma version: 5.5.2

Activity

  1. added
    kind/bug
    tech/engines
    bug/2-confirmed
    on Nov 6, 2023
  2. changed the title [-]bug: `findMany` with two large `in` filters with arrays of `32767` items each fails with `Assertion violation`, `too many bind variables in prepared statement`[/-] [+]bug: `findMany()` with two large `in` filters with arrays of `32767` items each fails with `Assertion violation`, `too many bind variables in prepared statement`[/+] on Mar 27, 2024
  3. changed the title [-]bug: `findMany()` with two large `in` filters with arrays of `32767` items each fails with `Assertion violation`, `too many bind variables in prepared statement`[/-] [+]Bug: `findMany()` with two large `in` filters with arrays of `32767` items each fails with `Assertion violation`, `too many bind variables in prepared statement`[/+] on Mar 27, 2024
  4. jkomyno commented on Jul 15, 2024

    @jkomyno
    ContributorAuthor

    Linked issue: #23957

  5. peterHakio commented on Dec 17, 2024

    @peterHakio

    What is the progress on this bug?

  6. Kila14 commented on Jul 9, 2025

    @Kila14

    Prisma version 6.11.1 still bug exist

  7. ryan-crabbe-berri commented on Sep 23, 2026

    @ryan-crabbe-berri

    hey litellm maintainer here, we're going to look at taking down this class of bug with a lint rule to remove unbounded IN queries and then have anywhere that would do this go through the same unified share logic for trying the initial query then chunking it for posterity. wip pr linked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/2-confirmedkind/bugtech/enginestopic: chunkingtopic: findMany()topic: postgresql

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions