Project

General

Profile

Actions

Bug #79330

closed

Extbase getObjectCountByQuery returns wrong results

Added by Morton Jonuschat almost 8 years ago. Updated about 7 years ago.

Status:
Closed
Priority:
Must have
Category:
Extbase
Target version:
Start date:
2017-01-15
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
8
PHP Version:
7.0
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Before Extbase was converted to use Doctrine the method used a

COUNT(DISTINCT uid)
to count on joined tables. With the migration to Doctrine this was changed to use GROUP BY uid. This works in most cases, for this use case it ends up with a different resultset.
This is visible in the functional tests in the BlogExample. The goal is to count all persons which use a Tag in either of two relations. In total there are three persons using that tag. 1 using it in both relations, and one each using it in one of them.
Thus the correct the result of the query is 3.
With the old DISTINCT based query the result would be 1 row with a count of 3. This is the intended result.
With the GROUP BY based count the resultset consists of three rows, each containing the count of usages per uid.

By coincidence MySQL implictly sorts the results in such a way the the first row of the resultset has a count of 3 uses for that uid (the other rows have 1 use each). PostgreSQL for example has the same resultset, but in a different implicit order. The first row has a counted usage of 1.

As the current getObjectCountByQuery only uses the first result row as the count the functional tests fail to detect the error on MySQL but it shows up on PostgreSQL.


Related issues 2 (1 open1 closed)

Related to TYPO3 Core - Bug #79988: Fix ensureCorrectPostOrderingByCategoryTitle extbase test on postgresClosed2017-02-24

Actions
Related to TYPO3 Core - Bug #93576: Typo3DbBackend::getObjectCountByQuery does not work correctly with custom doctrine queriesNew2021-02-24

Actions
Actions

Also available in: Atom PDF