Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cassandra primary key. performance implications if integer vs varchar

Tags:

cassandra

cql

In Cassandra , Will there be performance penalty if primary key is varchar instead of int or bigint ? I have id as primary key. I wont do any math operation on that. I use id just to insert,retrive compare. I want to change that to string for one of my requirements. Will the perforamnce go down ?

like image 426
user1955409 Avatar asked Dec 19 '13 21:12

user1955409


People also ask

What is the difference between text and varchar in Cassandra?

Both text and varchar are UTF8 encoded strings and are synonyms for each other, that is they are exactly the same thing.

Does Cassandra primary key have to be unique?

Each table demands a unique primary key. In Cassandra, a primary key consists of one or more partition keys and may include clustering key components. The Apache Cassandra partition key always precedes the clustering key since its hashed value determines which node will store the data.

Can primary key be duplicated in Cassandra?

Yes the primary key has to be unique. Otherwise there would be no way to know which row to return when you query with a duplicate key.

What is primary key in Cassandra?

A primary key in Cassandra consists of one or more partition keys and zero or more clustering key components. The order of these components always puts the partition key first and then the clustering key.


1 Answers

There won't be any noticeable difference. Primary key lookups are done on the token i.e. the hash of the key. The comparisons are therefore independent of the data type or size of the key.

Longer keys will take slightly longer to hash. And there are some internal comparisons on the raw key but I very much doubt any of this is significant so go ahead and use whatever type is best for your data.

like image 176
Richard Avatar answered Oct 16 '22 11:10

Richard