question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prepared statement contains too many placeholders

See original GitHub issue

Bug description

When creating many 1000s of rows (in my case also inside a transaction) in a MySQL database we hit:

ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError { code: 1390, message: "Prepared statement contains too many placeholders", state: "HY000" })) })

I don’t think these is an obvious workaround in the Prisma ecosystem.

How to reproduce

You can reproduce this with a large Prisma transaction given your available schema.

In my case this looks like:

const results = await this.prisma.$transaction([
  this.prisma.parent.update(/** ... */)
  this.prisma.child1.createMany(/** ... */),
  this.prisma.child1.deleteMany(/** ... */),
  this.prisma.child2.createMany(/** ... */),
  this.prisma.child2.deleteMany(/** ... */),
]);

Expected behavior

I think this is more like a feature request, but I’d expect the createMany or$transaction to allow some opportunity to support a batchSize / chunkSize / transactionChunk, like for example Knex BatchInsert or Sequelize Batch Create

Prisma information

Environment & setup

  • OS: Mac OS
  • Database: MySQL 8
  • Node.js version: v12.18.1

Prisma Version

prisma               : 2.26.0
@prisma/client       : 2.26.0
Current platform     : darwin
Query Engine         : query-engine 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules/@prisma/engines/query-engine-darwin)
Migration Engine     : migration-engine-cli 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary        : prisma-fmt 9b816b3aa13cc270074f172f30d6eda8a8ce867d (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : 9b816b3aa13cc270074f172f30d6eda8a8ce867d
Studio               : 0.408.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
janpiocommented, Nov 16, 2021

This has been fixed in Prisma 3.4.0. You will need to upgrade to benefit from this improvement.

1reaction
MichalLytekcommented, Sep 27, 2021

I have the same error with a single update call:

await prisma.segmentData.update({
  where: { id: segmentId },
  data: {
    lastActiveAt: new Date(),
    customers: { disconnect: { id: customerId } },
  },
});

This is my model:

model SegmentData {
  id               Int                     @id @default(autoincrement()) @db.UnsignedInt
  storeId          Int                     @db.UnsignedInt
  name             String?                 @db.VarChar(255)
  segmentType      SegmentData_segmentType
  lastActiveAt     DateTime                @db.DateTime(0)
  blueLinkId       Int?                    @db.UnsignedInt
  isDynamic        Boolean                 @default(false)
  blueLink         BlueLink?               @relation(fields: [blueLinkId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "fk_SegmentData_BlueLink1")
  store            Store                   @relation(fields: [storeId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "fk_SegmentData_Store1")
  campaignSegments CampaignSegment[]
  filters          SegmentFilter[]
  customers        Customer[]              @relation("CustomerToSegment")
  autoPilotTasks   AutoPilotTask[]         @relation("SegmentToAutoPilotTask")

  @@unique([storeId, segmentType, blueLinkId], map: "segmentStoreTypeBlueLink_UNIQUE")
  @@index([blueLinkId], map: "fk_SegmentData_BlueLink1")
}

This is the error:

Invalid `prisma.segmentData.update()` invocation:

  Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError { code: 1390, message: "Prepared statement contains too many placeholders", state: "HY000" })) })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Import of 50K+ Records in MySQL Gives General error: 1390 ...
Import of 50K+ Records in MySQL Gives General error: 1390 Prepared statement contains too many placeholders · If you import let´s say 100...
Read more >
Too many placeholders - Laracasts
the error message "Prepared statement contains too many Placeholders" is clear, the values you provide in the query is less than the placeholders...
Read more >
Prepared statement contains too many placeholders in Preload
The error is Error 1390: Prepared statement contains too many placeholders. best would be if large where in querys get chunked.
Read more >
101630: Consider increasing placeholder limit to be > 64k
Description: I see this error message in Orchestrator: Error 1390: Prepared statement contains too many placeholders.
Read more >
General Error 1390 Prepared statement contains too many ...
It's not the real solution but an instruction to use it wisely. There is a limit of 65,535 (2^16-1) placeholders in MySQL. So...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found