Skip to content

Make dependency aggregate query strategy configurable - SELECT/JOIN #1434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mipo256 opened this issue Feb 24, 2023 · 2 comments
Closed

Make dependency aggregate query strategy configurable - SELECT/JOIN #1434

mipo256 opened this issue Feb 24, 2023 · 2 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@mipo256
Copy link
Contributor

mipo256 commented Feb 24, 2023

When debugging the spring-data-jdbc queries, we found out, that for two entities, having OneToMany relationship between aggregates, like the two below (simplified for the sake of an example)

interface MyEntityRepo extends CrudRepository<MyEntity, Long> { }

@ToString
class MyEntity {

    @Id
    private Long id;

    @MappedCollection(idColumn = "my_entity_id", keyColumn = "my_entity_id")
    private List<Dependency> dependencies;
}

@ToString
class Dependency {

    @Id
    private Long id;

    private String type;

    private Long myEntityId;
}

if we will trigger an myEntityRepo.findById(), then there will be 2 selects issued, not one select with the join. I mean, we get:

SELECT "my_entity"."id" AS "id" FROM "my_entity" WHERE "my_entity"."id" = ?

and then

SELECT "dependency"."id" AS "id", "dependency"."type" AS "type", "dependency"."my_entity_id" AS "my_entity_id", "dependency"."my_entity_id" AS "my_entity_id" FROM "dependency" WHERE "dependency"."my_entity_id" = ? ORDER BY "my_entity_id"

instead of having something like:

SELECT ... FROM my_entity me INNER JOIN dependency d WHERE me.id = ?

That's a crucial thing. Because issuing 2 selects is generally, depends on a lot of conditions and particular DBMS worse. It is espesially the case when it comes to small selection subsets in the huge data set, which is a very common thing. There is an open discussion about that in DBA stackexchange.

The framework should at least provide a the way to choose per relation basis, like an additional attribute to MappedCollection annotation. That seems to be a quite large change, but still I think it is vital for the project in general

@schauder
Copy link
Contributor

I consider this a duplicate of #592 which just generally asks for a better handling of this situation.

Adding configurability to this could be a later improvement on top of that, but we can decide that only ones we have the basic infrastructure in place.

@schauder schauder closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2023
@mipo256
Copy link
Contributor Author

mipo256 commented Feb 27, 2023

Ok, I think we can close it as a duplicate, but I will add the comment in the aforementioned ticket anyway to just keep this improvement in mind

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants