---
title: "What MySQL quietly does for you"
description: "MySQL forgives a lot that PostgreSQL and SQLite reject. What porting Shopware found: SqlDialect, hex ids, MySQL traps, core bugs and a store plugin scan."
url: "https://brocksi.net/blog/what-mysql-quietly-does-for-you/"
author: "Björn Meyer"
published: "2026-12-16"
lang: "en"
categories: ["Shopware 6", "Performance", "PHP"]
---

# What MySQL quietly does for you

Getting the Shopware core to run on MySQL, MariaDB, PostgreSQL and SQLite from the same code, as described in [part 1](https://brocksi.net/blog/shopware-on-postgresql-it-runs-should-it/), taught me more about MySQL than about any of the others. This part is about what I learned on the way, and most of it is not about PostgreSQL at all.

When you only ever run your SQL on one database, you pick up its habits without noticing. MySQL is a forgiving database. It guesses what you meant, picks an order when you did not ask for one and carries on after an error. Put a second, stricter database next to it and it works like a mirror: every place where the code quietly relied on MySQL’s goodwill turns into an error.

If you write SQL for Shopware, in the core or in a plugin, this part is for you. Most of it helps even if you never leave MySQL.

> **Note:** This is research on a proof-of-concept branch. Nothing here is a supported Shopware feature.

## First try: translate everything

My first idea was the lazy one: change nothing in Shopware and translate the SQL on its way to the database. Shopware talks to the database through Doctrine DBAL, and DBAL lets you plug in middlewares, small layers that see every statement before it is sent. So I put a translator there (MySQLToPostgreSQLTranslator) that rewrote MySQL into PostgreSQL, plus a set of SQL functions on the PostgreSQL side that imitate MySQL ones (mysql-compat.sql).

It worked surprisingly well. All 910 migrations ran, the admin API, storefront and checkout worked, and about 90 % of the integration tests in five areas passed.

But I would not want to maintain it. The translator reads SQL with regexes, so every new statement shape needs a new rule. Every further database needs its own translator. And it hides the differences instead of deciding them: the code that depends on a MySQL behaviour never learns that it does.

Still, it was worth building. It became the list of every difference we hit, and that list is what the rest of this post is made of.

## What works: let each database speak its own SQL

The better design moves the decision out of the wire and into the code that writes the SQL.

**One dialect per database.** A dialect is a small service that knows how its database spells things. There is one SqlDialect each for MySQL, MariaDB, PostgreSQL and SQLite, and Shopware picks the one that matches the connection. Ask it to “join these values into one string” and you get:

```sql
-- MySQL and MariaDB
GROUP_CONCAT(name ORDER BY name SEPARATOR ',')

-- PostgreSQL
string_agg((name)::text, ',' ORDER BY name)
```

Every method exists because a real difference needed it, so the classes stay small. The MariaDB one only extends the MySQL one and waits for the first real difference. The dialect is filed as an [issue for the core](https://github.com/shopware/shopware/issues/23318).

**Ids as plain hex strings.** Shopware stores ids as 16 raw bytes (binary(16)), and PHP code converts them by hand before and after a query. PostgreSQL has a real uuid type instead. In the new design the PHP code only ever sees hex strings, and one class, IdBinding, decides how to hand them to the database:

```mermaid
flowchart TB
    subgraph before["Before"]
        direction LR
        A1["PHP code<br/>converts ids to bytes"] -->|"16 bytes"| A2["Translator<br/>guesses which values are ids"]
        A2 -->|"uuid text"| A3[("PostgreSQL uuid")]
    end
    before ~~~ after
    subgraph after["After"]
        direction LR
        B1["PHP code<br/>hex strings only"] --> B2["IdBinding"]
        B2 -->|"MySQL, MariaDB, SQLite: 16 bytes"| B3[("binary(16)")]
        B2 -->|"PostgreSQL: hex text"| B4[("uuid")]
    end
```

Because IdBinding looks like the old Uuid helper, a Rector rule could rewrite most call sites automatically. The files that still bind ids as bytes went from 309 to 12.

**The translator stays, but only as a shim.** The 910 historic migrations and plugin code that still sends raw MySQL go through it. New core code should not need it.

## The traps

Here is what MySQL does for you without telling you. Each one is fine as long as you only run MySQL, and each one broke something on PostgreSQL or SQLite.

### MySQL picks a row for you

Group rows and select a column that is neither grouped nor aggregated, and MySQL returns the value of some row of the group. Which row is not defined. Shopware allows this on purpose: it turns ONLY\_FULL\_GROUP\_BY off for every connection. PostgreSQL refuses the query.

```sql
SELECT parent_id, product_number FROM product GROUP BY parent_id;
-- MySQL: some product_number of the group
-- PostgreSQL: column "product.product_number" must appear in the GROUP BY clause
--             or be used in an aggregate function
```

The fix: group by every selected column, or wrap it in an aggregate like MIN() when any value of the group will do.

### MySQL forgives a failed statement

Inside a transaction, a failed statement on MySQL fails alone. Code can catch the error and carry on. PostgreSQL marks the whole transaction as broken, and every following statement fails with current transaction is aborted until you roll back. Code that catches a duplicate key error and just continues works on MySQL, MariaDB and SQLite, and breaks on PostgreSQL. The fix: check before you write, or put the risky statement in a savepoint, so a failure rolls back only that statement.

### Where do empty values go?

Sort by name when some rows have no name. MySQL treats NULL as the smallest value, so those rows come first in ascending order. PostgreSQL treats it as the largest, so they come last. Neither is wrong. Further down you will see what that does to the admin.

### Müller or muller?

The collation Shopware uses on MySQL, utf8mb4\_unicode\_ci, ignores case and accents. Search for `muller` and you find `Müller`. SQLite does not, and PostgreSQL does not either with the fast lower() comparison. Did anyone decide that the search should ignore accents? Nobody did. MySQL decided it.

### The order inside SET

In an UPDATE, MySQL runs the assignments from left to right, so a later one sees the new value of an earlier one. Standard SQL computes every assignment from the old row. Below you will see why that matters for stock.

### The same key twice

A multi-row upsert (INSERT … ON DUPLICATE KEY UPDATE) that contains the same key twice works on MySQL: the rows are applied in order and the last one wins. PostgreSQL rejects the whole statement with ON CONFLICT DO UPDATE command cannot affect row a second time. The fix: merge rows with the same key before you build the statement.

### Guessing types when parameters aren’t typed

PHP’s SQLite driver sends floats as text. SQLite then compares price <= :value as a number against a text. In SQLite a number always sorts before any text, so the result does not depend on the values at all. MySQL converts the text to a number for you.

That one has a nasty cousin. While the translator still guessed which 16-byte values were ids, an id that happened to be valid UTF-8 was sent as text, and PostgreSQL rejected it with invalid input syntax for type uuid. That happens to about 1 in 11,000 random ids, so the write failed at random. Only stating the type up front fixes it, which is one more reason for IdBinding.

## Three worth fixing on MySQL anyway

Most traps above are “only” a problem when you switch databases. These three are worth fixing even if you never do.

**Stock that is right by accident.** When an order changes stock, StockStorage::alter() runs this:

```sql
UPDATE product
SET stock = stock + :quantity, sales = sales - :quantity, available_stock = stock, updated_at = NOW()
```

available\_stock = stock only gets the new stock because MySQL works left to right. On standard SQL it silently keeps the old value. The code is correct on MySQL by accident. The fix has to work on both: compute available\_stock = stock + :quantity and put it before stock = stock + :quantity. Only change the expression and leave it at the end, and MySQL adds the quantity twice.

```sql
UPDATE product
SET available_stock = stock + :quantity, stock = stock + :quantity, sales = sales - :quantity, updated_at = NOW()
```

**The NULL order decides which products you see.** The DAL never says where empty values go. In the catalog test data, 834 of 1,916 product translation rows have no name. Sort the admin product search by name, and MariaDB showed 25 nameless variants first, while PostgreSQL with its default order showed named products. The proof of concept now forces MySQL’s order on PostgreSQL to get the same page. That is the pattern I saw most: not a bug, but a decision nobody made because MySQL made it for us.

**A hidden query per row.** This one surprised me most, because PostgreSQL did not show it, it hid it. Before Shopware writes a product, it checks which rows already exist. It loaded that state up front in one go, with the ids as hex, but then looked it up with the wrong key (EntityWriteGateway::getCurrentState()). It passed the column name (version\_id) to a lookup that expects the property name (versionId), so the id was never decoded and stayed raw bytes. The lookup missed every time, so Shopware asked the database again, row by row. In a benchmark that creates and updates 50 products on MySQL and MariaDB, 248 of 371 statements were these extra checks. With the fix it runs 121 statements in 60 ms instead of 371 in 88 ms. PostgreSQL never had the problem, because its ids were already hex. The fix is [already merged into Shopware](https://github.com/shopware/shopware/issues/23305).

## The findings for the core

Altogether the project collected 50 findings for the core: 8 bugs, 17 robustness issues, 12 performance issues, 10 portability items and a few ideas. I turned them into 37 issues. These are the ones behind this post, with their status on 2 December 2026:

- [Natural sorting in a grouped query sorts by a non-aggregated column](https://github.com/shopware/shopware/issues/23288): the first trap, in real code. Fix in review.
- [Replace session variable row counting with ROW\_NUMBER()](https://github.com/shopware/shopware/issues/23291): MySQL 8 deprecates the trick the DAL uses today. Fix in review.
- [LockValidator uses rowCount() after a SELECT](https://github.com/shopware/shopware/issues/23297): MySQL happens to return a count there, SQLite does not. Fix in review.
- [Date custom field filters cast the column but not the value](https://github.com/shopware/shopware/issues/23299). Fix in review.
- [Do not continue a transaction after a failed statement without a savepoint](https://github.com/shopware/shopware/issues/23292). Open.
- [State the NULL order of FieldSorting in the SQL](https://github.com/shopware/shopware/issues/23294). Open.
- [Decide and test whether string filters are accent-insensitive](https://github.com/shopware/shopware/issues/23296). Open.

I filed them on 23 November. Nine days later, one fix is merged and four more are in review. That is faster than I expected. The [full list of findings](https://github.com/BrocksiNet/shopware-db-independent/blob/main/docs/core-findings.md) has the source for each one, and the issue where one is filed. If an open one touches code you know, a pull request is very welcome.

## What this means for plugins

The core is one thing, but most shops also run plugins. So I scanned the code of every Shopware 6 plugin in the store, as of 2 October 2026, and sorted each plugin by the worst thing it does:

| What the plugin does | Share |
| --- | --- |
| No PHP files | 0.2 % |
| PHP, but no SQL of its own | 45.2 % |
| Own SQL, nothing MySQL-specific | 2.5 % |
| MySQL-specific SQL the shim can translate | 12.7 % |
| MySQL-only migrations, otherwise translatable | 29.9 % |
| SQL the shim cannot translate | 9.4 % |

In short: more than half of all plugins write their own SQL, and about one in ten does something no translator handles yet. The most common case is a check against information\_schema with TABLE\_SCHEMA = DATABASE(), and it fails silently on PostgreSQL. Apps, the other extension type in the store and not part of this table, are not affected at all: they contain no PHP and no SQL.

Two limits: the scan matches patterns in code, so it shows that a construct exists, not that it runs. And it counts plugins, not installations.

So a translation shim would have to live as long as those plugins do, for several release cycles with deprecation warnings. If you build plugins, I would not wait for any of this to start cleaning up, because every point below also makes your plugin more robust on MySQL:

- **Use the DAL where you can.** More than one in five plugins (22.8 %), about half of the “no SQL of its own” group above, already use only the DAL, and they would get database independence for free.
- **Bind ids with a type.** Pass ArrayParameterType::BINARY or ParameterType::BINARY instead of relying on a default string binding.
- **Don’t query information\_schema to check your own schema.** Use DBAL’s schema manager.
- **Say what you rely on.** Group by every selected column, sort with a tie-breaker and don’t assume that a LIKE ignores accents.
- **Don’t catch a failed statement and carry on in the same transaction.** Check first, or use a savepoint.

## SQLite: the proof that the abstraction holds

PostgreSQL alone could have been a special case. So SQLite was the stress test: if the same dialect design also carries a very different, embedded database, the abstraction is real.

It does. scripts/switch-db.sh sqlite installs Shopware, indexes it and passes all 8 smoke requests, including an admin write and a checkout, in 32.9 seconds. 795 of the 804 DAL integration tests pass. Most of the rest is about formatting, like ‘250.0000’ against ‘250’.

SQLite allows only one writer at a time, has no accent-insensitive collation and its ALTER TABLE limits (no column change, no added constraint, no primary key change) mean migrations must be rewritten for SQLite, sometimes with a full table rebuild. So it is a candidate for throwaway local setups and single-process CI, not for production.

## TL;DR

- Translating MySQL on the fly finds the differences fast, but it is not a design. One SqlDialect per database plus hex ids with one binding class is.
- MySQL forgives a lot: lenient GROUP BY, failed statements in transactions, a NULL order the code never states, accent-insensitive search, left-to-right SET and duplicate keys in one upsert.
- Some of that is a real bug on MySQL today, like 248 hidden queries for 50 products. One fix is already merged.
- More than half of all store plugins (about 55 %) write their own SQL, 9.4 % use constructs no shim handles. Apps are not affected.
- SQLite passes 795 of 804 DAL tests on the same abstraction. Good for local setups and CI, not for production.

Next up in part 3: closing the performance gap between PostgreSQL and MariaDB, and why I stopped trusting single benchmark runs.
