Review main Work in progress Orphaned

88753[BUGFIX] Fix COUNT(*) issue with GROUP BY and HAVING in Extbase QueryBuilder

Stefan Froemken CR -1 V 0 Normal +60 −5 updated 03/27/25, 17:37

Commit message

When building queries with TYPO3 QueryBuilder in Extbase that include
GROUP BY or HAVING clauses, Extbase replaces the entire SELECT part
with COUNT(*). This can cause errors if the HAVING clause depends on
column aliases from the original SELECT, which are lost when replaced
with COUNT(*).

This patch ensures that COUNT(*) is applied correctly by wrapping the
original query as a subquery, preserving aliases and avoiding SQL errors.

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 4
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/53/88753/4 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/53/88753/4 && git cherry-pick FETCH_HEAD

Review

  • Code review CR -1 Needs a vote
    • Stefan Froemken -1
  • Verified V 0 Needs a vote
    • core-ci +1 CI

Issues 1

Files 1

Review log 1014

  1. Stefan Froemken uploaded patch set 1 03/25/25, 16:43

  2. core-ci voted on patch set 1 V -1 03/25/25, 16:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76296

  3. Stefan Froemken uploaded patch set 2 V -1 03/25/25, 17:39

  4. core-ci voted on patch set 2 V -1 03/25/25, 17:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76298

  5. Garvin Hicking commented on patch set 2 03/25/25, 18:38

    Typo3DbBackend.php:338 Unresolved

    I guess these restrictions for the workspace need to be applied to the fullSql, not to the "outer" container?
  6. Stefan Froemken uploaded patch set 3 V -1 03/25/25, 21:38

  7. Stefan Froemken uploaded patch set 4 03/25/25, 21:40

  8. core-ci voted on patch set 3 V -1 03/25/25, 21:47 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76319

  9. core-ci voted on patch set 4 V +1 03/25/25, 21:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76320

  10. Stefan Froemken commented on patch set 4 CR -1 03/25/25, 22:00

    Yes, it's green. BUT! Please do NOT merge!!! I t just solves the issue for just Extbase Queries which are converted to Doctrine Query. For self builded Doctrine Queries this solution does NOT work, so it does not solve the related issue just right now. Maybe it needs some more tests. Further we should stop working with TABLE.*, which makes various problems when using query as subquery. For two tests I got "duplicate column 'sorting'". That was solved with my current patch. To solve this patch for Extbase queries and also for own Doctrine queries we had to parse the SELECT part and only replace all TABLE.* to individual columnname lists. That way we have to find a solution to just keep the last duplicate columnname value. But parsing SELECT with RegExp is nasty. I think I will ask Stefan Bürk how we/I can start solcing this.
  11. Simon Schaufelberger commented on patch set 4 03/25/25, 23:03

    Typo3DbBackend.php:403 Unresolved

    datatype for col missing
  12. Garvin Hicking commented on patch set 4 03/26/25, 07:36

    Reply

    I was thinking right now: if a "select count(*) from (subquery)" is used, doesn't that mean that the DB engine actually returns all the data in the subquery and only then counts it? that might cause bad performance because for large tables all data would (internally) be returned?
  13. Stefan Bürk commented on patch set 4 03/26/25, 09:23

    Reply Unresolved

    The DB engine has to compute the full result anyway to do a count. If you use count() directly or on a sub-query. In case you have an query which fully works on indexes, only than you have a performeance difference as it could not do the count on the indexes only. In real world, special within extbase that should not be happen so often and not be an issue here. Not saying the change is okay - need a deeper look.
  14. Benni Mack marked it work in progress 03/27/25, 17:37