简体   繁体   English

查询DateTime字段时,DocumentClient花费的时间太长

[英]DocumentClient takes too long when queried over a DateTime field

I have the following code to get the list of some objects from a DocumentDB database: 我有以下代码从DocumentDB数据库中获取一些对象的列表:

var document = this._client.CreateDocumentQuery<T>(UriFactory.CreateCollectionUri(dbName, collectionName), queryOptions)
.Where(r => r.pDate >= startDate && r.pDate <= endDate);

var result = document.ToList();

pDate is of type DateTime , and stored in the database as string with ISO8601 format. pDate的类型为DateTime ,并以ISO8601格式的字符串形式存储在数据库中。

The query takes unreasonably too long, like 4 to 5 minutes, to return the results back. 查询花费不合理的时间(例如4至5分钟)太长,无法返回结果。 When I trace the program it is that .ToList() where the program gets stuck. 当我跟踪程序时,就是程序卡住的那个.ToList() Oddly, the query quickly returns for some specific start and end dates. 奇怪的是,查询会快速返回一些特定的开始和结束日期。 The query also quickly comes back with some results if I put the filter on some fields other than pDate . 如果我将过滤器放在pDate以外的其他字段上,查询也会很快返回一些结果。

My settings are consistent with explanations in this document but I still get a very poor performance almost all the time except for those few exceptions. 我的设置与本文档中的解释一致,但是除少数例外外,几乎所有时间我的表现仍然很差。

I have tried several methods mentioned here and there to resolve the issue, but no luck so far. 我已经尝试过在这里和那里提到的几种方法来解决此问题,但是到目前为止还没有运气。 I appreciate any comment or solution to the problem. 感谢您对问题的任何评论或解决方案。

It could be because the indexing that is applied on this particular field. 这可能是因为在此特定字段上应用了索引。

From this link https://docs.microsoft.com/en-us/azure/cosmos-db/indexing-policies , you would need an Range index for range or Order by Queries. 从此链接https://docs.microsoft.com/zh-cn/azure/cosmos-db/indexing-policies ,您将需要一个Range索引用于range或Order by Queries。

The default index policy that is applied to a collection is "Hash for Strings and Range for Numbers" 应用于集合的默认索引策略是“字符串的哈希和数字的范围”

Datetimes are stored as strings, so for running range comparison queries or order by queries you would need to set the indexing policy to "Range" for string datatypes with precision to -1. 日期时间存储为字符串,因此对于运行范围比较查询或按查询排序,对于精度为-1的字符串数据类型,您需要将索引策略设置为“ Range”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM