jpa-streamer
jpa-streamer copied to clipboard
Optimize Streams that yield Join-operations
As JPAstreamer makes it easy to stream any database table there are many operations which can be added that results in a non-optimized stream. That is for example the case when accessing fields that depend on other tables. See for example:
long count = jpaStreamer.stream(Film.class)
.filter(f -> f.getActors()
.stream()
.filter(Actor$.lastName.startsWith("A"))
.count() > 0)
.count();
Here, the predicate on the fourth row (actors last names starts with A) should optimally be included as a where-clause in the original Join. As of now, we have to materialize every actor even though we are only interested in a subset of them.
It would be good to find a way to optimize similar queries.
We could potentially add predicate builders like:
Film$.actor.where().lastName.startsWith("A")
or
Film$.actor.flatMap().lastName.startsWith("A")