Skip to content
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

Clauses involving one-to-many relations in a filter require separate jointures or a subqueries #708

Closed
arteymix opened this issue Jun 3, 2023 · 2 comments · Fixed by #714 · May be fixed by #715
Closed

Clauses involving one-to-many relations in a filter require separate jointures or a subqueries #708

arteymix opened this issue Jun 3, 2023 · 2 comments · Fixed by #714 · May be fixed by #715
Milestone

Comments

@arteymix
Copy link
Member

arteymix commented Jun 3, 2023

They currently result in contradictions where clauses such as: c.id = 1 and c.id= 2 are generated.

This could be resolved in two different ways:

Multiple jointures (one per clause)

join c as c1 join c as c2 where c1.id = 1 and c2.id = 2

The disadvantage is that we do not control the process that produces the jointures when generating the restriction clause, so it will require significant changes.

Subqueries

where id in (select id from Entity e join e.c where e.c.id = 1) and id in (...)

Advantage: clauses are contained and likely easier to generate.

Drawback: the context to refer to aliases in the root query is not available.

@arteymix arteymix added this to the 1.30.0 milestone Jun 4, 2023
@arteymix
Copy link
Member Author

arteymix commented Jun 4, 2023

I'm starting to lean more in favour of subqueries for this. It will ease the Criteria-based filtering service implementation since it already natively supports this via a SubqueryExpression.

For HQL, unfortunately it will not be easy, but there should be enough information in the property meta to generate the jointure necessary in the subquery.

The upside is that by doing this, we will not require the group by clause anymore nor distinct for counting, so there might be a noticeable performance gain.

@arteymix
Copy link
Member Author

arteymix commented Jun 4, 2023

  • limit the number of in clauses in a filter
  • generate a subquery with HQL il FilterQueryUtils
  • generate a subquery using a SubqueryExpression for the Criteria-based service

If more information is needed, we might have to make the content of FilteringQueryUtils protected in AbstractQueryFilteringDao so that it can access metadata.

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