jpa-streamer icon indicating copy to clipboard operation
jpa-streamer copied to clipboard

Optimize Streams that yield Join-operations

Open julgus opened this issue 5 years ago • 1 comments

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.

julgus avatar Aug 11 '20 08:08 julgus

We could potentially add predicate builders like:

Film$.actor.where().lastName.startsWith("A")

or

Film$.actor.flatMap().lastName.startsWith("A")

minborg avatar Sep 04 '20 15:09 minborg