TableClient.Query<T> 如果不使用 AsPages() 会发起多少请求?

huangapple go评论56阅读模式
英文:

How many requests TableClient.Query<T> will make, if AsPages() is not used?

问题

I have a question about Pageable&lt; T &gt; 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&lt;Domain&gt;()
                .AsPages()
                .SelectMany(d =&gt; d.Values);

But i dont understant something. What if i use Query< T > without AsPages method ?

IEnumerable&lt;Domain&gt; domainsPAges = tableClient.Query&lt;Domain&gt;();

I know that AsPages() returns a collection of pages. For example if I have 10000 items in the table, Query&lt;Domain&gt;().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&lt;Domain&gt; domainsPAges = tableClient.Query&lt;Domain&gt;(); 

Query&lt;Domain&gt;() return Pageble&lt; T &gt; 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.

英文:

I have a question about Pageable&lt; T &gt; 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&lt;Domain&gt;()
                .AsPages()
                .SelectMany(d =&gt; d.Values);

But i dont understant something. What if i use Query< T > without AsPages method ?

IEnumerable&lt;Domain&gt; domainsPAges = tableClient.Query&lt;Domain&gt;();

I know that AsPages() returns a collection of pages. For example if I have 10000 items in the table, Query&lt;Domain&gt;().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&lt;Domain&gt; domainsPAges = tableClient.Query&lt;Domain&gt;(); 

Query&lt;Domain&gt;() return Pageble&lt; T &gt; 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.

答案1

得分: 1

"How many requests Query will make, if AsPages() is not used?"

  • 如果不使用AsPages()方法,Query<T>方法会进行多少次请求?

"In C#, the Query method is part of the Azure Cosmos DB SDK."

  • 在C#中,Query<T>方法是Azure Cosmos DB SDK的一部分。

"The Query method will retrieve all matching results in a single request to the database. This behavior is known as a single-partition query."

  • Query<T>方法将在单个请求中检索所有匹配的结果。这种行为被称为单分区查询。

"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."

  • 如果查询涉及多个分区,那么Query<T>方法将进行多次请求以检索所有匹配的结果。确切的请求次数取决于涉及的分区数量和结果集的大小。

"If the AsPages() method is not used, then the query results will be returned as a single enumerable object. If the AsPages() 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."

  • 如果不使用AsPages()方法,查询结果将作为单个可枚举对象返回。如果使用AsPages()方法,查询结果将作为页面序列返回,每个页面包含查询结果的子集。在这种情况下,请求次数将取决于每个页面的大小和与查询条件匹配的结果总数。

"What if I use Query without AsPages method"

  • 如果我在C#中使用Query&lt;T&gt;而不使用AsPages方法会发生什么?

"In C#, if you use Query<T> without the AsPages method, you will receive all the results of the query in a single batch."

  • 在C#中,如果你使用Query<T>而不使用AsPages方法,你将在单个批处理中接收查询的所有结果。

"The Query 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."

  • Query<T>方法返回表示查询结果的IEnumerable。如果不使用AsPages,整个结果集将一次性加载到内存中。这会导致高内存使用,并可能降低性能,因为它可能消耗大量内存。

"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."

  • AsPages方法还允许您以更高效的方式检索结果。它允许您以较小的批次或页面检索结果,这可以帮助减少内存使用并提高性能。AsPages方法返回一个IAsyncEnumerable<Page<T>>,其中每个Page表示结果的一页。

"Query() return Pageable 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?"

  • Query()返回Pageable,但它是否会再次对表进行10次请求,或者会获取所有元素直到内存溢出(默认为4 MB),或者会一次获取所有元素?

"The behavior of Query() depends on the implementation of the method and the underlying database system."

  • Query()的行为取决于方法的实现和底层数据库系统。

"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() 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."

  • 因此,如果您使用特定的页面大小调用Query(),它将仅检索在该页面大小中指定的元素数量,而不是表中的所有元素。

"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."

  • 用于存储检索结果的内存将取决于检索的对象的大小以及每个页面中检索的对象数量。使用可分页结果时,通常会限制返回的对象的大小以减少内存使用,因此不太可能超过默认的4 MB限制。

For more information refer this Query table entities and SO Thread.

英文:

>How many requests Query<T> will make, if AsPages() is not used?

In C#, the Query<T> method is part of the Azure Cosmos DB SDK.

The Query&lt;T&gt; 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<T> 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 the AsPages() 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.

>What if i use Query< T > without AsPages method

In C#, if you use Query&lt;T&gt; without the AsPages method, you will receive all the results of the query in a single batch.

The Query&lt;T&gt; method returns an IEnumerable<T> 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&lt;Page&lt;T&gt;&gt;, where each Page<T> represents a page of results.

> 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?

The behaviour of Query<Domain>() 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&lt;Domain&gt;() 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.

huangapple
  • 本文由 发表于 2023年2月16日 13:16:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75468105.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定