Issue Bug Closed

#106563Mitigate not-consumed query buffer in `OptimizeDatabaseTableTask`

Stefan Bürk 04/12/25, 14:40 updated 12/02/25, 14:22

Description

Using `pdo_mysql` driver with `MySQL` and `MariaDB` databases
requires that buffered result sets are fully read or explicity
free’d. That means, that queries returning a result seet needs
to consum the full result set by reading all rows and not only
one record and leaving the rest in the buffer.

TYPO3 mitigates this in several places for select queries by
explicitly enforcing `setMaxResults(1)` when reading only one
record and it could be a duplicates, which is not an ideal or
reading the full result set.

The DDL `OPTIMIZE TABLE` for `MariaDB` and `MySQL` databases
returns a result stating the outcome of the operation and is
a buffered query, which requires to use `executeQuery()` and
not `executeStatement()` on the connection and fully consume
the result when using `pdo_mysql`. However, the `mysqli`
driver is more forgiven here.

TYPO3 v12 used the `Connection::query()` method using
`executeQuery()` internally, which means that it has
been replaced with the wrong method while upgrading to
Doctrine DBAL 4 with #102875 in TYPO3 v13.

Reviews 2