azure - 为什么 Cosmos DB 在索引属性上显示索引利用率 0.00 %?
问题描述
你能说出为什么索引利用率是 0.00 % 吗?
我在索引策略中包含了这条路径:
{
"path": "/receivedDateTime/?",
"indexes": [
{
"kind": "Range",
"dataType": "Number",
"precision": -1
},
{
"kind": "Hash",
"dataType": "String",
"precision": 3
}
]
}
这是我的文件的一个例子:
{
"id": "",
"userId": "XYZ",
...
"receivedDateTime": 635903262620000000,
...
}
当我运行以下查询时,索引利用率为零。笔记:
- 我在索引策略中包含的任何其他属性/路径都不会发生这种情况
UserId 是分区键
client.CreateDocumentQuery<Message>(UriFactory.CreateDocumentCollectionUri(_databaseId, _collectionId), new FeedOptions { PopulateQueryMetrics = true, MaxItemCount = maxItemCount }) .Where(item => item.UserId == Guid.Parse("XYZ")) .OrderBy(m => m.ReceivedDateTime) .AsDocumentQuery();
另一方面,如果我添加item.ReceivedDateTime >= 0
到 where 子句,即使item.ReceivedDateTime >= 0
所有文档都为 true,我也会得到 98.02% 的索引利用率。
client.CreateDocumentQuery<Message>(UriFactory.CreateDocumentCollectionUri(_databaseId, _collectionId),
new FeedOptions
{
PopulateQueryMetrics = true,
MaxItemCount = maxItemCount
})
.Where(item => item.UserId == Guid.Parse("XYZ") && item.ReceivedDateTime >= 0)
.OrderBy(m => m.ReceivedDateTime)
.AsDocumentQuery();
谢谢
解决方案
像我的其他数据库一样,索引属性可能在存储时已经排序。因此,使用OrderBy
不会像实际对其进行索引那样密集Where
。
这里有更多关于它的信息,给你一个提示:https ://azure.microsoft.com/en-gb/blog/order-query-results-with-azure-documentdb/
推荐阅读
- angular - 将 ngFor 与 formArray 一起使用时,垫子扩展面板不会在垫子卡内呈现
- oracle - Oracle 动态连接(或移动行)
- asp.net-core - 在 ng build --prod --configuration=development 期间生成的文件与发布目标期望复制的文件不同
- c# - 了解 NuGet 包 - 包文件夹
- php - 无法使用 find 方法或 api 平台获取我的实体?
- html - vuetify v-col xs="12" 只填充一半宽度
- c++ - 有没有办法绕过错误“因为'this'参数丢弃了限定符?
- codeigniter - 如何在codeigniter中按id显示记录
- c++ - 如何将字符串的字符推入二维向量
- html - 如何从数组中填充下拉菜单并选择添加到表中的选项