Problem was that cost_group_min_max() could not handle if group by was optimized away.
Attach a file by drag & drop or click to upload