简体   繁体   中英

Cassandra: creating a Partition Key

I have a table student (id,marks,score) in cassandra. i created the table with id as primary key. I need to sort table by score and i haven't created a partition key for score. How to create a partition key without recreating table?

Cassandra does not allow you to alter the primary key as a primary key defines how data will be physically stored on the disk. If you really want to change it, as you already mentioned the only way is to create a new table with different primary key and migrate all the data to the new table.

In your new table, you will probably still want ID as your partition key (assuming you know the ID at query time), and score as a clustering column. This will allow you to search for a specific ID and then sort it by the scores associated with that partition.

The Materialized Views feature of Cassandra 3.0 allows you to have a new view with a different column as the partition key. The view can be added without re-creating the table.

There is a good discussion of when and when not to use them here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM