I have a question about Pageable< T >
in C#. I have table storage in Azure named- Domains. I am using Azure.Data.Tables nuget package, and to Query all the domains i am using this :
var domains = _localDomainTableClient
.Query<Domain>()
.AsPages()
.SelectMany(d => d.Values);
But i dont understant something. What if i use Query< T > without AsPages method ?
IEnumerable<Domain> domainsPAges = tableClient.Query<Domain>();
I know that AsPages()
returns a collection of pages. For example if I have 10000 items in the table, Query<Domain>().AsPages()
should make 10 requests to the table and return me 10 pages with 1000 items in each page (unless I changed the default value) but I don’t understand what exactly is happening if I don’t use AsPages() ?
Example:
IEnumerable<Domain> domainsPAges = tableClient.Query<Domain>();
Query<Domain>()
return Pageble< T >
but, does it make 10 requests to the table again or does it take all the elements until the memory overflows (4 MB by default) or take all the elements at once ?
I check documentation, but I couldn’t find what I needed.
A collection of values that may take multiple service requests to iterate over.
A collection of values retrieved in pages
What is it even mean ?
Thanks for help.
4
Answers
In C#, the Query method is part of the Azure Cosmos DB SDK.
The
Query<T>
method will retrieve all matching results in a single request to the database. This behaviour is known as a single-partition query.If the query involves multiple partitions, then the Query method will make multiple requests to retrieve all matching results. The exact number of requests will depend on the number of partitions involved and the size of the result set.
If the
AsPages()
method is not used, then the query results will be returned as a single enumerable object. If theAsPages()
method is used, the query results will be returned as a sequence of pages, each containing a subset of the query results. In this case, the number of requests made will depend on the size of each page and the total number of results matching the query criteria.In C#, if you use
Query<T>
without the AsPages method, you will receive all the results of the query in a single batch.The
Query<T>
method returns an IEnumerable that represents the results of the query. If you do not use AsPages, the entire result set will be loaded into memory at once. This leads to high memory usage and performance can be degraded, as it can consume a lot of memory.AsPages method also enables you to retrieve the results in a more efficient manner. It allows you to retrieve the results in smaller batches or pages, which can help reduce the memory usage and improve performance. The AsPages method returns an
IAsyncEnumerable<Page<T>>
, where each Page represents a page of results.The behaviour of Query() depends on the implementation of the method and the underlying database system.
when you execute a query that returns a pageable result, the database will execute the query and return only a subset of the results to the application, based on the page size and the current page number. The remaining results are retrieved on subsequent requests for the next pages.
So if you call
Query<Domain>()
with a specific page size, it will only retrieve the number of elements specified in that page size, and not all the elements in the table.The number of requests made to the table will depend on the number of pages that need to be retrieved to return all the results for the query.
The memory used to store the retrieved results will depend on the size of the objects retrieved and the number of objects retrieved in each page. When using pageable results, the size of the objects returned is generally limited to reduce memory usage, so it’s unlikely that the memory usage will exceed the default limit of 4 MB.
For more information refer this Query table entities and SO Thread.
—————–
A collection of values that may take multiple service requests to iterate over.
check with this-http://qa4.sdg.me/600000001403512
thanks bharti96
hi var domain should return some value properly
thanks
hi var domain should be returning some value.
When empty value returns, it throws an error.