Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra Delete by Secondary Index or By Allowing Filtering

Tags:

cassandra

cql

I’m trying to delete by a secondary index or column key in a table. I'm not concerned with performance as this will be an unusual query. Not sure if it’s possible? E.g.:

CREATE TABLE user_range (
  id int,
  name text,
  end int,
  start int,
  PRIMARY KEY (id, name)
)

cqlsh> select * from dat.user_range where id=774516966;

id        | name      | end | start
-----------+-----------+-----+-------
774516966 |   0 - 499 | 499 |     0
774516966 | 500 - 999 | 999 |   500

I can:

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…

But I can’t delete:

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

Even if I create an index:

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

Is it possible to delete without first knowing the primary key?

like image 899
axle_h Avatar asked Aug 29 '13 16:08

axle_h


People also ask

What does allow filtering do in Cassandra?

Allowing filtering By default, CQL only allows select queries that don't involve a full scan of all partitions. If all partitions are scanned, then returning the results may experience a significant latency proportional to the amount of data in the table. The ALLOW FILTERING option explicitly executes a full scan.

How do I drop a secondary index in Cassandra?

Cassandra Drop IndexCommand 'Drop index' drops the specified index. If index name was not given during index creation, then index name is TableName_ColumnName_idx. If the index does not exist, it will return an error unless IF EXISTS is used that will return no-op.

How does Cassandra delete data?

Cassandra treats a delete as an insert or upsert. The data being added to the partition in the DELETE command is a deletion marker called a tombstone. The tombstones go through Cassandra's write path, and are written to SSTables on one or more nodes.

How do I delete all records in Cassandra?

To remove all rows from a CQL Table, you can use the TRUNCATE command: TRUNCATE keyspace_name.


1 Answers

No, deleting by using a secondary index is not supported: CASSANDRA-5527

like image 107
Alex Popescu Avatar answered Sep 17 '22 11:09

Alex Popescu