How Cassandra stores multicolumn primary key (CQL) -


i have little misunderstanding composite row keys cql in cassandra. let's have following

cqlsh:testcql> create table note (            ... key int,            ... user text,            ... name text            ... , primary key (key, user)            ... ); cqlsh:testcql> insert note (key, user, name) values (1, 'user1', 'name1'); cqlsh:testcql> insert note (key, user, name) values (1, 'user2', 'name1'); cqlsh:testcql> cqlsh:testcql> select * note;   key | user  | name -----+-------+-------    1 | user1 | name1    1 | user2 | name1 

how data stored? there 2 rows or one.

if 2 how possible have more 1 row same key? if 1 having records key=1 , user "user1" "user1000" mean have 1 row key=1 , 1000 columns containing names each user?

can explain what's going on on background? thanks.

so, after diging bit more , reading article suggested lyuben todorov (thank you) found answer question.

cassandra stores data in data structures called rows totally different relational databases. rows have unique key.

now, what's happening in example... in table note have composite key defined primary key (key, user). first element of key acts row key , it's called partition key. internally rest of key used build composite columns.

in example

 key | user  | name -----+-------+-------    1 | user1 | name1    1 | user2 | name1 

this represented in cassandra in 1 row as

------------------------------------- |   | user1:name    | user2:name    | | 1 |-------------------------------- |   | name1         | name1         | ------------------------------------- 

having know it's clear it's not idea add column huge amount of unique values (and growing) composite key because stored in 1 row. worse if have multiple columns in composite primary key.

update: later found this blog post aaron morton explains same in more details.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -