gpt4 book ai didi

cassandra - Cassandra 中的单分区批处理如何实现多列更新?

转载 作者:行者123 更新时间:2023-12-01 16:40:41 30 4
gpt4 key购买 nike

我们在单个列族的单个分区中有多个更新查询。就像下面这样

update t1 set username = 'abc', url = 'www.something.com', age = ? where userid = 100;
update t1 set username = 'abc', url = 'www.something.com', weight = ? where userid = 100;
update t1 set username = 'abc', url = 'www.something.com', height = ? where userid = 100;

用户名url将始终相同,并且是必填字段。但根据给出的信息,将会有额外的列。

由于这是单个分区操作,我们需要原子性+隔离性。我们将批量执行此操作。

根据文档

A BATCH statement combines multiple data modification language (DML) statements (INSERT, UPDATE, DELETE) into a single logical operation, and sets a client-supplied timestamp for all columns written by the statements in the batch.

现在,当我们在多个语句中更新具有相同值的列(用户名、url)时,C* 会在执行之前将其组合为单个语句吗

update t1 set username = 'abc', url = 'www.something.com', age = ?, weight = ?, height = ? where userid = 100;

或者相同的值将被更新插入?

另一个问题是,由于它们都具有相同的时间戳,C* 如何解决该冲突。 C* 会比较每一列(用户名、url)值。

As they all have the same timestamp C* resolves the conflict by choosing the largest value for the cells. Atomic Batch in Cassandra

或者我们应该像下面这样批量添加查询。在这种情况下,我们必须检查用户名,url 已经添加到语句中。

update t1 set username = 'abc', url = 'www.something.com', age = ? where userid = 100;
update t1 set weight = ? where userid = 100;
update t1 set height = ? where userid = 100;

简而言之,最好的方法是什么。

最佳答案

对于你的第一个问题(C* 会将其合并为单个语句吗?)答案是肯定的。

单个分区批处理作为单行突变应用。

查看此链接了解详细信息: https://issues.apache.org/jira/browse/CASSANDRA-6737

对于你的第二个问题(C* 会比较每一列(用户名、url)值吗?)答案也是肯定的。

正如您提供的答案中所给出的link “通过选择单元格的最大值来解决冲突”

因此,您可以通过任何一种方式批量编写查询(在您的问题中给出)。因为它最终会在内部转换为单个写入。

关于cassandra - Cassandra 中的单分区批处理如何实现多列更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39121092/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com