代码之家  ›  专栏  ›  技术社区  ›  Eoin Campbell

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

  •  0
  • Eoin Campbell  · 技术社区  · 6 年前

    我试着调试两个单独的cosmos db collection之间的一个非常奇怪的离散性,它在面值上的配置是相同的。

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

    旧查询

    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降低。但仅在生产环境中。

    而原因似乎是在生产中,它没有触及指数。请参阅下面两个环境的输出。

    采集规模:2000ru/s

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

    产品配置

    采集规模:10000 RU/s

    {
        "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显示索引未命中,尽管索引策略之间没有明显的差异。

    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
    

    生产结果

    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
    

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

    在调试/解决此问题方面,任何人都知道我可以从何处着手。

    0 回复  |  直到 6 年前
        1
  •  3
  •   Mark Brown    6 年前

    您的Dev容器比较新,并且使用了我们的v2索引,该索引有显著的改进,包括在Array_Contains()上。若要了解有关如何升级产品容器的详细信息,请发送电子邮件至microsoft.com上的askcosmosdb。

    谢谢。