-
Notifications
You must be signed in to change notification settings - Fork 139
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
Filtering on relations breaks pagination #954
Comments
Relating to this issue in the typeorm repo: typeorm/typeorm#4742 (comment) This would require a change here:
The problem with skip/take is that it "gets all the results, merge them together into entities and then apply skip / take, which performance-wise a bit slower". For simple queries that don't work on relations limit/offset would be the better way to go. So a change should check wheater there's a join required and if so apply skip/take and otherwise use the faster offset/limit. Maybe a small hint in the docs on the performance impact when using such queries on large relations might be nice to add as well. |
* Added tests to typeorm-query.service.spec for filtering on relations with paging * Reverted basic example.
* Added tests to typeorm-query.service.spec for filtering on relations with paging * Reverted basic example.
* Added tests to typeorm-query.service.spec for filtering on relations with paging * Reverted basic example.
* Added tests to typeorm-query.service.spec for filtering on relations with paging * Reverted basic example.
* test: Test filtering on relations * test: Test relation query with overlapping relation matches and pagination (#954) * fix(typeorm, #954): use skip/take when joins are present) * docs: Note performance issues when using relation filters and pagination * style(comment): Added missing param in applyPaging comment * test: added ordering to make tests stable across different db vendors * fix(typeorm, #954): Filtering on relations with pagination * Added tests to typeorm-query.service.spec for filtering on relations with paging * Reverted basic example. Co-authored-by: Max Wölk <[email protected]>
Fixed in |
Describe the bug
When performing a query that includes or-filters with overlapping results on relations, it generates LEFT JOIN clauses (tested in postgres) in the query which leads to multiple rows in the database result containing the base entity. If pagination is used the query also contains a LIMIT. If the limit is e.g. set to 10 and we get more than 10 overlapping results the query returns only this one base entity instead of 10 different ones.
To Reproduce
Steps to reproduce the behavior:
Reproduction in the "basic"-example
TodoItemDTO
change the twoCursorConnection
fields toFilterableCursorConnection
to make them filterable.first
parameter of paging to 3 leads to both ToDos 1 and 2 to be returned.I started working on fixing things here (already modified the basic example and added a failing test case): https://github.com/mwoelk/nestjs-query/tree/issue954
Analysis based on the modified "basic" example
Ignoring the paging argument, the underlying database query would return something similar to the following table (due to the JOINs involved):
Due to the
first
argument set in paging, the database query is added anLIMIT (first + 1)
which leads to the behaviour described above. E.g. if first < 3, only the rows with an id of 1 are returned.Expected behavior
The number of results should match the expected pagination size if there are enough results available.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: