How are static columns stored internally in cassandra? Can someone please post an example discussing the design implementation of static column in cassandra?
Why don't we take a look at the structure of a table with static columns on disk and find out?
cqlsh:test> CREATE TABLE test (k int, v int, s int static, d int, PRIMARY KEY(k,v))
cqlsh:test> INSERT INTO test (k, v, s, d) VALUES ( 1, 1 ,20, 1 );
cqlsh:test> INSERT INTO test (k, v, s, d) VALUES ( 1, 3 ,21, 2 );
cqlsh:test> INSERT INTO test (k, v, s, d) VALUES ( 1, 2 ,21, 2 );
Exit out of cqlsh and run nodetool flush
to make our sstables. Run sstable2json
on the .db file that was created in the data directory.
[
{"key": "1", <--- K=1 Partition
"cells": [[":s","21",1425050917842350], <---- Our Static Column
["1:","",1425050906896717], < --- v=1 row
["1:d","1",1425050906896717], < --- v=1, d=1 value
["2:","",1425050917842350], < --- v=2 row
["2:d","2",1425050917842350], < --- v=2, d=2 value
["3:","",1425050912874025], <--- v=3 Row
["3:d","2",1425050912874025]]} <--- v=3, d=2 Value
]
You can see that in Cassandra this static column is held in a cell with the title "Blank:ColumnName" at the very beginning of our partition. Unlike all the other cells there is no information about c(our clustering column) in the cell name, so all values of c will still modify the same static column s
Reference:
https://stackoverflow.com/questions/28767452/cassandra-static-column-design