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

SpecificationComposition reversed predicates #2146

Closed
rideliner opened this issue Jan 29, 2021 · 3 comments
Closed

SpecificationComposition reversed predicates #2146

rideliner opened this issue Jan 29, 2021 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@rideliner
Copy link

It appears that lhs and rhs were reversed in 25924d8.

https://github.com/spring-projects/spring-data-jpa/blob/master/src/main/java/org/springframework/data/jpa/domain/SpecificationComposition.java#L54

This causes spec1.and(spec2) to result in spec2 and spec1.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 29, 2021
@schauder
Copy link
Contributor

schauder commented Feb 1, 2021

Does this matter? The order of execution is determined by the execution plan created by the database, not by the order of statements in the SQL statement, isn't it?

@schauder schauder added the status: waiting-for-feedback We need additional information before we can continue label Feb 1, 2021
@mp911de mp911de self-assigned this Feb 1, 2021
@mp911de mp911de added type: task A general task and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged labels Feb 2, 2021
@mp911de mp911de added this to the 2.3.7 (Neumann SR7) milestone Feb 2, 2021
@mp911de
Copy link
Member

mp911de commented Feb 2, 2021

The issue affects also OR concatenation.

@mp911de mp911de added type: bug A general bug and removed type: task A general task labels Feb 2, 2021
@mp911de mp911de closed this as completed in ab4dd9c Feb 2, 2021
mp911de added a commit that referenced this issue Feb 2, 2021
We now consider the ordering of left-hand-side and right-hand-side arguments when composing specifications. The primary aspect is consistency so that predicates appear in the actual SQL query in the order they were combined. Most SQL databases tend to reorder the criteria according to the most useful query execution plan. Only special cases tend to follow deferred evaluation when using OR combination.

Resolves #2146.
mp911de added a commit that referenced this issue Feb 2, 2021
We now consider the ordering of left-hand-side and right-hand-side arguments when composing specifications. The primary aspect is consistency so that predicates appear in the actual SQL query in the order they were combined. Most SQL databases tend to reorder the criteria according to the most useful query execution plan. Only special cases tend to follow deferred evaluation when using OR combination.

Resolves #2146.
@pgv
Copy link

pgv commented Oct 5, 2023

This also fixes #1309. It's not really a fix though, cause if you compose two specifications in the wrong order, let's say you add a condition parent.name = 'x' first and then inner join fetch parent, the first condition won't be able to find the parent join and create a new one (or throw an error, I don't remember). I have a lot of old code with the specifcations with conditions first and specifications with joins last because of this very issue. In this version I have to reverse those lines. I would like to work on a better composition implementation, but it's an old issue and don't have the time right now. I guess I'll just move my joins on top of my conditions and move on. There is no easy solution with the current implementation.

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

No branches or pull requests

5 participants