如何在没有分区键的情况下更新一行?

huangapple go评论50阅读模式
英文:

How do I update a row without the partition key?

问题

在我的Cassandra数据库上,有4个节点,我想执行如下的更新语句。

UPDATE table_todo SET todoUserKey = '123' WHERE todoUserKey = "000";

我得到了一个异常。

InvalidRequest: Error from server: code=2200 [Ivalid query] message="Some partition key parts are missing: id"

据我了解,由于Cassandra在多个节点上运行,我需要明确指定在哪个节点上执行我的更新操作。

但是我没有关于ID的任何信息。我该如何执行这个更新语句?

英文:

On my Cassandra DB with 4 Nodes, I want to execute an update statement like this.

UPDATE table_todo SET todoUserKey = '123' WHERE todoUserKey = "000";

I get an exception

InvalidRequest: Error from server: code=2200 [Ivalid query] message="Some partition key parts are missing: id"

As I understand because of Cassandra running on multiple nodes, I need to specify exactly on which node I need to execute my Update operation.

But I dont have any information about the ID. How I can perform the update statement?

答案1

得分: 2

你必须识别行。Cassandra要求所有写操作提供精确的主键。根据UPDATE命令的CQL文档:

WHERE子句用于选择要更新的行,并必须包括主键的所有列。

英文:

You must identify the row. Cassandra requires for all write operations to provide the exact primary key. From the CQL docs of UPDATE command:
> The WHERE clause is used to select the row to update and must include
> all columns of the PRIMARY KEY

答案2

得分: 2

无法执行您的查询,因为如果允许执行,这意味着Cassandra必须执行完整的表扫描,以检查群集中每个分区上的每一行。

允许这样的更新操作根本不可扩展。如果您有一个具有数十亿个分区的表,每个分区都有数百或数千行,而且在具有数百个节点的集群中,很容易理解允许查询运行的代价非常高,性能不佳。

正是因为这个确切的原因,您需要指定分区键以及(如果适用)聚簇列,以便Cassandra可以更新分区内的特定行(或多行),而无需执行完整的表扫描。祝好运!

英文:

It isn't possible to execute your query because if it was allowed, it means Cassandra has to perform a full table scan to check every single row on every single partition on every single node in the cluster.

Allowing such update operate simply does not scale. If you had a table with billions of partitions, each with hundreds or thousands of rows in a cluster with hundreds of nodes, it's not difficult to see that the allowing the query to run is very expensive and will not perform well.

For this exact reason, you need to specify not just the partition key but the clustering column (where appropriate) so Cassandra can update the specific row (or rows) within the partition without having to perform a full table scan. Cheers!

huangapple
  • 本文由 发表于 2023年2月14日 21:14:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448387.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定