问题描述
我想知道在添加新的Composite索引时要考虑的事情,并且它对数组字符串有效吗?
示例宇宙文档
{
"id": "ed78b9b5-764b-4ebc-a4f2-6b764679","OrderReference": "X000011380","SetReferences": [
"000066474884"
],"TransactionReference": "ed78b9b5-764b-4ebc-6b7644f06679","TransactionType": "Debit","Amount": 73.65,"Currency": "USD","BrandCode": "TestBrand","PartitionKey": "Test-21052020-255","SettlementDateTime": "2020-05-21T04:35:35.133Z","ReasonCode": "TestReason","IsProcessed": true,}
我的现有索引政策
{
"indexingMode": "consistent","automatic": true,"includedpaths": [
{
"path": "/PartitionKey/?"
},{
"path": "/BrandCode/?"
}
],"excludedpaths": [
{
"path": "/*"
},{
"path": "/\"_etag\"/?"
}
],"compositeIndexes": [
[
{
"path": "/PartitionKey","order": "ascending"
},{
"path": "/IsProcessed","order": "ascending"
}
]
]
}
要从字符串SettlementReferences,IsProcessed,ReasonCode的数组中获取数据。
SELECT * FROM c WHERE ARRAY_CONTAINS(c.SettlementReferences,'00884') and c.IsProcessed = true and c.ReasonCode = 'TestReason'
我正计划添加以下政策
{
"indexingMode": "consistent","order": "ascending"
}
],[
{
"path": "/SettlementReferences",{
"path": "/ReasonCode","order": "ascending"
}
]
]
}
请让我知道此更改是否足够?
此外,我尝试比较更改前后的RU。我看不出有什么大的差异,两者都在133.56卢比附近。
为了优化性能,我还需要考虑什么吗?
解决方法
综合索引将无法帮助该查询,并且总体上不会对相等性语句产生任何影响。当在查询中进行排序时,它们很有用。这就是为什么您在查询中看不到任何RU / s减少的原因。但是,您会注意到写入时的RU / s增加。
如果要提高查询性能,应将where子句中的所有属性添加到索引策略中的“ includedPaths
”中。
还要指出的另一件事是,通常最好的做法是在默认情况下为所有内容建立索引并有选择地将属性添加到excludesPaths中。这样,如果您的架构发生更改,它将自动建立索引,而无需重建索引。
,如前所述,我们需要为数组“ / SettlementReferences / [] /?”添加包含路径。将我的Ru数量从115减少到5 ru。