为什么我看到2个看似相同的CosmosDb集合之间的索引行为不同

Eoi*_*ell 5 indexing query-performance azure-cosmosdb azure-cosmosdb-sqlapi

我正在尝试调试2个单独的cosmos db集合之间的一个非常奇怪的差异,该差异在表面值上配置为相同。

我们最近修改了一些执行以下查询的代码。

旧查询

SELECT * FROM c 
WHERE c.ProductId = "CODE" 
AND c.PartitionKey = "Manufacturer-GUID"
Run Code Online (Sandbox Code Playgroud)

新查询

SELECT * FROM c
WHERE (c.ProductId = "CODE" OR ARRAY_CONTAINS(c.ProductIdentifiers, "CODE")) 
AND c.PartitionKey = "Manufacturer-GUID"
Run Code Online (Sandbox Code Playgroud)

Array_Contains在生产环境中引入该调用使该查询的性能从〜3 RU / s ==>〜6000 RU / s降低。但仅在生产环境中。

原因似乎是在生产中,它没有达到指标。有关这两种环境,请参见下面的输出。

开发人员配置

收集规模:2000 RU / s

索引策略:(请注意ETag的排除路径)

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "String",
                    "precision": -1
                },
                {
                    "kind": "Spatial",
                    "dataType": "Point"
                }
            ]
        }
    ],
    "excludedPaths": [
        {
            "path": "/\"_etag\"/?"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

产品配置

收集规模:10,000 RU / s

索引策略:(请注意,与DEV相比,缺少ETag的排除路径)

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                },
                {
                    "kind": "Range",
                    "dataType": "String",
                    "precision": -1
                },
                {
                    "kind": "Spatial",
                    "dataType": "Point"
                }
            ]
        }
    ],
    "excludedPaths": []
}
Run Code Online (Sandbox Code Playgroud)

比较两种环境的输出结果时,尽管索引策略之间没有明显差异,但DEV显示的是索引命中,而PROD的是显示索引未命中。

DEV中的结果

Request Charge:           3.490 RUs
Showing Results:          1 - 1
Retrieved document count: 1
Retrieved document size:  3118 bytes
Output document count:    1
Output document size:     3167 bytes
Index hit document count: 1
Run Code Online (Sandbox Code Playgroud)

PROD中的结果

Request Charge:           6544.870 RUs
Showing Results:          1 - 1
Retrieved document count: 124199
Retrieved document size:  226072871 bytes
Output document count:    1
Output document size:     3167 bytes
Index hit document count: 0
Run Code Online (Sandbox Code Playgroud)

我唯一能在网上找到的是文档中对Cosmos Collection中发生的某些更改的引用,该更改指出“ New Index Layout”正在用于较新的collection,但是没有其他提及Index Layouts的内容。我可以在文档中的任何地方找到的概念。

https://docs.microsoft.com/zh-cn/azure/cosmos-db/index-types#index-kind

任何人都知道我可以从此处调试或解决此问题。

Mar*_*own 2

您的开发容器较新,并使用我们的 v2 索引,该索引在包括 Array_Contains() 方面都有显着改进。要了解有关如何升级 PROD 容器的更多信息,请发送电子邮件至 microsoft dot com 的 Askcosmosdb。

谢谢。

  • 这个答案确实需要更新:这个“v2”索引到底是什么?有哪些“改进”?如何升级?“给我们发电子邮件寻求帮助”并不是真正的答案。 (4认同)