Skip to content

adapter-mariadb 7.5.0: prepared statement leak after switch to binary protocol #29364

Closed

Description

@niroschwartz

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,294 vs Com_stmt_close = 3,279,759 (massive gap)
  • performance_schema.prepared_statements_instances shows the same Prisma-generated
    query repeated 300+ times
  • Queries confirmed to be Prisma-style SQL (backtick-quoted identifiers, AND 1=1 pattern)
  • performance_schema.threads confirms all statements come from Node.js connections
  • Did not happen on 7.3.0 — only after upgrading to 7.5.0

How to reproduce

  1. Use @prisma/adapter-mariadb 7.5.0 with the mariadb Node.js driver
  2. Run a workload with many Prisma queries (especially varying IN clause sizes)
  3. Monitor: SHOW GLOBAL STATUS LIKE 'Com_stmt%' and
    SELECT COUNT(*) FROM performance_schema.prepared_statements_instances
  4. Observe Prepared_stmt_count growing continuously until it hits max_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-mariadb to 7.3.0 (uses text protocol, no prepared statements)
  • Set prepareCacheLength: 0 on the mariadb pool config to disable caching

Environment

  • @prisma/adapter-mariadb: 7.5.0
  • @prisma/client: 7.5.0
  • mariadb (Node.js driver): 3.5.2
  • Database: MariaDB (RDS)

Related

Activity

  1. added
    bug/1-unconfirmed
    kind/bug
    on Mar 23, 2026
  2. jacek-prisma commented on Mar 23, 2026

    @jacek-prisma
    Contributor

    Thanks for submitting the issue!

    Evicted statements are not reliably closed via COM_STMT_CLOSE on the server,

    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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions