In CQL, you can apply the WHERE to all columns as soon as you create indexes for them (i.e. secondary index). Otherwise, you will receive the following error:
Bad Request: No indexed columns present in by-columns clause with Equal operator
Unfortunately, even with secondary indexes, the WHERE clause must have at least one CQ secondary index EQ due to a performance issue .
Q: Why is it always necessary to have at least one EQ comparison on secondary indices?
A: Inequalities in secondary indexes are always executed in memory, so without at least one equalizer on another secondary index, you will load every row in the database, which with a massive database is not a good idea. Therefore, requiring at least one equalizer per (secondary) index, you hope to limit the set of lines that need to be read into memory to a manageable size. (Although, obviously, you can still get into trouble with this as well.)
Thus, if you have something other than EQ comparison, it loads all the lines "that match your query" and checks to see if they match one at a time. This is unacceptable by default, as it "may be slow." (Essentially, indexes only index โfor equalityโ not for anything else, such as <and>, which indexes in the relational database will be).
It should be noted that if you have several conditions without an equalizer for secondary indexes, you also need to include the ALLOW FILTERING in your query, otherwise you will get
Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING
One easy workaround is to add a dummy column to your table, where all rows have the same value in that column. Thus, in this case, you can execute the specified range only for the desired column. Understand that such queries in a NoSQL database can be slow / intimidating the system.
Example
cqlsh:demo> desc table table1; CREATE TABLE table1 ( keya int, keyb int, dummyvalue int, valuea int, PRIMARY KEY (keya, keyb) ) .... cqlsh:demo> select * from Table1; keya | keyb | dummyvalue | valuea ------+------+------------+-------- 1 | 2 | 0 | 3 4 | 5 | 0 | 6 7 | 8 | 0 | 9
Create secondary indexes for ValueA and DummyValue:
cqlsh:demo> create index table1_valuea on table1 (valuea); cqlsh:demo> create index table1_valueb on table1 (dummyvalue);
Perform a job in the ValueA range with DummyValue=0 :
cqlsh:demo> select * from table1 where dummyvalue = 0 and valuea > 5 allow filtering; keya | keyb | dummyvalue | valuea ------+------+------------+-------- 4 | 5 | 0 | 6 7 | 8 | 0 | 9