spring-projects / spring-data-jpa

Simplifies the development of creating a JPA-based data access layer.
https://spring.io/projects/spring-data-jpa/
Apache License 2.0
2.93k stars 1.39k forks source link

Use provider built-in result count to reuse query if possible #3456

Open quaff opened 2 months ago

quaff commented 2 months ago

Hibernate introduce SelectionQuery::getResultCount since 6.5.0, It may be JPA Query method in the future.

christophstrobl commented 1 month ago

Thank you @quaff for bringing this up. Did you eventually compare the resulting database interaction triggered by getResultCount to the count as it is done right now? Before we change the current behaviour I'd like to understand potential implications on both what the count query looks like as well as potential runtime implications.

quaff commented 1 month ago

Thank you @quaff for bringing this up. Did you eventually compare the resulting database interaction triggered by getResultCount to the count as it is done right now? Before we change the current behaviour I'd like to understand potential implications on both what the count query looks like as well as potential runtime implications.

Please refer to https://github.com/hibernate/hibernate-orm/blob/8c3b68cd784076a06a4bc2a7a3d67fc32904dba3/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectStatement.java#L465