Scylladb:防止特定列上的重复条目
我正在使用scylladb
,并且有一个具有以下5列的表:
K1 K2 V1 V2 V3
其中k1
是分区密钥,k2
是群集密钥, v1..v3
是表中三个不同值的三列。
我想防止重复值添加到表中,其中k1,k2,v1和v2
与表中的现有条目匹配。换句话说,不应该添加/存储多个行以上,其中该行中的所有4列与现有的行匹配具有相同值的现有行。
这可以通过Scylla实现吗?
谢谢
I'm using ScyllaDB
and I have a table with the following 5 columns:
K1 K2 V1 V2 V3
Where K1
is the partition key, K2
is the clustering key, V1..V3
are three columns representing 3 different values in the table.
I want to prevent duplicate values from being added to the table where K1, K2, V1 and V2
match an existing entry in table. In other words, it should not be possible to add/store more than one row where ALL 4 columns in this row match an existing row with the same values.
Is this possible to achieve with Scylla?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实现这一目标的最可靠方法是使所有这些列中的所有四个成为表的主要键的一部分。键自然会被删除或更好地说,具有关键价值的新文字只会用上述密钥覆盖旧值。
您提到当前的架构是这样的(假设文本为简单的类型):
您可以将主键更改为这样:
主键(K1,(K2,V1,V2))
。您仍然可以根据
k1
和k2
来查询,因为聚类限制仅允许指定聚类键的前缀。The most reliable way to achieve that is to make all 4 of those columns be part of the primary key of the table. Keys are naturally de-duplicated or better said, a new write with a key value will just overwrite the old value with said key.
You mention that the current schema is something like this (assuming text as type for simplicity):
You can change your primary key to be like this:
PRIMARY KEY(K1, (K2, V1, V2))
.You will still be able to query based on just
K1
andK2
, as clustering restrictions allow for only a prefix of the clustering key to be specified.