1. Compound Primary Key
Compound Primary Key consists of two parts.
- Partition key for Cassandra to determine the node location for the partition.
- The clustering columns are used to locate a unique record in the data node.
The clustering columns instruct Cassandra to guarantee the clustering or ordering of the rows within the partition by the values of clustering columns. On a physical node, when the rows for a partition key are stored in the order that is based on the clustering columns, the retrieval of rows is very efficient.
The values of the clustering columns are used as a prefix to the columns, which are not specified in the
PRIMARY KEY
clause. As Cassandra stores the internal columns in the sorting order of the column name, the rows are sorted inherently.PRIMARY KEY (exchange, price_time)
We can use order by, min, max, predicates in where on the clustering columns.
2. Composite Partition Key
The composite partition key spreads the data over multiple nodes. It is defined by an extra set of parentheses in the
PRIMARY KEY
clause. Internally, Cassandra concatenates the columns in the composite partition key together as an internal row key. e.g. exchange:symbolPRIMARY KEY ((exchange, symbol), price_time)
No comments:
Post a Comment