You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
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)
if we will trigger an
myEntityRepo.findById()
, then there will be 2 selects issued, not one select with the join. I mean, we get:and then
instead of having something like:
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 generalThe text was updated successfully, but these errors were encountered: