Repository navigation
Description
Bug description
After upgrading @prisma/adapter-mariadb from 7.3.0 to 7.5.0, prepared statements accumulate
unboundedly in MySQL/MariaDB, eventually hitting max_prepared_stmt_count.
7.5.0 switched the adapter from text protocol (.query()) to binary protocol
(.execute() / COM_STMT_PREPARE) in PR #29285 to fix lossy number conversions.
This means every query now creates a server-side prepared statement.
The mariadb Node.js driver caches prepared statements per connection
(prepareCacheLength defaults to 256). Because Prisma generates many distinct SQL strings
(e.g. varying IN (?) clause sizes), the cache fills with unique entries.
Evicted statements are not reliably closed via COM_STMT_CLOSE on the server,
causing prepared_statements_instances to grow indefinitely.
Evidence from production
max_prepared_stmt_count = 16382(hit the limit)Com_stmt_prepare = 40,802,294vsCom_stmt_close = 3,279,759(massive gap)performance_schema.prepared_statements_instancesshows the same Prisma-generated
query repeated 300+ times- Queries confirmed to be Prisma-style SQL (backtick-quoted identifiers,
AND 1=1pattern) performance_schema.threadsconfirms all statements come from Node.js connections- Did not happen on 7.3.0 — only after upgrading to 7.5.0
How to reproduce
- Use
@prisma/adapter-mariadb7.5.0 with themariadbNode.js driver - Run a workload with many Prisma queries (especially varying
INclause sizes) - Monitor:
SHOW GLOBAL STATUS LIKE 'Com_stmt%'and
SELECT COUNT(*) FROM performance_schema.prepared_statements_instances - Observe
Prepared_stmt_countgrowing continuously until it hitsmax_prepared_stmt_count
Expected behavior
Prepared statements should be closed after use (COM_STMT_CLOSE), or the adapter
should continue using text protocol (.query() / COM_QUERY) which worked correctly in 7.3.0.
Workarounds
- Pin
@prisma/adapter-mariadbto 7.3.0 (uses text protocol, no prepared statements) - Set
prepareCacheLength: 0on the mariadb pool config to disable caching
Environment
@prisma/adapter-mariadb: 7.5.0@prisma/client: 7.5.0mariadb(Node.js driver): 3.5.2- Database: MariaDB (RDS)
Related
- PR fix: use mysql binary protocol to avoid a lossy conversion #29285 (switched adapter to binary protocol)
- Ballooning of Prepared_stmt_count on MYSQL #6872 (historical prepared statement ballooning)
- mysql: Leaking of prepared statements when using opentelemetry #18975 (prepared statement leak with OpenTelemetry)
Activity
jacek-prisma commentedon Mar 23, 2026
Thanks for submitting the issue!
If this is indeed the case then it appears to be a bug in the MariaDB NodeJS driver and it might be best to create an issue there. On Prisma side I think it's worth to keep both options, using the cache and opting out of it via
prepareCacheLength: 0(which should already work as expected).Depending on severity of this we might want to change the default behavior not to cache statements
feat: mariadb protocol options (#29392)
feat(adapter-mariadb): support passing a pool instance (#27992)
feat(adapter-mariadb): support passing a pool instance (prisma#27992)
fix(server): DATABASE_URL refuses TLS params; Prisma 5 pool size; no …
fix(server): DATABASE_URL refuses TLS params; Prisma 5 pool size; no …