azure - 文档数据库 : How to verify which indexes were used?

标签 azure indexing azure-cosmosdb sql-execution-plan

即使您精心设计了文档架构,并手工制作了最少的必要索引,以实现读取与更改场景的良好平衡,但哪个索引实际上正在为重型 RU 查询执行工作以及选择是否可行,可能并不总是直观的是你所期望的。或者,关键属性名称中的索引策略可能存在拼写错误,导致静默回退到其他查询所需的某些不合适的索引。

我知道我可以使用以下工具来调试 DocumentDB 中的索引使用情况:

  • RequestCharge 每个查询的使用情况,但没有说明此 RU 的用途。
  • 使用 x-ms-documentdb-populatequerymetrics header 的时间/计数指标,这很有用,并暗示使用了“某些”索引,但没有实际使用了哪些索引。

问题是上述工具集仍然强制进行盲目实验并基于无法验证的假设,导致查询/索引优化成为一个耗时的过程。

在 SQL Server 中,您可以简单地获取执行计划并验证索引设计和使用的正确性。 DocumentDB 有类似的工具吗?

当 DocDB 将选择哪个索引并不明显时,查询的说明性伪示例:

select s.poorlySelectiveIndexed
from c
join s in c.sub
where c.anotherPoorlySelectiveIndexed = @aCommonValue
   and s.Indexed1 in ('a', 'b', 'c') 
   and ARRAY_CONTAINS(s.Indexed2, @searchValue)
   and ARRAY_CONTAINS(s.Indexed3, 'literalValue')
   and (s.SuperSelective ='23456' OR c.AnotherSuperSelective = '76543') 
order by s.RangeIndexed4

最佳答案

似乎 documentDB 团队正在考虑已经提到的 x-ms-documentdb-populatequerymetrics header 及其相应的响应作为这样的工具。

this response from "Azure Cosmos DB Team" in Azure feedback site 中所述自 2017 年 8 月 27 日起:

We’re pleased to announce the availability of query execution statistics: https://learn.microsoft.com/en-us/azure/cosmos-db/documentdb-sql-query-metrics#query-execution-metrics

Using these metrics, you can infer the execution plan and tune the query and index for best performance tradeoffs.

目前似乎没有正式公开有关所用索引的详细信息,但我们希望它会在未来的版本中有所改变。

关于azure - 文档数据库 : How to verify which indexes were used?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47031250/

相关文章:

azure - 有没有办法停止执行 Azure 认知搜索索引器?

azure - 在 Cosmos Db 中查询文档进行日期比较时如何截断时间

mysql - 使用覆盖索引选择某一天的记录

mongodb - 通过代码在 Cosmos DB 中启用 Mongo DB 聚合管道

c# - 来自 Web 应用程序的 .NET 实时电子邮件通知

asp.net-mvc - Azure 应用服务可用性损失。内存计数器每秒页读取数处于危险水平

search - 重建 Screwturn wiki 搜索索引

postgresql - Postgres - 用于读取之前或之后日期的日期索引(<、<=、>、>=)

c# - Azure HTTP 函数无法发布

python - CosmosDB 和 Python3 : how to query?