Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findUnique() batching exceeding parameter binding limits #23957

Open
chris-basis opened this issue Apr 24, 2024 · 0 comments
Open

findUnique() batching exceeding parameter binding limits #23957

chris-basis opened this issue Apr 24, 2024 · 0 comments
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: batching topic: findUnique() topic: postgresql

Comments

@chris-basis
Copy link

chris-basis commented Apr 24, 2024

Bug description

While querying large datasets leveraging findUnique to prevent GraphQL N+1s, we're experiencing parameter binding errors due to the amount of bound parameters created in the batched query.

This causes the graphql query hitting these resolvers to fail.

Error:

prisma.account.findUnique(
  Assertion violation on the database: `too many bind variables in prepared statement, expected maximum of 32767, 
  received 150656`

How to reproduce

  1. With over 33000 rows in the table you're querying
  2. Perform 33000 individual entity.findUnique() queries in a Promise.all, simulating a large GQL N+1
  3. Expect parameter binding error after surpassing your Postgres variable binding limit.

Expected behavior

Potentially split queries that would exceed the bound param limit into multiple batches.

Prisma information

Schema: Unrelated

Code:

    const accountIds = await prisma.account
        .findMany({
            select: { id: true },
            where: {
                companyId: redacted,
            },
        })
        .then((result) => result.map(({ id }) => id));

    await Promise.all(
        accountIds.map((id) =>
            prisma.account.findUnique({
                where: {
                    id,
                },
            })
        )
    );

Environment & setup

  • OS: macOS, Windows, Debian, CentOS
  • Database: PostgreSQL
  • Node.js version: v20.11.1

Prisma Version

prisma                  : 5.7.1
@prisma/client          : 5.7.1
Computed binaryTarget   : darwin
Operating System        : darwin
Architecture            : x64
Node.js                 : v20.11.1
Query Engine (Node-API) : libquery-engine 0ca5ccbcfa6bdc81c003cf549abe4269f59c41e5 (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Schema Engine           : schema-engine-cli 0ca5ccbcfa6bdc81c003cf549abe4269f59c41e5 (at node_modules/@prisma/engines/schema-engine-darwin)
Schema Wasm             : @prisma/prisma-schema-wasm 5.7.1-1.0ca5ccbcfa6bdc81c003cf549abe4269f59c41e5
Default Engines Hash    : 0ca5ccbcfa6bdc81c003cf549abe4269f59c41e5
Studio                  : 0.495.0
Preview Features        : metrics, relationJoins
@chris-basis chris-basis added the kind/bug A reported bug. label Apr 24, 2024
@janpio janpio changed the title FindUnique batching exceeding parameter binding limits findUnique() batching exceeding parameter binding limits Apr 25, 2024
@janpio janpio added bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. team/client Issue for team Client. topic: findUnique() topic: batching topic: postgresql labels Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. kind/bug A reported bug. team/client Issue for team Client. topic: batching topic: findUnique() topic: postgresql
Projects
None yet
Development

No branches or pull requests

2 participants