apache / apache/grails-core

Total count from criteria builder is not including group property projection

Open
#14,431 0 comments 0 reactions 0 assignees View on GitHub
relates-to: grails-data-hibernate5
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

### Background

The total count from a criteria builder does not appear to include projections that group properties, resulting in a result set that is grouped but a total count that is just the count of all records.

### Steps to reproduce

Create criteria builder to list results with projections that group properties, the result set appears to be correct but the total count query does not include any group by.

### Expected behaviour

Total count query includes the same group by clauses defined in the result set query.

### Actual behaviour

Total count query is not including any of the projections/group by and query appears to be a flat count.

`select count(*) as y0_ from person this_`

### Environment Information
GORM Version: 7.1.0.M2
Grails Version (if using Grails): N/A
JDK Version: Java 8
Database: Postgres or H2 file

### Example Application
A Micronaut application with H2 database and simple test to confirm total count value from criteria.

https://github.com/nmkae/gorm-criteria-count

Contributor guide

Open the contributing guide

Research direction

Start with the linked Micronaut example application and its simple criteria test, reproducing the count behavior on H2 or PostgreSQL. Compare the grouped result query with the total count query; done when the count includes the same group-by clauses and the test confirms the expected total.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.