Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQL and range on secondary indexed columns

Tags:

cassandra

cql

The below CQL query resulted in an error saying

No indexed columns present in by-columns clause with equals operator

Note that the column age was already secondary indexed.

select * from employee where age > 25

However I had another secondary indexed column type. So when I used that...

select * from employee where type='engineer' and age > 25

I seemed to get proper results.

How does this happen?

like image 912
varun Avatar asked Aug 13 '12 17:08

varun


People also ask

Does Cassandra support secondary indexes?

4. Secondary Indexes. Secondary Indexes in Cassandra solve the need for querying columns that are not part of the primary key. When we insert data, Cassandra uses an append-only file called commitlog for storing the changes, so writes are quick.

What is not allowed in CQL query?

CQL does not support wildcard queries. CQL does not support Union, Intersection queries. Table columns cannot be filtered without creating the index. Greater than (>) and less than (<) query is only supported on clustering column.

How many secondary indexes are allowed per table?

For maximum query flexibility, you can create up to 20 global secondary indexes (default quota) and up to 5 local secondary indexes per table.

How do I create a secondary index in Cassandra?

The CREATE INDEX statement is used to create a new (automatic) secondary index for a given (existing) column in a given table. A name for the index itself can be specified before the ON keyword, if desired. If data already exists for the column, it will be indexed asynchronously.


1 Answers

Cassandra's built-in secondary indexes are more of a hash-style index, as opposed to a B-tree.

As such, at least one equality comparison is required to perform lookups efficiently (any additional column predicates result in late-filtering of the equality matches).

Try the following wiki page for a decent starting point for questions about Cassandra's secondary indexes: http://wiki.apache.org/cassandra/SecondaryIndexes

like image 58
jericevans Avatar answered Nov 16 '22 01:11

jericevans