Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search secondary index in Cassandra without equality?

I need to be able to perform search on secondary indexes using only <, >, <=, or >=. I understand that Cassandra requires at least one equality index clause because it iterates over all the results from that equality index.

Are there any tricks to perform operations using only <, >, <=, or >= (at least conceptually)? Is it a bad idea?

Also, does anybody know if there are any plans to change this in Cassandra?

Thanks!

like image 489
David V Avatar asked Mar 18 '11 19:03

David V


1 Answers

If there were a good way to do this with 0.7 indexes, we/I would have mentioned it in http://www.datastax.com/dev/blog/whats-new-cassandra-07-secondary-indexes instead of saying "you need an equality expression." There is no Double Secret Cheat Code.

One alternative is to use ByteOrderedPartitioner (which lets you do >= queries on the row key). Another may be to create a materialized view on some subset of your data at write time. That's assuming you have enough rows that simply doing an unordered sequential scan is too slow.

Bitmap indexes in 0.8 ( https://issues.apache.org/jira/browse/CASSANDRA-1472) will support inequality operations on indexes.

like image 90
jbellis Avatar answered Oct 07 '22 14:10

jbellis