Review main Merged

91373[FEATURE] Provide pagination for QueryBuilder

Georg Ringer CR +2 V +2 Hard +399 −0 updated 03/06/26, 12:36

Commit message

A new `QueryBuilderPaginator` is introduced to simplify
pagination of `QueryBuilder` instances directly.

The paginator ensures that the main query is executed only
once per page request by storing the result internally.
This avoids double execution of the database statement.

Calculating the total amount of items is handled automatically
and robustly using a common table expression (CTE) around the
passed QueryBuilder instance to create the result mitigating
casual culprit advanced queries like UNION, CTE's or in case
windowing functions are used along with a grouping.

Example usage:

```php
$paginator = new QueryBuilderPaginator(
    $queryBuilder,
    $currentPage,
    $itemsPerPage,
);
```

Review

  • Code review CR +2 Done
    • Georg Ringer +2
    • Garvin Hicking +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 1

Files 5

Review log 1626

Show 1 earlier messages
  1. Georg Ringer uploaded patch set 1 10/30/25, 18:34

  1. core-ci voted on patch set 1 V -1 10/30/25, 18:41 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88175

  2. Georg Ringer uploaded patch set 2 V -1 10/30/25, 18:54

  3. core-ci voted on patch set 2 V +1 10/30/25, 19:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88178

  4. Stefan Froemken uploaded patch set 3 V +1 02/24/26, 21:55

  5. core-ci voted on patch set 3 V +1 02/24/26, 22:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/96779

  6. Stefan Froemken updated the commit message in patch set 4 V +1 02/24/26, 22:11

  7. core-ci voted on patch set 4 V +1 02/24/26, 22:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/96783

  8. Stefan Bürk commented on patch set 4 03/05/26, 15:37

    QueryBuilderPaginator.php:78

    Why another clone here ? If this is only about getting the "distict" out of it this can be done on the already cloned query builder instance.

    QueryBuilderPaginator.php:85

    The whole solution introduces quite a lot of code and using "internal" api droped by upstream doctrine/dbal querybuilder already and only kept internal for some places in TYPO3 (TypoScript Database Query thing) to get the parts. We should abstain from increasing the usage of them as this implementation may act as example for some developers and we should not emphasize internal api. Technically I would replace all this handling and use a simple non-recursive CTE query for it: ```sql WITH -- cte parts cte_base AS ( /* SQL from cloned $queryBuilder and removed parts */ ) -- main part SELECT COUNT(*) from cte_base ``` over the classic "subquery select" done here conditionally. Using a CTE is better supported by dbms engines and allows for better optimization in the background and compared to a direct table count in the false condition part there is no real impact as the full result set needs to be generated anyway to create a count on it. The CTE api is php code wise a little bit cleaner and smaler than handing over a querybuilder instance as select part through the decorated concrete QueryBuilder instance. The current implementation does not support having a `UNION` query and would possible breaks the intended query. Or even worser, if a CTE query may be handed over. A complete CTE as cte part (nested) is allowed and taken all the points into account I'd would prefere using a CTE here. Despite mentioning `@internal` API above, we need to use the internal prefixed CTE variant `$queryBuilder->typo3_with()` here for now. doctrine/dbal has already rudimentary CTE `$queryBuilder->with()` but that is not adopted yet into our decorator construct. As I plan to raise doctrine/dbal after adding some additional CTE stuff upstream (recursive support and similar) I would take care of replacing the internal usage anyway and this place would be the second place it is used despite functional tests and RootlineUtility). I'm going to push a new change set with the CTE construct.

    QueryBuilderPaginator.php:92

    QueryBuilder has an API for such things and we should use that and abstain from composing plain sql queries..
  9. Stefan Bürk uploaded patch set 5 V +1 03/05/26, 16:55

  10. Stefan Bürk uploaded patch set 6 03/05/26, 17:04

  11. core-ci voted on patch set 5 V -1 03/05/26, 17:06 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97422

  12. core-ci voted on patch set 6 V +1 03/05/26, 17:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97425

  13. core-ci commented on patch set 6 03/05/26, 17:51 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97426

  14. Georg Ringer uploaded patch set 7 V +1 03/06/26, 06:46

  15. Georg Ringer commented on patch set 7 03/06/26, 06:46

    This change is ready for review.
  16. core-ci voted on patch set 7 V +1 03/06/26, 06:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97467

  17. Simon Schaufelberger commented on patch set 7 03/06/26, 08:41

    Use markdown syntax

    QueryBuilderPaginator.php:39

    Private

    QueryBuilderPaginator.php:43

    Can be private because of final
  18. Georg Ringer uploaded patch set 8 V +1 03/06/26, 09:31

  19. core-ci voted on patch set 8 V +1 03/06/26, 09:45 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97475

  20. Simon Schaufelberger uploaded patch set 9 V +1 03/06/26, 09:57

  21. Simon Schaufelberger commented on patch set 9 03/06/26, 10:00

    Reply

    Done
  22. core-ci voted on patch set 9 V +1 03/06/26, 10:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97480

  23. Garvin Hicking commented on patch set 9 CR +1 V +1 03/06/26, 11:30

    QueryBuilderPaginator.php:39 Reply

    Done

    QueryBuilderPaginator.php:43 Reply

    Done

    QueryBuilderPaginator.php:78 Reply

    Done

    QueryBuilderPaginator.php:85 Reply

    Done

    QueryBuilderPaginator.php:92 Reply

    Done
  24. Georg Ringer voted on patch set 9 CR +2 V +2 03/06/26, 12:36

  25. Georg Ringer merged patch set 10 03/06/26, 12:36