Repository navigation
Conversation
Record auto-increment column names during snapshot export and pass them to the existing sequence reset helper when restoring rows. Skip sequence resets for tables without an auto-increment column. This avoids repeated PostgreSQL catalog queries and restores generated IDs correctly for quoted mixed-case columns. Add functional coverage for ordinary and custom ID columns, repeated restores and non-sequence tables. A local PostgreSQL 17 benchmark of SlugLinkGeneratorTest drops from 46.93 s to 42.37 s with the same 194 tests and 202 assertions. The number of sequence catalog lookups drops from 2,123 to zero. WIP: prepared for CI validation.
sbuerk
left a comment
There was a problem hiding this comment.
Thanks Wouter, skipping the catalog lookup on every restore makes a lot of sense.
I reviewed the change and ran it against PostgreSQL 17, MariaDB 10.11 and SQLite. Summary:
What works
- The mixed-case fix is real. On
mainthe data set "quoted mixed-case column" fails on PostgreSQL withrelation "public.tx_testingframework_sequence_entryid_seq" does not exist, because the old path passes an unquoted sequence name tosetval().pg_get_serial_sequence()takes the column name literally, so the PR fixes that. - Changing the export format is safe.
DatabaseSnapshotkeeps the export in memory for one test case, and SQLite snapshots are file copies, so an export withoutautoIncrementColumnNamecan never be imported. - The tests pass on all three platforms with the PR code.
- A quick probe (4 tables with 20 rows each, 50 restores, PostgreSQL 17) shows the import going from 111.5 ms to 101.1 ms on average, which matches your ~10 %.
Regression: SERIAL columns on PostgreSQL (see inline comment)
DBAL 4 and TYPO3's own PostgreSQLSchemaManager only report autoincrement for identity columns (attidentity = 'd'). A table with a classic SERIAL column now gets no sequence reset after a restore, and the next generated insert collides with the restored IDs. main handles that through the catalog lookup.
Blocker: the new functional test is never executed
Same as in #758: this repository has no functional suite. Build/phpunit/ only has UnitTests.xml, runTests.sh only knows -s unit, CI runs unit tests only, and the Core does not pick up vendor tests. Running it directly stops in bootstrap with Unable to determine path to entry script ... 'TYPO3_PATH_ROOT'. So CI only shows that the file lints and passes PHPStan. I'd like to add a functional suite (phpunit config, runTests.sh -s functional with database containers and the Core's not-<dbms> exclude groups, CI job) in a separate PR first, and then rebase this one and #758 on top. Nice side note: this test is platform agnostic and needs no groups at all.
Further points
- The commit body ends with
WIP: prepared for CI validation., which is not in the PR description and should not land. - Two body lines are longer than 72 characters ("ordinary and custom ID columns, ..." and "46.93 s to 42.37 s with the same ..."). Footer
Releases: main, 10is missing. - Please run the Core functional suite on PostgreSQL with this change, as
CONTRIBUTING.rstasks, and add the result (tests and assertions, same as without the change) to the description.
Not mergeable yet from my side because of the SERIAL regression, the commit message and the missing functional suite wiring.
| } | ||
| $autoIncrementColumnName = null; | ||
| foreach ($table->getColumns() as $column) { | ||
| if ($column->getAutoincrement()) { |
There was a problem hiding this comment.
On PostgreSQL getAutoincrement() is only true for identity columns: 'autoincrement' => $tableColumn['attidentity'] === 'd' in DBAL 4.4 and in TYPO3\CMS\Core\Database\Schema\SchemaManager\PostgreSQLSchemaManager. A SERIAL column is not detected, so importTable() skips the reset and the sequence keeps its old position.
Reproduced on PostgreSQL 17:
$connection->executeStatement('CREATE TABLE tx_probe_serial (uid SERIAL PRIMARY KEY, title VARCHAR(20))');
$connection->insert('tx_probe_serial', ['uid' => 1, 'title' => 'a']);
$connection->insert('tx_probe_serial', ['uid' => 2, 'title' => 'b']);
$snapshot = $subject->export();
$connection->executeStatement('TRUNCATE tx_probe_serial RESTART IDENTITY');
$subject->import($snapshot);
$connection->insert('tx_probe_serial', ['title' => 'generated']);
// PR: SQLSTATE[23505] duplicate key value violates unique constraint "tx_probe_serial_pkey"
// main: uid 3The TYPO3 schema itself uses identity columns since DBAL 4, so the default tables are fine. But tests and extensions creating tables with raw SQL still use SERIAL a lot (the tests in #758 do), and on main this works.
Suggestion that keeps the gain: on PostgreSQL resolve the owned sequence column once in export() (which runs once per test case) with one catalog query for all tables, for example pg_depend with deptype IN ('a', 'i') joined to pg_attribute. That covers SERIAL and identity columns, and import() stays free of catalog lookups. Please add a SERIAL data set to the test as well.
| use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Snapshot\DatabaseAccessor; | ||
| use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase; | ||
|
|
||
| final class DatabaseAccessorSequenceTest extends FunctionalTestCase |
There was a problem hiding this comment.
As mentioned in the summary: nothing in this repository executes Tests/Functional/. With a manual harness it passes for me on PostgreSQL 17, MariaDB 10.11 and SQLite, and on main it fails on PostgreSQL for the mixed-case data set, so the test is good. It just isn't run by CI yet.
| $connection->insert($table->getName(), [$columnName => 7, 'title' => 'first']); | ||
| $connection->insert($table->getName(), [$columnName => 11, 'title' => 'last']); | ||
| $subject = new DatabaseAccessor($connection); | ||
| $snapshot = json_decode(json_encode($subject->export(), JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR); |
There was a problem hiding this comment.
Nit: DatabaseSnapshot keeps the export as a PHP array in memory and only uses json_encode() for the size check, so this round trip is not what happens in production and suggests that snapshots get serialized. Passing $subject->export() directly (same in line 82) mirrors DatabaseSnapshot::create() and restore().
Record auto-increment column names during snapshot export and pass them to the existing sequence reset helper when restoring rows. Skip sequence resets for tables without an auto-increment column.
This avoids repeated PostgreSQL catalog queries and restores generated IDs correctly for quoted mixed-case columns. Add functional coverage for ordinary and custom ID columns, repeated restores and non-sequence tables.
A local PostgreSQL 17 benchmark of SlugLinkGeneratorTest drops from 46.93 s to 42.37 s with the same 194 tests and 202 assertions. The number of sequence catalog lookups drops from 2,123 to zero.