带有附加where子句和过滤器的cassandra查询

e4eetjau  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(298)

我正在尝试从cassandra中的一个表中删除,我想根据附加的where子句删除,该子句不是主键的一部分,但我也可以传递主键。场景是我想从搜索表中删除一条记录,该记录在附加列中有目标表id。搜索字段是主键,例如:
目标表:

create table user (id text primary key, email text, other_data text)

搜索表:

create table emails(email text primary key, id text)

现在我想从emails表中删除,只有当一封邮件属于一个特定的id时。如果我发出如下声明是否可以: delete from emails where email ='a@test.com' and id ='' 这需要允许过滤,否则它会抱怨。

pxy2qtax

pxy2qtax1#

您尝试执行的语法不起作用(where条件中的备用列不是主键的一部分)。
您可以执行以下操作:

delete from emails where email ='a@test.com' if id = 'abc';

这是可行的,但需要注意的是:

Conditional deletions incur a non-negligible performance cost and should be used sparingly.

不确定你的陈述的数量,但是大量的陈述可能是显而易见的。
-吉姆

相关问题