SEBLOD
SEBLOD copied to clipboard
wrong results count in List when using GROUP BY
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
After 14 months can I ask for a feedback?