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

时间:2019-02-28 11:16:22

标签: indexing azure-cosmosdb query-performance azure-cosmosdb-sqlapi

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

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

旧查询

SELECT * FROM c 
WHERE c.ProductId = "CODE" 
AND c.PartitionKey = "Manufacturer-GUID"

新查询

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

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

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

DEV配置

收集规模: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\"/?"
        }
    ]
}

产品配置

收集规模: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": []
}

在比较两种环境的输出结果时,尽管索引策略之间没有显着差异,但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

产生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

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

https://docs.microsoft.com/en-us/azure/cosmos-db/index-types#index-kind

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

1 个答案:

答案 0 :(得分:3)

您的Dev容器较新,并且使用我们的v2索引,该索引具有显着的改进,包括Array_Contains()。要了解有关如何升级PROD容器的更多信息,请通过microsoft dot com上的askcosmosdb向我们发送电子邮件。

谢谢。