Is there any performance gain if I only select several columns instead of a whole entity


#1

Currently, I am fetching all the columns and then use MapStruct to map it into the DTO, it works fine for me.
It is bothersome to just select several fields in Hibernate/HQL.
For example:

So I think I should just stick with the old way (select the whole enity and use MapStruct).

I want to know is there any big gap about the performance between between these two, especially in the case my queries contains several join statement


#2

Yes, it is.

As explained in this article, selecting only a subset of columns is much more efficient and will always perform better than selecting all columns only to discard whatever fields you don’t need.