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

问题描述 投票:4回答:1

我正在尝试调试两个独立的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中消失。但仅限于生产环境。

原因似乎是在生产中,它没有达到指数。请参阅下面的输出以了解两种环境。

DEV配置

收集规模:2000 RU / s

索引政策:(注意ETags的排除路径)

{
    "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\"/?"
        }
    ]
}

PROD CONFIGURATION

收集规模:10,000 RU / s

索引政策:(注意ETAG与DEV相比没有排除路径)

{
    "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中发生的一些变化,声明新的集合使用了“新索引布局”,但没有提到索引布局作为我可以在文档的任何地方找到的概念。

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

在调试/解决这个问题方面,任何人都知道我可以从哪里开始。

indexing azure-cosmosdb query-performance azure-cosmosdb-sqlapi
1个回答
3
投票

您的Dev容器更新并使用我们的v2索引,该索引具有重大改进,包括Array_Contains()。要了解有关如何升级PROD容器的更多信息,请发送电子邮件至microscos dot com的askcosmosdb。

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.