Skip to content

Support to set maxRows as well as fetchSize of Statement #3453

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

Open
quaff opened this issue Apr 16, 2025 · 6 comments
Open

Support to set maxRows as well as fetchSize of Statement #3453

quaff opened this issue Apr 16, 2025 · 6 comments

Comments

@quaff
Copy link

quaff commented Apr 16, 2025

This is standard way to limit results size without writing dialect.

I'd like to prepare PR if the team accepts proposal.

@harawata
Copy link
Member

Hello @quaff ,

Recently, I explained why setMaxRows is not so useful compared to the SQL solution.
#3436 (comment)

@quaff
Copy link
Author

quaff commented Apr 16, 2025

The best way is to limit the number of returned rows in SQL using FETCH NEXT x ROWS ONLY or LIMIT x.

Not every database and every version follows SQL:2008 standards, setMaxRows() is the most portable solution.

@harawata
Copy link
Member

Here is an excerpt from the linked article.

Conclusion
Although it looks like the setMaxRows is a portable solution to limit the size of the ResultSet, the SQL-level pagination is much more efficient if the database server optimizer doesn't use the JDBC maxRows property.

The main purpose of limiting rows is performance, so even though setMaxRows() is portable, it does not make much sense if the effect depends on the database.
What would you say?

@quaff
Copy link
Author

quaff commented Apr 16, 2025

Some use case requires consuming first n rows of given sql, for example, find latest or top rated n comments of an article, the portable way is query all comments as List then call List.subList() to limit, the performance is worse than setMaxRows().

@harawata
Copy link
Member

My point is: if the performance matters, you should use the non-portable way.

Anyway, I do not strongly oppose your proposal. It is part of the JDBC API after all.
@jeffgbutler @epochcoder Any opinion on this?

quaff added a commit to quaff/mybatis-3 that referenced this issue Apr 17, 2025
Closes mybatisGH-3453

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
@quaff
Copy link
Author

quaff commented Apr 17, 2025

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

No branches or pull requests

2 participants