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

Pagination with JOINs for repository methods #3174

Merged
merged 4 commits into from
Oct 16, 2024
Merged

Pagination with JOINs for repository methods #3174

merged 4 commits into from
Oct 16, 2024

Conversation

dstepanov
Copy link
Contributor

@dstepanov dstepanov commented Oct 11, 2024

  • For repository methods with JOIN and pagenation, the query is generated as:
        // SQL tabular results with JOINs cannot be property limited by LIMIT and OFFSET
        // Create a query that can be paginated with JOINs using a subquery
        //
        // SELECT mainEntity.* FROM MyEntity mainEntity JOIN ... WHERE mainEntity.id in (
        //     SELECT paginationEntity.id FROM MyEntity paginationEntity WHERE paginationEntity.id in (
        //        SELECT filteredEntity.id FROM MyEntity filteredEntity JOIN ... WHERE ... ;
        //     ) ORDER BY ... LIMIT ... OFFSET ...
        // ) ORDER BY ...
        //

(In future version we can optimize it)

  • Only valid for SQL and JPA builders - we might consider another layer between the query builder for repositories to generate queries
  • The append of pagination / sort is implemented using an expandable functionality of queries.
  • The count query is now represented as a separate annotation (with backwards compatibility). In the next major version I would like to change to have:
    • DataMethod - basic representation of the method
    • "queryDefinition" - eveything about the query etc
    • "countQueryDefinition" - eveything about the count query etc
    • possibly a collection of queries, we can also support different dialects for one method if needed
  • Not working for MySql now, because MySql doesn't support LIMIT in subqueries. It could be implemented using a JOIN - SELECT ... JOIN (Select ... ) as filtered WHERE filtered.id = ID, but our criteria don't support this kind of query yet

@dstepanov dstepanov added the type: improvement A minor improvement to an existing feature label Oct 14, 2024
@dstepanov dstepanov marked this pull request as ready for review October 15, 2024 07:39
…dQuery.java

Co-authored-by: Radovan Radic <radicr@gmail.com>
@graemerocher
Copy link
Contributor

does it work for cursor pagination?

@dstepanov
Copy link
Contributor Author

I have added a test. It looks like it's working, but I found a scenario that doesn't work, which is not related to my changes. When we reach the end and find a page that returns nothing, it's impossible to go back. Any idea @andriy-dmytruk?

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
1 New Bugs (required ≤ 0)
3 New Critical Issues (required ≤ 0)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@dstepanov dstepanov merged commit 9469700 into 4.10.x Oct 16, 2024
52 of 53 checks passed
@dstepanov dstepanov deleted the joinpx branch October 16, 2024 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants