Scylladb:防止特定列上的重复条目

发布于 2025-01-26 09:05:14 字数 319 浏览 5 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紫轩蝶泪 2025-02-02 09:05:14

实现这一目标的最可靠方法是使所有这些列中的所有四个成为表的主要键的一部分。键自然会被删除或更好地说,具有关键价值的新文字只会用上述密钥覆盖旧值。
您提到当前的架构是这样的(假设文本为简单的类型):

CREATE TABLE ks.tbl (
    K1 text,
    K2 text,
    V1 text,
    V2 text,
    V3 text,
    PRIMARY KEY(K1, K2)
);

您可以将主键更改为这样:主键(K1,(K2,V1,V2))
您仍然可以根据k1k2来查询,因为聚类限制仅允许指定聚类键的前缀。

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):

CREATE TABLE ks.tbl (
    K1 text,
    K2 text,
    V1 text,
    V2 text,
    V3 text,
    PRIMARY KEY(K1, K2)
);

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 and K2, as clustering restrictions allow for only a prefix of the clustering key to be specified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文