以下查询可以直接从索引中回答,因为“ partition”是分区键(并且在默认索引策略中是范围索引)。
"SELECT value count(1) FROM c WHERE c.partition = 'xxx'"
但是,查询指标显示未使用索引。相反,它会产生大量的RUs费用...
任何想法可能是什么问题?
var client = DatabaseClient.Client;
IDocumentQuery<dynamic> query = client.CreateDocumentQuery(
UriFactory.CreateDocumentCollectionUri(DatabaseClient.DatabaseName, DatabaseClient.CollectionName),
"SELECT count(1) FROM c WHERE c.partition = 'xxx',
new FeedOptions
{
PartitionKey = new PartitionKey("xxx"),
PopulateQueryMetrics = true,
MaxItemCount = -1,
MaxDegreeOfParallelism = -1,
EnableCrossPartitionQuery = false
}).AsDocumentQuery();
FeedResponse<dynamic> result = await query.ExecuteNextAsync();
// Returns metrics by partition key range Id
IReadOnlyDictionary<string, QueryMetrics> metrics = result.QueryMetrics;
指标显示索引使用率为0。