Open In App

Single-Row and Multi-Row Partitions in Cassandra

Last Updated : 15 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

In Cassandra, CQL(Cassandra Query Language) has two partitions as follows –

  • Single-Row Partitions
  • Multi-Row Partitions

Single-Row Partitions :
In Cassandra, the primary key represents a unique data partition and the clustering columns part are also helpful for data arrangement and are used to handle the data arrangement part. In Single-Row partitions, there is only a partitioning key on single column.

Example –
Let us take the Employee table having fields like Emp_id, Emp_name, Emp_email, where Emp_id is the primary key. 

CREATE table Employee(
Emp_id UUID, 
Emp_name TEXT, 
Emp_email TEXT,
primary key(Emp_id)
);

You can check the partitioning logical reference model for the above example as follows –

K - Primary key
C - Clustering column
S - Static column
Employee
Fields_name Data Type Key
Emp_id  UUID K
Emp_name TEXT  
Emp_email TEXT  

In Cassandra, the Primary key is the combination of the Partitioning key and Clustering column if any. 

Primary Key = Partition Key + [Clustering Columns]

Multi-Row Partitions :
In Multi-Row partitions, partitioning key is applied on more than one single column and clustering column for arrangement or partitioning data modelling.

Example –
Let us take the Event table having fields like Event_venue, Event_year, Event_artifact, Events_title, Events_country, where Event_venue, Event_year are the primary keys and Event_artifact is the clustering column key. 

CREATE table Events(
Event_venue TEXT, 
Event_year INT,
Event_artifact TEXT,
Events_title TEXT,
Events_country TEXT STATIC,
primary key((Event_venue, Event_year), Event_artifact)
);

You can check partitioning logical reference model for above example as follows –

K - Primary key
C - Clustering column
S - Static column
Events
Fields_name Data Type Key
Event_venue TEXT K
Event_year INT K
Event_artifact TEXT  
Events_title TEXT  
Events_country  TEXT S

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads