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

skip + take vs limit + offset poll #576

Closed
bashleigh opened this issue Aug 12, 2021 · 8 comments
Closed

skip + take vs limit + offset poll #576

bashleigh opened this issue Aug 12, 2021 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@bashleigh
Copy link
Collaborator

bashleigh commented Aug 12, 2021

Seems like there are some conflicts between the default method of querying. I feel this is a bit of an opinionated choice in some cases and I also don't want to be bias! I personally would stick with limit + offset as it's perfect for simple queries however some people may differ.

Please could people vote for their perfered method, once I have enough votes say by end of November we can release a breaking change if required.


@bashleigh bashleigh added the help wanted Extra attention is needed label Aug 12, 2021
@bashleigh bashleigh pinned this issue Aug 12, 2021
@csxcode
Copy link

csxcode commented Aug 20, 2021

Well, when use pagination with Limit & Offset, I have problems using joins as other people. I understand that I should use "Take and Skip" with joins, but what is the main difference, the performance?

@bashleigh
Copy link
Collaborator Author

@csxcode well it's looking pretty close atm so I think I might do a bit of research and see what the diff is (been a while since I've properly looked at query performance) and see if we can convince more people! If there's no performance difference then I guess we leave it?

@vjrngn
Copy link

vjrngn commented Oct 6, 2021

I second @csxcode point. I don't think this is a question of only performance. Depending on the query "take and skip" may be preferable over "limit and offset".

@Elbarae1921
Copy link
Contributor

Like it was said by the creator of typeorm:

use skip / take instead of limit / offset when you do joins with selection.

typeorm/typeorm#8014 (comment)

@Elbarae1921
Copy link
Contributor

One issue I find though is when I have joins with selection and an orderBy clause. Neither take/skip nor limit/offset worked for me.

@ChamaraWP
Copy link

cloud someone shows me how to change the query type to TAKE_LIMIT. I couldn't find it in the documentation. sorry for commenting on the irrelevant issue.

@Elbarae1921
Copy link
Contributor

@ChamaraWP

const result = await paginate(
    queryBuilder, 
    {
        limit: 10,
        page: 1,
        paginationType: PaginationTypeEnum.LIMIT_AND_OFFSET
    }
);

@bashleigh
Copy link
Collaborator Author

I think after several extra months, it's pretty unanimous that limit and offset is the prefered method.
After doing some reading a long time ago here is a general gist to remind others

Limit & Offset

Uses query based method for selection

Skip & Take

Uses javascript filter to filter results

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants