Skip to content

fix: MySQL introspection failing on MariaDB servers#1547

Merged
sorenbs merged 2 commits into
mainfrom
fix/1367-mariadb-introspection
Jul 18, 2026
Merged

fix: MySQL introspection failing on MariaDB servers#1547
sorenbs merged 2 commits into
mainfrom
fix/1367-mariadb-introspection

Conversation

@sorenbs

@sorenbs sorenbs commented Jul 18, 2026

Copy link
Copy Markdown
Member

Fixes #1367, fixes #1511

Root cause

The tables-introspection query aggregates column metadata with cast(coalesce(json_arrayagg(json_object(...)), '[]') as json). This breaks on MariaDB two ways:

Fix

  • The adapter detects the server flavor once per instance via select version() (matches MariaDB case-insensitively, incl. 5.5.5-…-MariaDB prefixed strings; detection failure falls back to the MySQL SQL).
  • On MariaDB, aggregation uses coalesce(concat('[', group_concat(json_object(...) separator ','), ']'), '[]') — valid on all supported MariaDB versions.
  • New normalizeTablesQueryResult() parses string columns payloads for all flavors (transport-agnostic; equivalent to the JS-side hardening proposed in fix mysql introspection json columns #1495, which this supersedes at the SQL level).

Verification

  • End-to-end against real MariaDB 10.4 and 10.11 Docker containers: introspection succeeds with correct tables, PKs, autoincrement, enum options, FKs, generated columns, and timezone.
  • pnpm test:data:mysql against local Vitess/MySQL: 38/38 pass — the MySQL SQL path is byte-identical (snapshot-asserted).
  • 18 new unit tests (flavor detection, SQL branching, string-payload parsing, caching); typecheck/lint clean; changeset included.

🤖 Generated with Claude Code

Studio's tables introspection aggregated column metadata with
json_arrayagg, which does not exist before MariaDB 10.5 (#1511)
and returns LONGTEXT rather than native JSON on any MariaDB version, while
cast(... as json) is invalid syntax there (#1367).

The MySQL adapter now detects the server flavor once per adapter via
select version() and, on MariaDB, aggregates columns with
coalesce(concat('[', group_concat(json_object(...) separator ','), ']'), '[]')
instead. String-aggregated columns payloads are parsed back into arrays on
the client, which also hardens introspection against MySQL transports that
return json_arrayagg results as strings. Version detection failures fall
back to the existing MySQL SQL.

Verified end-to-end against MariaDB 10.4 and 10.11 containers and the
Vitess-backed MySQL integration suite.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 35 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3230a369-fe24-4917-85f6-071a0c274438

📥 Commits

Reviewing files that changed from the base of the PR and between 6f30bcc and 9eccabc.

📒 Files selected for processing (5)
  • .changeset/mariadb-introspection-compat.md
  • FEATURES.md
  • data/mysql-core/adapter.ts
  • data/mysql-core/introspection.mariadb.test.ts
  • data/mysql-core/introspection.ts

Walkthrough

The MySQL adapter now queries select version() to detect MariaDB, caches the detected flavor, and uses MariaDB-compatible group_concat(json_object(...)) aggregation when needed. MySQL continues using json_arrayagg. Introspection results now parse stringified column payloads and validate their shape. New tests cover query generation, detection, fallback, caching, normalization, and end-to-end adapter behavior. Documentation and a patch changeset describe the compatibility update.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing MariaDB introspection in the MySQL adapter.
Description check ✅ Passed The description is directly about the MariaDB introspection fix and matches the changeset.
Linked Issues check ✅ Passed The changes address both linked issues by supporting MariaDB and avoiding unsupported JSON_ARRAYAGG/CAST syntax.
Out of Scope Changes check ✅ Passed The diff stays focused on MariaDB introspection, tests, and docs with no obvious unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1367-mariadb-introspection
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/1367-mariadb-introspection

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

Compute preview deployed.

Branch: fix/1367-mariadb-introspection
Service: fix-1367-mariadb-introspection
Preview: https://bt531yo412kotfh8jad24z8s.cdg.prisma.build

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

CodeRabbit couldn't request changes on this pull request because it doesn't have sufficient GitHub permissions.

Please grant CodeRabbit Pull requests: Read and write permission and re-run the review.

👉 Steps to fix this

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@data/mysql-core/introspection.ts`:
- Around line 172-179: The MariaDB branch in the aggregated query must not use
group_concat, because group_concat_max_len can truncate column metadata. Replace
this aggregation with a non-truncating path that returns one row per column and
groups results client-side, or an equivalent approach independent of the session
cap, while preserving normalizeTablesQueryResult behavior. Add a regression test
covering a metadata payload larger than the default 1 MB limit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0496bcf5-f900-4973-a8e5-4c087ef75d75

📥 Commits

Reviewing files that changed from the base of the PR and between 81354ff and 6f30bcc.

📒 Files selected for processing (5)
  • .changeset/mariadb-introspection-compat.md
  • FEATURES.md
  • data/mysql-core/adapter.ts
  • data/mysql-core/introspection.mariadb.test.ts
  • data/mysql-core/introspection.ts

Comment thread data/mysql-core/introspection.ts Outdated
Addresses PR review feedback: the group_concat-based aggregation was capped
by the session's group_concat_max_len (1MB default on MariaDB, sometimes
configured much lower), which could silently truncate the JSON payload on
very wide tables.

The MariaDB flavor now uses a dedicated tables query
(getMariaDBTablesQuery) that returns one row per column with no JSON
functions and no aggregation at all, and groupMariaDBTablesQueryResult
groups the rows into the aggregated shape on the client. This is immune to
any aggregation size cap and works on every MariaDB version. The MySQL
tables query is restored to its original json_arrayagg form.

Includes a regression test grouping over 1MB of column metadata, and was
verified against MariaDB 10.4/10.11 containers including with
group_concat_max_len lowered to 128 bytes.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sorenbs
sorenbs merged commit df3f210 into main Jul 18, 2026
3 checks passed
@sorenbs
sorenbs deleted the fix/1367-mariadb-introspection branch July 18, 2026 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prisma studio error: FUNCTION pomagamy.json_arrayagg does not exist Support MariaDB.

1 participant