Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partition key only in Cassandra

Tags:

cassandra

In Cassandra, I understand that by default, given PRIMARY KEY(id1, id2), id1 will be partition key and id2 will be clustering key.

I want to know if can I define two partition keys without any clustering key as follows:

PRIMARY KEY ((id1, id2));
like image 381
stackyyflow Avatar asked Jan 20 '26 11:01

stackyyflow


1 Answers

  1. Your understanding is correct.
  2. Your PRIMARY KEY ((id1, id2)) is correct and you are specifying one partition key consisting of two columns.

In the second case, you can query the data only by specifying both columns values. EG:

SELECT * FROM mytable WHERE id1=1 AND id2=3;

and queries like:

SELECT * FROM mytable WHERE id1=1;

will fail because id2 is part of your primary key.

like image 54
xmas79 Avatar answered Jan 23 '26 03:01

xmas79