Is it possible to find records in Cassandra who's primary key matches an arbitrary subset of all of the primary key fields?
Using the table described below, it is possible to find the records whos's primary key has a particular type
and name
without specifying an id
or size
?
CREATE TABLE playlists (
id uuid,
type text,
name text,
size int,
artist text,
PRIMARY KEY (id, type, name, size)
);
Thanks!
At least in Cassandra 1.2 it is possible but it is disabled by default,
If you try to make this:
SELECT * from playlist where type = 'sometype' and name = 'somename';
You will receive this error:
Bad Request: 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
Then you can enable it running this:
SELECT * from playlist where type = 'sometype' and name = 'somename' ALLOW FILTERING;
In your example Cassandra will allow you to do queries using a complete subset of the primary key from left to right, for example:
SELECT * from playlist where id = 'someid'; (ALLOWED)
SELECT * from playlist where id = 'someid' and type = 'sometype'; (ALLOWED)
SELECT * from playlist where id = 'someid' and type = 'sometype' and name = 'somename'; (ALLOWED)
SELECT * from playlist where id = 'someid' and type = 'sometype' and name = 'somename' and size=somesize; (ALLOWED)
Hope it helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With