Prepared statement contains too many placeholders – MySQL error
See original GitHub issueDiscussed in https://github.com/prisma/prisma/discussions/15508
<div type='discussions-op-text'>Originally posted by honzapav September 25, 2022
Hello, I have a query (see below), and I am getting an error: Prepared statement contains too many placeholders
. I understand that there are limits on the MySQL database, but I don’t know how to overcome them. What is the best practice in this case.
I use Prisma 4.3.1.
Thank you. H.
</div>The error message from redis
This query is implemented in NestJS API in Bull query. I got this message from redis. The query works as expected when I read less data (thousands of rows of shop_products).
{"failedReason":"\nInvalid `this.prisma.shop_project.findUnique()` invocation in\n\/Users\/honzapav\/Dev\/clients\/expando\/expando-lister\/src\/projects\/project-export.consumer.ts:39:52\n\n 36 @Process('export-project-job')\n 37 async exportProjectJob(job) {\n 38 console.log(`Job ${job.id} started`);\n→ 39 const project = await this.prisma.shop_project.findUnique(\nError occurred during query execution:\nConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError { code: 1390, message: \"Prepared statement contains too many placeholders\", state: \"HY000\" })) })","attemptsMade":"1","finishedOn":"1664094991735","priority":"0","name":"export-project-job","timestamp":"1664094877697","data":"{\"shopProjectId\":41}","processedOn":"1664094877787","delay":"0","stacktrace":"[\"Error: \\nInvalid `this.prisma.shop_project.findUnique()` invocation in\\n\/Users\/honzapav\/Dev\/clients\/expando\/expando-lister\/src\/projects\/project-export.consumer.ts:39:52\\n\\n 36 @Process('export-project-job')\\n 37 async exportProjectJob(job) {\\n 38 console.log(`Job ${job.id} started`);\\n→ 39 const project = await this.prisma.shop_project.findUnique(\\nError occurred during query execution:\\nConnectorError(ConnectorError { user_facing_error: None, kind: QueryError(Server(ServerError { code: 1390, message: \\\"Prepared statement contains too many placeholders\\\", state: \\\"HY000\\\" })) })\\n at RequestHandler.handleRequestError (\/Users\/honzapav\/Dev\/clients\/expando\/expando-lister\/node_modules\/@prisma\/client\/runtime\/index.js:29913:13)\\n at RequestHandler.request (\/Users\/honzapav\/Dev\/clients\/expando\/expando-lister\/node_modules\/@prisma\/client\/runtime\/index.js:29892:12)\\n at PrismaService._request (\/Users\/honzapav\/Dev\/clients\/expando\/expando-lister\/node_modules\/@prisma\/client\/runtime\/index.js:30864:16)\\n at ExportProjectConsumer.exportProjectJob (\/Users\/honzapav\/Dev\/clients\/expando\/expando-lister\/src\/projects\/project-export.consumer.ts:39:21)\"]","opts":"{\"attempts\":1,\"delay\":0,\"timestamp\":1664094877697}"}
The query
const project = await this.prisma.shop_project.findUnique({
where: { id: job.data.shopProjectId },
select: {
id: true,
shop_id: true,
project_code: true,
target_feed_id: true,
target_language_id: true,
target_feed_url: true,
created_at: true,
last_updated_at: true,
shop_category: {
where: {
OR: [{ category_status_id: 2 }, { category_status_id: 3 }],
},
select: {
category_library: {
select: {
natural_category_id: true,
},
},
shop_product: {
select: {
natural_product_id: true,
product_name: true,
shop_product_information: {
where: {
OR: [
{ product_information_status_id: 3 },
{ product_information_status_id: 2 },
],
},
select: {
item_information: {
select: {
item_information_name: true,
},
},
product_information_value: true,
},
},
shop_brand: {
where: {
OR: [{ brand_status_id: 2 }, { brand_status_id: 3 }],
},
select: {
target_brand_id: true,
},
},
},
},
shop_param: {
where: {
OR: [{ parameter_status_id: 2 }, { parameter_status_id: 3 }],
},
select: {
target_param_id: true,
shop_value: {
where: {
OR: [{ value_status_id: 2 }, { value_status_id: 3 }],
},
select: {
target_value: true,
},
},
},
},
},
},
},
});
Schema
Here is my schema (I removed unrelated tables):
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model category_library {
id Int @id @unique(map: "id") @default(autoincrement())
language_id Int
feed_id Int
natural_category_id String @db.VarChar(255)
name_origin_language String? @db.VarChar(255)
name String? @db.VarChar(255)
created_at DateTime @default(now()) @db.DateTime(0)
last_updated_at DateTime @default(now()) @db.DateTime(0)
language language @relation(fields: [language_id], references: [id], onDelete: NoAction, map: "category_library_ibfk_1")
feed feed @relation(fields: [feed_id], references: [id], onDelete: NoAction, map: "category_library_ibfk_2")
category_mall_menuitemid category_mall_menuitemid[]
category_parameter category_parameter[]
categorytext categorytext[]
h_i_target_product h_i_target_product[]
shop_category shop_category[]
@@unique([language_id, feed_id, natural_category_id], map: "one_entry")
@@index([feed_id], map: "feed_id")
@@index([language_id], map: "language_id")
@@index([name], map: "name")
@@index([natural_category_id], map: "natural_category_id")
@@index([natural_category_id, name, feed_id], map: "search_index")
}
model item_information {
id Int @id @unique(map: "id") @default(autoincrement())
item_information_name String? @db.VarChar(255)
h_i_target_information h_i_target_information[]
shop_product_information shop_product_information[]
}
model shop_brand {
id BigInt @id @unique(map: "id") @default(autoincrement()) @db.UnsignedBigInt
shop_product_id Int
natural_brand_name String? @db.Text
target_brand_id String? @db.Text
target_brand_name String? @db.Text
brand_status_id Int @default(1)
shop_product shop_product @relation(fields: [shop_product_id], references: [id], onDelete: Cascade, map: "shop_brand_ibfk_1")
item_status item_status @relation(fields: [brand_status_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "shop_brand_ibfk_2")
@@index([brand_status_id], map: "item_status_id")
@@index([shop_product_id], map: "shop_feed_item_id")
}
model shop_category {
id Int @id @unique(map: "id") @default(autoincrement())
shop_project_id Int
shop_product_id Int
categorytext String? @db.VarChar(1000)
target_category_id Int?
category_status_id Int @default(1)
created_at DateTime @default(now()) @db.DateTime(0)
last_updated_at DateTime @default(now()) @db.DateTime(0)
shop_project shop_project @relation(fields: [shop_project_id], references: [id], onDelete: Cascade, map: "shop_category_ibfk_1")
shop_product shop_product @relation(fields: [shop_product_id], references: [id], onDelete: Cascade, map: "shop_category_ibfk_2")
category_library category_library? @relation(fields: [target_category_id], references: [id], onUpdate: SetNull, map: "shop_category_ibfk_3")
item_status item_status @relation(fields: [category_status_id], references: [id], onDelete: SetDefault, map: "shop_category_ibfk_4")
shop_param shop_param[]
@@unique([shop_project_id, shop_product_id], map: "one_entry")
@@index([category_status_id], map: "item_status_id")
@@index([shop_project_id, target_category_id], map: "shop_feed_item_idx_shop_id_target_id")
@@index([shop_product_id], map: "shop_product_id")
@@index([target_category_id], map: "target_category_id")
}
model shop_param {
id Int @id @default(autoincrement())
shop_category_id Int?
origin_param_id String? @db.VarChar(255)
target_param_id String? @db.VarChar(255)
parameter_status_id Int @default(1)
is_mandatory Boolean?
created_at DateTime @default(now()) @db.DateTime(0)
last_updated_at DateTime @default(now()) @db.DateTime(0)
item_status item_status @relation(fields: [parameter_status_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "shop_param_ibfk_3")
shop_category shop_category? @relation(fields: [shop_category_id], references: [id], onDelete: Cascade, map: "shop_param_ibfk_5")
shop_value shop_value[]
@@unique([shop_category_id, origin_param_id], map: "one_entry")
@@unique([shop_category_id, target_param_id], map: "one_entry_target")
@@index([target_param_id], map: "idx_target")
@@index([parameter_status_id], map: "item_status_id")
@@index([origin_param_id], map: "origin_param_id")
}
model shop_product {
id Int @id @unique(map: "id") @default(autoincrement())
shop_id Int?
natural_product_id String @db.VarChar(255)
product_name String? @db.Text
is_deleted Boolean @default(false)
created_at DateTime @default(now()) @db.DateTime(0)
last_updated_at DateTime @default(now()) @db.DateTime(0)
last_imported_at DateTime? @db.DateTime(0)
shop shop? @relation(fields: [shop_id], references: [id], onDelete: Cascade, map: "shop_product_ibfk_1")
shop_brand shop_brand[]
shop_category shop_category[]
shop_product_information shop_product_information[]
@@unique([shop_id, natural_product_id], map: "one_entry")
@@index([natural_product_id], map: "product_id")
}
model shop_product_information {
id BigInt @id @unique(map: "id") @default(autoincrement()) @db.UnsignedBigInt
shop_project_id Int?
shop_product_id Int
product_information_type_id Int
product_information_value String? @db.LongText
product_information_status_id Int @default(2)
created_at DateTime @default(now()) @db.DateTime(0)
shop_product shop_product @relation(fields: [shop_product_id], references: [id], onDelete: Cascade, map: "shop_product_information_ibfk_1")
item_information item_information @relation(fields: [product_information_type_id], references: [id], onDelete: Cascade, map: "shop_product_information_ibfk_2")
item_status item_status @relation(fields: [product_information_status_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "shop_product_information_ibfk_3")
shop_project shop_project? @relation(fields: [shop_project_id], references: [id], onDelete: Cascade, map: "shop_product_information_ibfk_4")
@@unique([shop_project_id, shop_product_id, product_information_type_id, created_at], map: "one_entry")
@@index([product_information_type_id], map: "item_information_type_id")
@@index([product_information_status_id], map: "item_status_id")
@@index([shop_product_id], map: "shop_feed_item_id")
}
model shop_project {
id Int @id @unique(map: "id") @default(autoincrement())
shop_id Int
project_code String? @db.VarChar(255)
target_language_id Int
target_feed_id Int
target_feed_url String? @db.Text
export_feed_url String? @db.Text
created_at DateTime @default(now()) @db.DateTime(0)
last_updated_at DateTime @default(now()) @db.DateTime(0)
feed feed @relation(fields: [target_feed_id], references: [id], onDelete: NoAction, map: "shop_project_ibfk_3")
language language @relation(fields: [target_language_id], references: [id], onDelete: NoAction, map: "shop_project_ibfk_5")
shop shop @relation(fields: [shop_id], references: [id], onDelete: Cascade, map: "shop_project_ibfk_6")
shop_category shop_category[]
shop_log shop_log[]
shop_product_information shop_product_information[]
shop_request shop_request[]
@@index([shop_id], map: "shop_id")
@@index([target_feed_id], map: "target_feed_id")
@@index([target_language_id], map: "target_language_id")
}
model shop_value {
id Int @id @default(autoincrement())
shop_param_id Int
origin_param_value_id String? @db.VarChar(255)
origin_measure String? @db.VarChar(255)
target_value_id String? @db.VarChar(255)
target_value String? @db.VarChar(255)
target_measure String? @db.VarChar(255)
value_status_id Int @default(1)
created_at DateTime @default(now()) @db.DateTime(0)
last_updated_at DateTime @default(now()) @db.DateTime(0)
shop_param shop_param @relation(fields: [shop_param_id], references: [id], onDelete: Cascade, map: "shop_value_ibfk_2")
item_status item_status @relation(fields: [value_status_id], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "shop_value_ibfk_3")
@@index([value_status_id], map: "item_status_id")
@@index([shop_param_id], map: "origin_param_id")
@@index([target_value], map: "target_param_value_id")
@@index([shop_param_id, value_status_id], map: "unique_record")
}
Issue Analytics
- State:
- Created a year ago
- Comments:9 (5 by maintainers)
Top 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 >1390 Prepared statement contains too many ... - Laracasts
I am trying to import batch datas (excel) to my database table. But I am getting this error: 1390 Prepared statement contains too...
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 >mysql Error 1390: Prepared statement contains too ... - GitHub
Mysql has a limit of 65536 placeholders in each query. If you query for enough items you'll hit: Added error: (models: failed to...
Read more >Prepared statement contains too many placeholders - Laravel.io
Forum whereIn error: Prepared statement contains too many placeholders ... I have a simple query like this: $userIdLists = Users::whereIn('id', $ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@janpio Hello, please find the project dump here: https://drive.google.com/file/d/12z075ZkFTpIFO7PY0w_mChHqpjFbdbMg/view?usp=sharing.
It was quite easy to anonymize so I can share it. I have tested this dump, and the error persists. Please let me know if you have any further information. Many thanks!
fyi @janpio – tested today with prisma 4.4.0 and the problem persists.