FetchMode Join vs SubSelect

后端 未结 4 1597
闹比i
闹比i 2020-12-05 05:28

I have two tables Employee and Department following are the entity classes for both of them

Department.java
@Entity
@Table(name = \"DEPARTMENT\")
public clas         


        
4条回答
  •  粉色の甜心
    2020-12-05 06:09

    I'd say it depends...

    Let assume you have N employees in a department, that contains D bytes of information and an average employee consist of E bytes. (Bytes are sum of the attribute length with some overhead).

    Using the join strategy you perform 1 query and transfers N * (D + E) data.

    Using the subquery strategy you perform 1 + N queries, but transfers only D + N*E data.

    Typically the N+1 query is the NO GO if the N is large, so the JOIN is preferred.

    But actually you must check your mileage between number of queries and data transfer.

    Note that I'm not considering other aspects as Hibernate caching.

    Additional subtle aspect could be valid if the employee table is large and partitioned - partition pruning on the index access comes to the consideration as well.

提交回复
热议问题