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

Transform SIZE in where clause to COUNT in having clause #188

Closed
beikov opened this issue Feb 9, 2016 · 5 comments
Closed

Transform SIZE in where clause to COUNT in having clause #188

beikov opened this issue Feb 9, 2016 · 5 comments
Assignees
Labels
component: core kind: enhancement worth: low Implementing this has a low worth

Comments

@beikov
Copy link
Member

beikov commented Feb 9, 2016

Instead of creating a subquery for the SIZE function when appearing in the where clause, we can transform it into

  • A newly generated JOIN node
  • GROUP BY parent JOIN node
  • and replace the SIZE with a COUNT(newAlias) in the having clause

as long as there are no group bys present.

Multiple SIZE usages require to use COUNT(DISTINCT newAlias) which is not possible for some DBs when the relation uses a composite id.

This tranformation should be deactivatable via a property.

@beikov
Copy link
Member Author

beikov commented Sep 15, 2016

Just as a side note, this issue is about composite ids and count: https://hibernate.atlassian.net/browse/HHH-11042
I found a solution that should work in general which we could also apply here. Maybe we also need a property for switching between strict ansi sql and non-strict.

@beikov
Copy link
Member Author

beikov commented Sep 18, 2016

The tuple count distinct emulation is implemented now.

@beikov
Copy link
Member Author

beikov commented Sep 30, 2016

Currently SIZE in the WHERE clause gets passed through unmodified for the JPA provider to handle.
In the HAVING clause, it gets rewritten to COUNT_TUPLE although I am not sure if this is correct how it is done right now. More tests are required for the HAVING clause usage. Especially a test that asserts the cases when the SIZE must be rewritten to a subquery.

Note that the use of SIZE in GROUP BY is currently not possible because of #195
When SIZE is used in the ON clause, it must always be rewritten to a subquery. This must be properly tested.

@Mobe91
Copy link
Contributor

Mobe91 commented Sep 30, 2016

The transformation of SIZE to subqueries in ON clauses is covered by the tests already.

@beikov beikov modified the milestones: 1.2.0, 1.3.0 Jan 28, 2018
@beikov beikov added the worth: low Implementing this has a low worth label Sep 20, 2020
@beikov
Copy link
Member Author

beikov commented Jan 10, 2021

As this transformation oftentimes requires the addition of a select item and grouping by all select items, I decided to not implement this as the performance is probably way worse than using a subquery.

@beikov beikov closed this as completed Jan 10, 2021
@beikov beikov removed this from the 1.6.0 milestone Jan 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: core kind: enhancement worth: low Implementing this has a low worth
Projects
None yet
Development

No branches or pull requests

2 participants