Cassandra 中的单分区批处理如何用于多列更新?
How single partition batch in Cassandra function for multiple column update?
我们在单个列族的单个分区中有多个更新查询。喜欢下面
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;
username
、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.
或者我们应该像下面那样批量添加查询。在这种情况下,我们必须检查用户名,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;
简而言之,最好的方法是什么。
您正在使用单分区批处理,因此所有内容都进入一个分区。因此您的所有更新将合并并应用单个 RowMutation。
因此您的更新将在没有批处理日志、原子、隔离的情况下应用
对于您的第一个问题(C* 会将其合并为一个语句吗?)答案是肯定的。
单分区批处理作为单行突变应用。
查看此 link 了解详细信息:
https://issues.apache.org/jira/browse/CASSANDRA-6737
对于你的第二个问题(C*会比较每一列(用户名,url)的值吗?)答案也是肯定的。
如您提供的 "Conflict is resolved by choosing the largest value for the cells"
的答案所示
因此,您可以通过任何一种方式(在您的问题中给出)批量编写查询。
因为它最终会在内部转换为单次写入。
我们在单个列族的单个分区中有多个更新查询。喜欢下面
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;
username
、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.
或者我们应该像下面那样批量添加查询。在这种情况下,我们必须检查用户名,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;
简而言之,最好的方法是什么。
您正在使用单分区批处理,因此所有内容都进入一个分区。因此您的所有更新将合并并应用单个 RowMutation。
因此您的更新将在没有批处理日志、原子、隔离的情况下应用
对于您的第一个问题(C* 会将其合并为一个语句吗?)答案是肯定的。
单分区批处理作为单行突变应用。
查看此 link 了解详细信息: https://issues.apache.org/jira/browse/CASSANDRA-6737
对于你的第二个问题(C*会比较每一列(用户名,url)的值吗?)答案也是肯定的。
如您提供的
因此,您可以通过任何一种方式(在您的问题中给出)批量编写查询。 因为它最终会在内部转换为单次写入。