Ligo George
Ligo George

Reputation: 889

Cassandra Range Query : Secondary Index vs Unindexed Colum

I have seen that the best way to do range query on cassandra is by using CLUSTERING KEY. But I need to do some range query other than CLUSTERING KEY columns.

I read that we can do it on any column using ALLOW FILTERING. But is there any performance advantage if I create secondary index on that column ?

Upvotes: 0

Views: 908

Answers (1)

Alec  Collier
Alec Collier

Reputation: 1523

Have a look at this link: https://www.datastax.com/dev/blog/allow-filtering-explained-2

The ALLOW FILTERING option allows you tell Cassandra that it is ok to perform in-memory filtering of the data once it loads rows from disk. So we can use this to search by a clustering column without specifying the previous clustering columns. But we can't use it on non-clustering columns.

See the below example schema from the blog. Use of ALLOW FILTERING doesn't allow us to filter by author column until we make it an index, which then doesn't need the ALLOW FILTERING option.

cqlsh:test> SELECT * FROM blogs WHERE author = 'john' ALLOW FILTERING;
Bad Request: No indexed columns present in by-columns clause with Equal operator
cqlsh:test>

cqlsh:test> CREATE INDEX authors ON blogs (author);

cqlsh:test> SELECT * FROM blogs WHERE author = 'john';
(0 rows)
cqlsh:test> SELECT * FROM blogs WHERE author = 'john' ALLOW FILTERING;
(0 rows)

Upvotes: 1

Related Questions