Cassandra Batch语句-多个表 [英] Cassandra Batch statement-Multiple tables

查看:147
本文介绍了Cassandra Batch语句-多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用批处理语句从数据库中的3个表中删除一行,以确保原子性。所有三个表中的分区键都将相同。在我阅读的有关批处理语句的所有示例中,所有查询都针对单个表?就我而言,使用批处理语句是一个好主意吗?或者,应该避免吗?

I want to use batch statement to delete a row from 3 tables in my database to ensure atomicity. The partition key is going to be the same in all the 3 tables. In all the examples that I read about batch statements, all the queries were for a single table? In my case, is it a good idea to use batch statements? Or, should I avoid it?

我正在使用Cassandra-3.11.2,并且使用C ++驱动程序执行查询。

I'm using Cassandra-3.11.2 and I execute my queries using the C++ driver.

推荐答案

是的,您可以使用批处理来确保原子性。单个分区批处理速度更快(相同的表和相同的分区键),但是仅对于有限数量的分区(在您的情况下为三个)是可以的。但是请勿将其用于性能优化(例如:减少多个请求)。如果需要原子性,可以使用它。

Yes, you can use batch to ensure atomicity. Single partition batches are faster (same table and same partition key) but only for a limited number of partitions (in your case three) it is okay. But don't use it for performance optimization (Ex: reduce of multiple requests). If you need atomicity you can use it.

您可以检查以下链接:

在具有不同分区键的表上执行Cassandra批处理查询

Cassandra批处理查询与单插入性能

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

已编辑



在我的情况下,表是不同的,但是分区键在所有3个表中都是相同的。那么这是单分区批处理的特殊情况还是完全不同。

In my case, the tables are different but the partition key is the same in all 3 tables. So is this a special case of single partition batch or is it something entirely different.


对于不同的表,分区也不同。因此,这是一个多分区批处理。 LOGGED 批处理用于确保不同分区(不同表或不同分区键)的原子性。 UNLOGGED 批处理用于确保单个分区批处理的原子性和隔离性。如果将 UNLOGGED 批处理用于多分区批处理原子性,将无法保证。默认为 LOGGED 批次。对于单个分区批处理,默认值为 UNLOGGED 。原因是将单个分区批处理视为单行突变。对于单行更新,无需使用 LOGGED 批处理。要了解 LOGGED UNLOGGED 批次,我在下面共享了一个链接。

For different tables partitions are also different. So this is a multi partition batch. LOGGED batches are used to ensure atomicity for different partitions (different tables or different partition keys). UNLOGGED batches are used to ensure atomicity and isolation for single partition batch. If you use UNLOGGED batch for multi partition batch atomicity will not be ensured. Default is LOGGED batch. For single partition batch default is UNLOGGED. Cause single partition batch is considered as single row mutation. For single row update, there is no need of using LOGGED batch. To know about LOGGED or UNLOGGED batch, I have shared a link below.


多分区批处理仅应用于实现对不同表的几次写入的原子性。除此之外,应避免使用它们,因为它们太昂贵了。

Multi partition batches should only be used to achieve atomicity for a few writes on different tables. Apart from this they should be avoided because they’re too expensive.

单个分区批处理可用于实现原子性和隔离性。它们并不比普通写入昂贵得多。

Single partition batches can be used to achieve atomicity and isolation. They’re not much more expensive than normal writes.

但是您可以使用多分区 LOGGED 批处理作为分区是有限的。

But you can use multi partition LOGGED batch as partitions are limited.

批处理中非常有用的文档,并且提供了所有详细信息。如果您阅读了这篇文章,所有的困惑将被清除。

A very useful Doc in Batch and all the details are provided. If you read this, all the confusions will be cleared.

Cassandra-批处理或不批处理

分区键令牌与行分区

表分区和分区键令牌是不同的。分区键用于确定数据所在的节点。对于相同的行键分区令牌,因此它们位于相同的节点中。对于不同的分区键或相同的键不同的表,它们是不同的行突变。您无法通过一个查询来查询不同的分区键或从不同的表获得数据,即使是相同的键也是如此。协调器节点必须将其视为不同的请求或变异,并分别从复制的节点请求实际数据。这是C *存储数据的内部结构。

Table partitions and partition key tokens are different. Partition key is used to decide which node the data resides. For same row key partition tokens are same thus resides in the same node. For different partition key or same key different tables they are different row mutation. You cannot get data with one query for different partition keys or from different tables even if for the same key. Coordinator nodes have to treat it as different request or mutation and request the actual data from replicated nodes separately. It's the internal structure of how C* stores data.


每个表甚至都有自己的目录结构,这清楚地表明一个表的分区永远不会与另一个分区交互。

Every table even has it's own directory structure making it clear that a partition from one table will never interact with the partition of another.

Does the same partition key in different cassandra tables add up to cell theoretical limit?

要了解有关C *如何映射数据的详细信息,请检查以下链接:

To know details how C* maps data check this link:

了解CQL3如何映射到Cassandra的内部数据结构

这篇关于Cassandra Batch语句-多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆