microsoft / spring-data-cosmosdb

Access data with Azure Cosmos DB
MIT License
94 stars 64 forks source link

Pagination returns all the documents #366

Closed blackbaud-alanacable closed 5 years ago

blackbaud-alanacable commented 5 years ago

Hi,

Let's say I have a Cosmos database with 10,000 documents. I do a findAll query with a page size of 20. On line 498 (in the paginationQuery method) of DocumentDbTemplate, I set a breakpoint. For the first page, I hit that breakpoint and inspect sqlQuerySpec. The query is SELECT * FROM ROOT r. The iterator that is returned back contains all 10,000 documents. It is the for loop on the next line that creates a list equal to my page size.

My question is, why do all 10,000 documents need to be fetched? This seems very expensive if your database is large. Why not do select top PAGE_SIZE * from ROOT r?

Thanks, Alana

blackbaud-alanacable commented 5 years ago

On Page2, using the continuation token 9980 documents are returned, on page3, 9960 documents are returned and so on.

blackbaud-alanacable commented 5 years ago

I see whats happening now. The data is fetched in the iterator. Im closing this issue, since I was mistaken. Sorry :(