与常规查询命令相比,DynamoDB partiQl成本高

发布于 2025-02-04 21:40:48 字数 1442 浏览 1 评论 0原文

我正在尝试编写DynamoDB表达式以过滤某些内容。我注意到以下partiql比我想象的要贵得多。

 aws dynamodb execute-statement --return-consumed-capacity INDEXES --statement 'SELECT * FROM "hit_counts"."as_of_when-the_url-index-2" where "as_of_when" = ? and not contains("the_url", ?)' --parameters "[{\"S\": \"2022-06-06\"},{\"S\":\".html-dev\"}]"

 *snip*

 "ConsumedCapacity": {
    "TableName": "hit_counts",
    "CapacityUnits": 66.0,
    "Table": {
        "CapacityUnits": 0.0
    },
    "GlobalSecondaryIndexes": {
        "as_of_when-the_url-index-2": {
            "CapacityUnits": 66.0
        }
    }
}

但是,如果我省略了标准查询中的一部分(它不断地说我不能使用过滤器表达式中的主键属性),那么它使用的容量要少得多。

aws dynamodb query --table-name hit_counts \                                                                                               
    --index-name as_of_when-the_url-index-2 \                                                                    
    --key-condition-expression 'as_of_when=:foo' --return-consumed-capacity INDEXES \
    --expression-attribute-values "{\":foo\": {\"S\": \"2022-06-06\"}}" \
    --select ALL_PROJECTED_ATTRIBUTES

*snip* 

"ConsumedCapacity": {
    "TableName": "hit_counts",
    "CapacityUnits": 1.0,
    "Table": {
        "CapacityUnits": 0.0
    },
    "GlobalSecondaryIndexes": {
        "as_of_when-the_url-index-2": {
            "CapacityUnits": 1.0
        }
    }
}

这里发生了什么,PartiQL实际上如何创建一个查询计划?

I'm trying to write a dynamodb expression to filter certain things out. I've noticed that the following partiql is significantly more expensive than I thought it would be.

 aws dynamodb execute-statement --return-consumed-capacity INDEXES --statement 'SELECT * FROM "hit_counts"."as_of_when-the_url-index-2" where "as_of_when" = ? and not contains("the_url", ?)' --parameters "[{\"S\": \"2022-06-06\"},{\"S\":\".html-dev\"}]"

 *snip*

 "ConsumedCapacity": {
    "TableName": "hit_counts",
    "CapacityUnits": 66.0,
    "Table": {
        "CapacityUnits": 0.0
    },
    "GlobalSecondaryIndexes": {
        "as_of_when-the_url-index-2": {
            "CapacityUnits": 66.0
        }
    }
}

However if I omit the contains portion in a standard query (It constantly says I can't use a primary key attribute in a filter expression), it uses significantly less capacity.

aws dynamodb query --table-name hit_counts \                                                                                               
    --index-name as_of_when-the_url-index-2 \                                                                    
    --key-condition-expression 'as_of_when=:foo' --return-consumed-capacity INDEXES \
    --expression-attribute-values "{\":foo\": {\"S\": \"2022-06-06\"}}" \
    --select ALL_PROJECTED_ATTRIBUTES

*snip* 

"ConsumedCapacity": {
    "TableName": "hit_counts",
    "CapacityUnits": 1.0,
    "Table": {
        "CapacityUnits": 0.0
    },
    "GlobalSecondaryIndexes": {
        "as_of_when-the_url-index-2": {
            "CapacityUnits": 1.0
        }
    }
}

What's going on here, and how does partiql actually create a query plan?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔梦 2025-02-11 21:40:48

您唯一的索引属性是分区键和排序密钥,要使用这些索引,必须将分区密钥作为确切值提供,将sort键作为值,范围或前缀。您的包含查询不会表达可以优化索引的约束,因此DynamoDB必须过滤以限制结果,并且在过滤时,您的消耗是基于预滤波的数据大小。

进行索引驱动的方法没有直接的方法包含DynamoDB中的约束。

查看DynamoDB的Vanilla非PartiQl接口。在幕后,这些是PartiQl必须使用的原始图。

Your only indexed attributes are the partition key and sort key, and to use these indexes your partition key has to be provided as an exact value and the sort key as either a value, range, or prefix. Your contains query doesn't express a constraint that can be index optimized, so DynamoDB has to filter to limit the results, and when filtering your consumption is based on the pre-filtered data size.

There is no straightforward way to do an index-driven contains constraint in DynamoDB.

Look at the vanilla non-PartiQL interface to DynamoDB. Behind the scenes these are the primitives that PartiQL has to work with.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文