-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
HHH-3356 Support for normal and lateral subquery in from clause #5086
Conversation
This looks rather good, assuming I'm understanding everything. A couple of comments:
|
Either way, I'd rather not make this the default if that's what you mean by "implicit".
I'll add a few more tests if that makes you feel better ;) |
Well yeah but I'm not suggesting to generate the |
Right, we can determine this, but I wouldn't say it is "straightforward". The problem here is that JPA Criteria seems to allow accessing paths from the outer query regardless if the path base is correlated, so the check is not as simple as determining whether the set of correlated nodes is non-empty. We'd have to traverse the whole query tree to be sure. Maybe we could do that somehow during SQM->SQL AST translation, but it's not like I can just grab a flag from somewhere and do something like |
https://hibernate.atlassian.net/browse/HHH-3356
This adds support for sub queries in the from clause as roots and joins. Sub queries can have an optional lateral marker, which allows sub queries to refer to previous from clause nodes. Also see the SQL standard definition of LATERAL or the nice documentation text from PostgreSQL for more details: https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-LATERAL
The design follows what was discussed here which is, that tuple types and their model parts are determined based on the select items of a sub query. It is not necessary to define an explicit (managed) type in order to use this feature.
There are a few things missing which are mostly of "mechanical" nature, i.e. someone needs to do it, but there shouldn't be any technical challenge. These will be added to the next bug fix version of 6.1, given that this PR makes it into 6.1. This was done deliberately to be able for this feature to make it into 6.1.
The currently missing parts are:
DomainResult
support for anonymous tuples i.e.select d from (select ...) d
is not supportedselect ... from (select ...) d where (select ... where d.field = 1)
is not supportedSubQueryInFromEmbeddedIdTests
andSubQueryInFromIdClassTests