spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Load arbitrary aggregates with a single select

Open schauder opened this issue 2 years ago • 4 comments

This should resolve #592. I opted for a separate issue in order to allow for a more focused discourse about this specific approach.

We have a concept for how to load arbitrary aggregates with a single select statement, at least for those databases that support a sufficient subset of the SQL standard.

This ticket is an epic for tracking the progress in the implementation this concept.

Subtickets:

  • [ ] #1579
  • [ ] #1658
  • [x] #1446
  • [x] #1586
  • [ ] #1447
  • [x] #1448
  • [ ] #1449
  • [ ] #1450
  • [ ] #1451
  • [x] #1601
  • [ ] #1545
  • [ ] #1546

schauder avatar Mar 10 '23 09:03 schauder

Hi, thanks for this enhancement. I just wanted to know is there any plans for this feature? Like when implementation process is going to start and in which spring version we can use it? I'm specifically interested in single queries using R2DBC.

devfarzane avatar Mar 25 '23 10:03 devfarzane

The implementation started and we hope to make first parts available during 2023.

schauder avatar Mar 27 '23 07:03 schauder

I'm very excited to see that Spring Data JDBC is addressing this issue I solved the problem in the same way as presented in this blog post and published the code. (Single Query and Aggregate ResultSet Mapping) This is the Beginning of the End of the N+1 Problem: Introducing Single Query Loading.

Spring JDBC Plus is a library that extends Spring JDBC and Spring Data JDBC.

  • AggregateResultSetExtractor : https://github.com/naver/spring-jdbc-plus/blob/7ad384bc3d50ac66e3d06405973044ec0267a174/spring-data-jdbc-plus-sql/src/main/java/com/navercorp/spring/data/jdbc/plus/sql/convert/AggregateResultSetExtractor.java#L34

  • AggregateResultJdbcConverter : Map results from a ResultSet to entities, grouped by the value of the @Id column https://github.com/naver/spring-jdbc-plus/blob/7ad384bc3d50ac66e3d06405973044ec0267a174/spring-data-jdbc-plus-sql/src/main/java/com/navercorp/spring/data/jdbc/plus/sql/convert/AggregateResultJdbcConverter.java#L66

  • https://github.com/naver/spring-jdbc-plus/wiki/User-Guide#142-aggregateresultsetextractor

This feature is very useful. I'm looking forward to seeing it nicely addressed in Spring Data JDBC.

mhyeon-lee avatar Aug 31 '23 16:08 mhyeon-lee