I have a table in my DB mapped to one entity in my project. I'm trying to perform a simple select using findById()
based on the PK's of this entity. This table has 48 million rows, so it's a very heavy table. Hibernate generates a simple SELECT statement to perform this operation. The problem is that this simple SELECT takes in average 3 seconds to run, but if I get the same query and run it in DBeaver or MSSQL, it takes less than 80ms to run. What could be the reasons for this problem?
@Data@Entity@Builder@NoArgsConstructor@AllArgsConstructor@Table(name = "MyEntity")public class MyEntity implements Serializable { @EmbeddedId private IdMyEntity id; // More columns @Data @Builder @Embeddable @NoArgsConstructor @AllArgsConstructor public static class IdMyEntity implements Serializable { // 7 columns that represent the PK of the entity }}
select -- All the columns from the entityfrom MyEntity myEntity0_where -- All the columns that represent the PK of the entity