Review 13.4 Merged

95496[BUGFIX] Reduce queries when indexing many-to-many relations

Benni Mack CR +2 V +2 Normal +114 −6 updated 08/31/26, 16:36

Commit message

ReferenceIndex::compileReferenceIndexRowsForRecord() fetched every
foreign side row of an MM relation on its own through
BackendUtility::getRecord(). That is one query per relation: A
sys_category assigned to 12000 records needs 12000 queries whenever
the reference index of that category is updated, which happens on
every save of a related record and takes seconds per category.

Fetch the rows per foreign table instead, chunked to keep the number
of predicates within the limits of the database platform.

Only four values of a foreign row are evaluated afterwards: The
disabled, starttime and endtime fields, plus t3ver_state. Select
those instead of all columns. The rows of all relations of a field
are held in memory at once, so "select *" of 12000 rows of a wide
table like tt_content costs roughly 150MB, while the restricted set
stays below 10MB.

Review

  • Code review CR +2 Done
    • Benni Mack +2
  • Verified V +2 Done
    • Benni Mack +2
    • core-ci +1 CI

Issues 2

Files 4

Review log 34

  1. Benni Mack commented on patch set 1 08/31/26, 16:23

    Cherry Picked from branch 14.3.
  2. core-ci voted on patch set 1 V +1 08/31/26, 16:31 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107436

  3. Benni Mack voted on patch set 1 CR +2 V +2 08/31/26, 16:36

  4. Benni Mack merged patch set 2 08/31/26, 16:36