我正试图通过表中的辅助索引或列键进行删除。我不关心性能,因为这将是一个不寻常的查询。不确定这是否可能?例如:
CREATE TABLE user_range (
id int,
name text,
end int,
start int,
PRIMARY KEY (id, name)
)
cqlsh>从dat.user_range中选择*,其中id=774516966;
id | name | end | start
-----------+-----------+-----+-------
774516966 | 0 - 499 | 499 | 0
774516966 | 500 - 999 | 999 | 500
我可以:
cqlsh> select * from dat.user_range where name='1000 - 1999' allow filtering;
id | name | end | start
-------------+-------------+------+-------
-285617516 | 1000 - 1999 | 1999 | 1000
-175835205 | 1000 - 1999 | 1999 | 1000
-1314399347 | 1000 - 1999 | 1999 | 1000
-1618174196 | 1000 - 1999 | 1999 | 1000
Blah blah…
但我不能删除:
cqlsh> delete from dat.user_range where name='1000 - 1999' allow filtering;
Bad Request: line 1:52 missing EOF at 'allow'
cqlsh> delete from dat.user_range where name='1000 - 1999';
Bad Request: Missing mandatory PRIMARY KEY part id
即使我创建了一个索引:
cqlsh> create index on dat.user_range (start);
cqlsh> delete from dat.user_range where start=1000;
Bad Request: Non PRIMARY KEY start found in where clause
是否可以在不知道主键的情况下删除?
否,不支持使用辅助索引删除:CASSANDRA-5527
当您有了辅助索引时,您可以从该索引中选择所有行。当您拥有行时,您就知道主键,然后可以删除这些行。
我来这里是为了寻找从cassandra列族中删除行的解决方案。最后我做了一个INSERT并设置了一个TTL(生存时间),这样我就不必担心删除它了
把它放在那里,可能会对某人有所帮助。