Skip to content

Driver Adapters: findMany() with two large in filters with arrays of 65536 items each results in no query chunking when using Driver Adapters #21803

Open

Description

@jkomyno

Consider the following query when using the pg / neon Driver Adapters:

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

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

One would expect query chunking to kick in (as n > 32767). Yet the Prisma query above is translated into a single SELECT statements with 98303 parameters:

SELECT "public"."tag"."id" FROM "public"."tag"
WHERE ("public"."tag"."id"
  IN ($1, $2, ..., $65536)
OR "public"."tag"."id"
  IN ($65537, $65538, ..., ,$98302)
)
OFFSET $98303

which causes Postgres to trigger the error bind message has 32767 parameter formats but 0 parameters:

  prisma:driver-adapter:pg Error in performIO: error: bind message has 32767 parameter formats but 0 parameters
  prisma:driver-adapter:pg     at /prisma/prisma/node_modules/.pnpm/[email protected][email protected]/node_modules/pg-pool/index.js:45:11
  prisma:driver-adapter:pg     at processTicksAndRejections (node:internal/process/task_queues:95:5)
  prisma:driver-adapter:pg     at PrismaPg.performIO (/prisma/prisma/packages/adapter-pg/dist/index.js:253:22)
  prisma:driver-adapter:pg     at PrismaPg.queryRaw (/prisma/prisma/packages/adapter-pg/dist/index.js:224:22)
  prisma:driver-adapter:pg     at /prisma/prisma/packages/driver-adapter-utils/src/binder.ts:60:14 {
  prisma:driver-adapter:pg   length: 122,
  prisma:driver-adapter:pg   severity: 'ERROR',
  prisma:driver-adapter:pg   code: '08P01',
  prisma:driver-adapter:pg   detail: undefined,
  prisma:driver-adapter:pg   hint: undefined,
  prisma:driver-adapter:pg   position: undefined,
  prisma:driver-adapter:pg   internalPosition: undefined,
  prisma:driver-adapter:pg   internalQuery: undefined,
  prisma:driver-adapter:pg   where: undefined,
  prisma:driver-adapter:pg   schema: undefined,
  prisma:driver-adapter:pg   table: undefined,
  prisma:driver-adapter:pg   column: undefined,
  prisma:driver-adapter:pg   dataType: undefined,
  prisma:driver-adapter:pg   constraint: undefined,
  prisma:driver-adapter:pg   file: 'postgres.c',
  prisma:driver-adapter:pg   line: '1567',
  prisma:driver-adapter:pg   routine: 'exec_bind_message'
  prisma:driver-adapter:pg } +18ms

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

See related issue for Rust drivers only: #21802.


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
    bug/2-confirmed
    kind/bug
    on Nov 6, 2023
  2. changed the title [-]bug: `findMany` with two large `in` filters with arrays of `65536` items each results in no query chunking when using Driver Adapters[/-] [+]Driver Adapters: `findMany` with two large `in` filters with arrays of `65536` items each results in no query chunking when using Driver Adapters[/+] on Nov 6, 2023
  3. jkomyno commented on Nov 14, 2023

    @jkomyno
    ContributorAuthor

    Note: occasionally, the snippet above actually results in a different parameter count in the error message (see Slack thread):

    bind message has 5 parameter formats but 0 parameters

  4. changed the title [-]Driver Adapters: `findMany` with two large `in` filters with arrays of `65536` items each results in no query chunking when using Driver Adapters[/-] [+]Driver Adapters: `findMany()` with two large `in` filters with arrays of `65536` items each results in no query chunking when using Driver Adapters[/+] on Mar 27, 2024
  5. self-assigned this
    on Jul 15, 2024
  6. jkomyno commented on Jul 16, 2024

    @jkomyno
    ContributorAuthor

    For this issue, refer to the comment in #23957 (comment)

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions