Range queries in secondary index columns are not allowed in Kassandra up to 2.2.x. However, since post Looks back at the CQL WHERE clause , they are allowed for non-indexed columns if filtering is used:
Direct queries on secondary indexes support only =, CONTAINS or CONTAINS KEY restrictions.
[..]
Secondary index queries allow you to restrict the returned results using the constraints =,>,> =, <= and <, CONTAINS and CONTAINS KEY on non-indexed columns using filtering.
So, given the table structure and index
CREATE TABLE test_secondary_index ( a text PRIMARY KEY, b timestamp, c timestamp ); CREATE INDEX idx_inequality_test ON test_secondary_index (b);
The following query fails because the inequality test runs on an indexed column:
SELECT * FROM test_secondary_index WHERE b >= '2016-04-29 18:00:00' ALLOW FILTERING ; InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: 'b >= <value>'"
But the following works because the inequality test runs on an unindexed column:
SELECT * FROM test_secondary_index WHERE b = '2016-04-29 18:00:00' AND c >= '2016-04-29 18:00:00' ALLOW FILTERING ; a | b | c
This still works if you add another index to column c
, but also still requires the term ALLOW FILTERING
, which for me means that the index in column c is not used in this scenario.
Raalf source share