offset/limit vs page/pagesize

What is the difference between offset/limit vs page/pagesize ? I see when using page/pagesize grid loads comparatively faster

They are essentially just expressing the same thing in bit different ways. In recent Vaadin versions, the Grid fetches data from the backend with deterministic pages, so ready calculated page/pagesize is there for better developer experience.

There shouldn’t be a difference in performance. Maybe something wrong in your version of code that is using offset/limit :thinking:

You can check the query done and see if they are different

Looks there is no count query getting executed when using Page/PageSize. I’m not seeing it and FYI I tested this with H2 DB

That depends on which version of the lazy loading API you are using. You can also use offset+limit and not provide the total size and visa versa.

is it ? I see the total count query is getting executed automatically.

can you provide an example where I can ignore this count query ? I’m migrating from V14 to V24

If you use setItems(CallbackDataProvider.FetchCallback<T,F> fetchCallback, CallbackDataProvider.CountCallback<T,F> countCallback) or some of the old school DataProvider variants, the count query is made&required. If you use the setItems(CallbackDataProvider.FetchCallback<T,F> fetchCallback) variant, the count query is not needed. It doesn’t matter if you use page/pagesize or offset/limit from the query object to determine which items to return.

Hi,

Sorry to revive this post, but in my mind it lacks some information I just found, when figuring out that there were duplicates in my grids. I’m working with Vaadin 23.

getPageSize() must be used with getPage(), and called AFTER getPage(), because getPage() can modify the output of getPageSize().

In my case, I have a grid with 87 items, with 50 items per page, backed with a Spring data pagination (PageRequest.of … )
First page is loaded perfectly, but the second one loads duplicate from the first page. It was because we used getOffset() and getPageSize() the following way :
PageRequest.of(query.getOffset() / pageSize, pageSize, this.currentSort)

When displaying the second page of our grid: pageSize = 37, which causes Spring to consider that 37 items should be returned from page 1, but then also considering that the page 0 is 37 items too ! This resulted then in the display of 13 duplicates in the grid.

This should be documented somewhere. When I first read the javadoc of getPageSize, I didn’t understood it (maybe because english is not my mother tong). Then when doing some tests, I figured out that getPageSize() didn’t return the same value, then I checked its code, and It was… the revelation ! :grin:

Regards,
Sébastien.