-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
SQL query not optimized when using Projection with a Specification (FetchableFluentQuery) #2721
Labels
status: waiting-for-triage
An issue we've not yet triaged
Comments
gonzalad
changed the title
Using Specification with FetchableFluentQuery as doesn't optimize the SQL query
Using Projection with a Specification (FetchableFluentQuery) doesn't optimize the SQL query
Dec 5, 2022
gonzalad
changed the title
Using Projection with a Specification (FetchableFluentQuery) doesn't optimize the SQL query
SQL query not optimized when using Projection with a Specification (FetchableFluentQuery)
Dec 5, 2022
spring-projects-issues
added
the
status: waiting-for-triage
An issue we've not yet triaged
label
Dec 5, 2022
Related: #1524 |
This was referenced Feb 24, 2023
any workaround |
Usage
|
Any updates on this issue? I have this exact use case as described in the OP for implementing (optimized) GraphQL queries that only retrieve requested fields/columns from database. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
Summary
Atm, using projection with specifications doesn't change the generated SQL query, the JPA entity is still loaded under the hood.
Could we expect query optimization in the future when using Projections with Specifications ? (limiting the fields to be loaded to those of the projection interface/class ?)
Detailed issue
I just tried SB 3.0 Projection support with Specifications:
This works nicely, bu when I look at the sql, I see:
I would have expected the SQL to fetch only the properties from the projection, i.e.:
Even if I use
project(<property>)
:I still get the same sql.
Looking at the source code, I see in FetchableFluentQueryBySpecification:
The
project(property)
method updates theproperties
attribute. This attribute is only used to set the fetchgraphThe
as(Class)
method is used after executing the jpa query to convert the jpa entity to the projection type, hence this one doesn't change the sql query generation behaviour atm.So, to optimize the generated query, the only way I found atm would be to rely on
project(String)
, activate bytecode enhacement and annotate each basic attribute with@Basic(fetch=LAZY)
.But setting @basic(fetch=LAZY) seems to me to be too much hassle because it impacts all the queries I already have in my application.
The text was updated successfully, but these errors were encountered: