Skip to content

[BUG]: Paginator\Adapter\QueryBuilder total count for group by with NULL values #15266

Open
@chipco

Description

@chipco

In mysql COUNT (DISTINCT col1, col2, col3) will not count any results that have one of the columns NULL.
However SELECT (DISTINCT col1, col2, col3) will show those rows with NULL as part of the result.

This is a problem when using the phalcon paginator with GROUP BY queries. The results that have NULL on one of the columns in the GROUP BY will not be counted.

I suggest adding an option to provide the columns for the total count on group by queries, similar to the having queries.

For example, create paginator like this:

$paginator = new PaginatorQueryBuilder([
	'builder' => $query,
	'limit' => 1,
	'page' => 1,
	'columns' => 'IFNULL(col1,0) , IFNULL(col2,0) , col3',
]);

And then use the columns parameter in the total query here, instead of the groupColumn variable:

totalBuilder->groupBy(null)->columns(
[
"COUNT(DISTINCT " . groupColumn . ") AS [rowcount]"
]
);

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasebugA bug reportstatus: unverifiedUnverified

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions