Skip to content

HHH-19331: query plan cache should take parameter type into accound for cast #10182

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

victornoel
Copy link
Contributor

@victornoel victornoel commented May 20, 2025

My understanding of the problem is that the query plan cache has some mechanisms to know if a cached query plan is invalid. Until now it handled two cases in relation to query parameters:

  • if the value of the parameter was used directly in the rendered SQL, then the same query with different parameters cannot reuse the cached SQL
  • if the parameters are related to limit/offset, for select queries, then we are not so much interested in the value of the limit/offset parameters but with the fact they are specified or not to know if we can reuse the cached SQL.

My change add one more case: when a parameter type is involved in the rendered SQL, precisely here if we render a cast that was not explicit in the HQL query, then the cached SQL cannot be reused with a different parameter type. I haven't found out if there were more cases of this problem, other than cast.

I didn't go all the way into remembering the type of the parameter used during the SQL rendering but just on the presence of the parameter in appliedParameters. Most certainly it should be possible to optimize this but I didn't want to make things too complex.

I went with refactoring things a bit to 1) remove duplicate code between JdbcOperationQuerySelect and AbstractJdbcOperationQuery. I think it's equivalent but I may have missed something. I think it also remove chances of NPE (as mentioned in a TODO I removed) when appliedBinding is null.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19331

@victornoel victornoel changed the title HHH-19331: query plan cache should honour parameter type into accound for cast HHH-19331: query plan cache should take parameter type into accound for cast May 20, 2025
@victornoel victornoel marked this pull request as draft May 22, 2025 15:29
@victornoel
Copy link
Contributor Author

Making this a draft based on the discussion in Zulip and the fact that

  • this is really corner case (it ONLY applies to those "select ?1" kind of query where the hibernate parser cannot infer the expected type of the parameter)
  • it should be improved even if we went forward

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant