SEBLOD icon indicating copy to clipboard operation
SEBLOD copied to clipboard

wrong results count in List when using GROUP BY

Open Giuse69 opened this issue 2 years ago • 1 comments

When displaying a list of items with a List Type, if no conditions are set (no field is the Search View is filled), the plugins\search\cck\cck.orig calculates the number of results, and related results pagination, but the count is wrong when a GROUP BY condition has been added in the Search Query field and that group by is not "#__cck_core.id" . This is due to the fact that cck.php in line 443 clears the GROUP BY conditions and repeats the select with a COUNT('DISTINCT t0.id)'): the result is wrong since the GROUP BY reduces the number of results and infact the pagination is not fully working - last pages are empty since there are less results than the query has calculated. A possible fix is to replace if ( $hasGroup ) { $query->clear( 'group' ); $query->select( 'COUNT(DISTINCT t0.id)' ); with if ( $hasGroup ) { $query->select('DISTINCT COUNT(*) OVER ()'); using at least mySQL 5.7 or mariaDB 10.2 that supports windowing functions (OVER operator).

Giuse

Giuse69 avatar May 03 '22 21:05 Giuse69

After 14 months can I ask for a feedback?

Giuse69 avatar Jul 08 '23 07:07 Giuse69