Skip to content

Simplify predicate concatenation in JpqlQueryBuilder.and(List) - #4352

Open
JunggiKim wants to merge 1 commit into
spring-projects:mainfrom
JunggiKim:issue/simplify-jpql-and
Open

Simplify predicate concatenation in JpqlQueryBuilder.and(List)#4352
JunggiKim wants to merge 1 commit into
spring-projects:mainfrom
JunggiKim:issue/simplify-jpql-and

Conversation

@JunggiKim

@JunggiKim JunggiKim commented Sep 11, 2026

Copy link
Copy Markdown

JpqlQueryBuilder.and(List) combines predicates by repeatedly calling Predicate.and(Predicate), and each of those calls flattens everything accumulated so far into a new list, so the element copies are quadratic in the number of predicates. AndPredicate.of(List) already flattens a list in one pass and or(List), directly below, already delegates to OrPredicate.of(List), so and(List) now delegates the same way. The empty and single-element cases stay explicit to keep the returned instance the same as before.

The only caller is KeysetScrollSpecification, where the list holds one predicate per keyset sort key; in the queries the tests generate that is one to four predicates. One thing does change for input that caller never produces: a null next to another predicate used to be dropped, or to fail inside List.of, and now throws when the predicate is rendered.

The added tests pass against the previous implementation too, and the module test suite passes before and after.

  • You have read the Spring Data contribution guidelines.
  • You use the code formatters provided here and have them applied to your changes. Don't submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.
  • You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only).

JpqlQueryBuilder.and(List) combined predicates by repeatedly calling Predicate.and(Predicate), and each of those calls flattened everything accumulated so far into a new list, which makes the element copies quadratic in the number of predicates. AndPredicate.of(List) already flattens an entire list in one pass and or(List) directly below already delegates to OrPredicate.of(List), so and(List) now delegates the same way.

The empty and single-element cases stay explicit so that the returned instance is the same as before: an empty list returns null and a single predicate is returned unchanged rather than wrapped in an AndPredicate.

Signed-off-by: Junggi Kim <kimjg2477@gmail.com>
@JunggiKim
JunggiKim force-pushed the issue/simplify-jpql-and branch from d7beab6 to 57e1001 Compare September 11, 2026 06:22
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants