1

I want to filter on a table that has a partition and a clustering key with another criteria on a regular column. I got the following warning.

InvalidQueryException: 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

I understand the problem if the partition and the clustering key are not used. In my case, is it a relevant error or can I ignore it?

Here is an example of the table and query.

CREATE TABLE mytable(
    name text,
    id uuid,
    deleted boolean
    PRIMARY KEY((name),id)
)

SELECT id FROM mytable WHERE name='myname' AND id='myid' AND deleted=false;
Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82

1 Answers1

3

In Cassandra you can't filter data with non-primary key column unless you create index in it.

Cassandra 3.0 or up it is allowed to filter data with non primary key but in unpredictable performance

Cassandra 3.0 or up, If you provide all the primary key (as your given query) then you can use the query with ALLOW FILTERING, ignoring the warning

Otherwise filter from the client side or remove the field deleted and create another table :

Instead of updating the field to deleted true move your data to another table let's say mytable_deleted

CREATE TABLE mytable_deleted (
    name text,
    id uuid
    PRIMARY KEY (name, id)
);

Now if you only have the non deleted data on mytable and deleted data on mytable_deleted table

or

Create index on it :

The column deleted is a low cardinality column. So remember

A query on an indexed column in a large cluster typically requires collating responses from multiple data partitions. The query response slows down as more machines are added to the cluster. You can avoid a performance hit when looking for a row in a large partition by narrowing the search.

Read More : When not to use an index

Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53
  • Thank you for your answer. I just have an additional question. What about the tombstone created by moving a record from one table to another one, is there a problem about that? – Nicolas Henneaux Jul 20 '17 at 10:49
  • 1
    Yes, Moving data will create tombstone. If small amount of tombstone will not create problem but If you frequently delete then huge tombstone will generate. In that case you should filter data from the client side. Read this : https://stackoverflow.com/a/27567303/2320144 – Ashraful Islam Jul 20 '17 at 10:54
  • Then, I will only use a deleted table without removing the element in the original table. Both will be removed after expiration of the elements. – Nicolas Henneaux Jul 20 '17 at 11:09