问题描述
有人可以简单地解释一下Cassandra中的静态列及其用途吗?
我遇到了此链接静态列
Can someone explain in simple terms what is the static column in Cassandra, and its use?I came across this link Static column, but wasn't able to understand it much.
谢谢
推荐答案
静态列是将数据与整个分区关联的一种方式,因此它将在该分区内的所有行之间共享。在某些情况下,当所有行都需要具有相同的数据并且更新了数据时,我们就不需要更新每一行。
Static column is a way to associate data with the whole partition, so it will be shared between all rows inside that partition. There are legitimate cases, when all rows need to have the same data, and when data is updated, we won't need to update every row.
下面是一个示例考虑到电子商务。例如,您要卖东西,并且您在不同的国家/地区使用不同的货币和货币销售商品。不同的价格。但是它们之间有一些共同点,例如描述,大小等。在这种情况下,我们可以对其建模如下:
One example that comes in mind is e-commerce. For example, you're selling something, and you're selling in different countries with different currency & different prices. But some things are common between them, like, description, sizes, etc. In this case we can model it as following:
create table articles (
sku text,
description text static,
country text,
currency text,
price decimal,
primary key (sku, country)
);
在这种情况下,当您执行时,请从sku =的文章中选择*。 .. and country = ...
,那么无论如何您都可以获得描述,并且只能使用更新文章集description ='...'来更新描述,其中sku = ...
,然后单击下一步将提取更新的描述。
in this case, when you do select * from articles where sku = ... and country = ...
then you get description anyway, and you can update description only with update articles set description = '...' where sku = ...
, and next select will pull updated description.
此外,分区中可能存在静态列而没有任何行。我看到的一种用例是收集汇总信息,其中详细数据存储为带有TTL的单独行,并且有一项将数据汇总到静态列中的工作,因此当行过期时,该分区仍然只保留汇总数据。
Also, static columns may exist in partition without any rows. One of the use cases that I've seen is collection of the aggregated information, where detailed data were stored as individual rows with some TTL, and there was a job that aggregated data into static column, so when rows are expired, then this partition still stays only with aggregated data.
这篇关于Cassandra中的静态列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!