Cassandra how to add clustering key in table?

泄露秘密 提交于 2019-12-23 23:22:48

问题


There is a table in cassandra

create table test_moments(id Text, title Text, sort int, PRIMARY KEY(id));

How add clustering key in column "sort". Not re-creating the table


回答1:


The main problem is the on-disk data structure. Clustering key directly dictates how data is sorted and serialized to disk (and then searched), so what you're asking is not possible.

The only way is to "migrate" the data to another table. Depending on your data, if you have a lot of records you could encounter some timeout error during the queries, so be prepared to tweak your migration with some useful techniques such as the COPY command or the TOKEN function.

Have a look at this SO question also.




回答2:


All you need to do is add it as the second part of the PRIMARY KEY to make it a composite key

create table test_moments(id Text, title Text, sort int, PRIMARY KEY(id, sort));


来源:https://stackoverflow.com/questions/42650970/cassandra-how-to-add-clustering-key-in-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!