#111268SuggestWizardDefaultReceiver::queryTable() exhausts memory when maxItemsInResultList is high
Description
Problem
Searching in the suggest wizard of a group field runs into PHP’s memory limit when
@maxItemsInResultList@ is set well above 50 and the search term matches 50 or more
records. Terms with fewer than 50 matches work.
Steps to reproduce
Verified on a fresh cms-base-distribution v14.3.10 (SQLite, no extensions):
- Create 122 content elements on page 1 whose header contains “ter” (e.g. “Water 1” to
“Water 122”) and 22 whose header contains “obe” (e.g. “Globe 1” to “Globe 22”). - Set page TSconfig on page 1:
TCEFORM.tt_content.records.suggest.default.maxItemsInResultList = 9999
- Create a content element of type “Insert records” on page 1 and search “ter” in the
suggest field of “Items”.
Expected
The suggest list shows the matching records.
Actual
- Searching “obe” (22 matches) returns all 22 records.
- Searching “ter” (122 matches) fails after a few seconds with
“Allowed memory size of 134217728 bytes exhausted” (memory_limit = 128M). - With memory_limit = 512M, SQLite fails instead with
“General error: 1 Expression tree is too large (maximum depth 1000)”, which shows
the WHERE clause growing on every call. - With maxItemsInResultList = 50, “ter” returns 50 records and uses 26 MB.
Cause
queryTable() fetches 50 rows per call and calls itself for the next page
(SuggestWizardDefaultReceiver.php#L185):
if (count($rows) < $this->maxItems && $allRowsCount >= $maxQueryResults && $recursionCounter < $this->maxItems) {
Three things combine:
- The recursion does not stop when the results run out.
$allRowsCountis the total
number of matches and does not change between calls, and$rowsonly holds the
current page. Once the matches are used up, every further call returns no rows and
still calls itself again, until$recursionCounterreachesmaxItems. - The call limit is compared with the item limit.
$recursionCounter < $this->maxItems
allows up tomaxItemsInResultListcalls (9999 in the example) instead of
ceil($allRowsCount / 50)pages. - The WHERE clause grows on every call.
queryTable()callsprepareSelectStatement()
on every call
(L139 which adds the search constraints andsearchConditionto$this->queryBuilder
again, with new parameters each time. Each call then clones a larger query builder,
so memory use grows with the square of the call depth.
With 122 matches and maxItemsInResultList = 9999, three calls would be enough; the
code keeps calling itself until memory runs out.
A second effect of the recursion: results are merged with array_merge($tmp, $rows),
which puts later pages in front of earlier ones. When the controller then trims the
list to maxItemsInResultList, it removes the records that sort first. With 122
matches and maxItemsInResultList = 60, the list does not start with the first
record in sort order.
Custom receivers that extend the class and call parent::prepareSelectStatement() are
affected the same way.
Possible fix
- Call
prepareSelectStatement()once, before fetching. - Replace the recursion with a loop over pages that stops when a page returns fewer than
50 rows, or whenmaxItemsrecords have been collected. - Keep the sort order of the result.
- Drop the separate count query, as #106981 proposed.
Note: stopping when a page yields no accepted rows (the approach in the abandoned
change https://review.typo3.org/c/Packages/TYPO3.CMS/+/89912) would end the search early
if all 50 rows of a page fail checkRecordAccess(). The stop condition should depend on
the rows fetched, not on the rows accepted.
A patch with functional tests along these lines will follow on Gerrit.
Workaround
Keep maxItemsInResultList at 50 or lower. That limits the number of calls to roughly
@maxItemsInResultList / 50@.
Related
- #106981 (rejected) and its abandoned change 89912 touched the same recursion but
targeted query count and result limiting, not the memory problem.
Reviews 1
History 02
-
Gerrit Code Review pushed patch set 1 for main to change 97197 status
NewUnder Review <span data-processor="relativetime" data-value="2026-10-28T15:10:24+00:00" > 10/28/26, 15:10 </span> -
Gerrit Code Review pushed patch set 2 for main to change 97197 <span data-processor="relativetime" data-value="2026-11-16T16:36:11+00:00" > 11/16/26, 16:36 </span>