educative.io

Educative

Question on Partition Key

Hi, I was reading the “anatomy of cassandra’s read operation” section of the Cassandra database.

It seems the the “key” in read lookup is the partition key. But in Cassandra, the primary key is partition key + cluster key. So one partition key can have multiple rows?

If the read operation just want a single row, should it read base on the primary key, instead of partition key?

Thanks

If you need to read a row, you would need its primary key. Primary key has two parts: Partition key and Clustering key. These two parts have different purposes.

“Key” means “primary key”. Would you like to elaborate on how you got the idea that the “key” refers to partition key in the read path?

Thanks, I was just wondering the “key” that Cassandra used for indexing its SSTable. Since you mentioned that in the disk it stores the “data file” and the “index file”. Do we use “partition key” to in the index file?

In this case, when I would like to read a specific row. Let’s assume the partition index file helps me to locate the offset of that partition key. After that, do I need to iterate over all the records/rows to find the specific row that matches the primary key?

Same concern.

That’s a good question.

Restating your question so that we are on the same page: Partition Index tells us the offset (or the position) of the partition key in the SStable’s data file, but how does Cassandra filters out rows based on clustering columns? Does Cassandra start reading sequentially from the offset until it finds out the exact row?

To extend this question, if we are querying a set of columns, how does Cassandra finds out the exact position of a column for a given row? Is it a sequential search?

Answer: In the older Cassandra versions, it was sequential. Meaning, Cassandra goes to the offset given by the partition index and then starts reading sequentially until it finds the correct column or row.

In the latest releases of Cassandra, they have introduced the concept of “Promoted index” which is used for large partitions with many rows. “Promoted index” is also stored in the index file. To find a specific row in a partition with many rows the promoted index is used to find the data file portion that holds the information related to the range of rows this row belongs to.

In short, “Promoted index” divides the set of rows at 64KB blocks (by default); where each blockis summarized by index_info structure containing: start_name and end_name are the names of the first and last columns in that block. To find a row, Cassandra does a binary search on these blocks and then scans the partition of the appropriate range.

For more details see the following links:

https://issues.apache.org/jira/browse/CASSANDRA-11206