为什么不能将辅助索引(=?)和聚类列(排序依据)一起用于CQL查询? [英] Why Secondary Index ( = ?) and Clustering Columns (order by) CANNOT be used together for CQL Query?

查看:206
本文介绍了为什么不能将辅助索引(=?)和聚类列(排序依据)一起用于CQL查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:相关的jira

a related jira ticket

模式为的查询从*

其中< partition_keys> =?和< secondary_index_column> =?按< first_clustering_column>排序desc 不起作用,出现错误消息:

A query in pattern select * from <table> where <partition_keys> = ? and <secondary_index_column> = ? order by <first_clustering_column> desc does not work, with error msg:

InvalidRequest: Error from server: code=2200 [Invalid query] message="ORDER BY with 2ndary indexes is not supported."

来自结构,上面的查询包括分区键和索引表中的前两个群集列。另外,请注意,如果没有order by子句,则结果将按聚簇列排序为CLUSTERING ORDER。

From the structure of index table, above query include the partition key, and first two cluster columns in the index table. Also, note that without order by clause, the result is sorted by clustering column as CLUSTERING ORDER.

有什么方法可以使查询工作?如果不是,为什么?

Is there any way to make the query work? If not, why?

推荐答案

Cassandra中的数据自然根据聚类列的排序顺序存储。

Data in Cassandra is naturally stored based on the sort order of Clustering Columns.

Cassandra中的二级索引与关系数据库中的相应索引有很大不同。每个节点的本地地址,这意味着群集的其他节点不了解其内容。因此,按此索引排序是非常不可能的。同样在该节点内,辅助索引仅保留指向相应分区键的指针。

Secondary index in Cassandra is way different than a corresponding index in relation database. Its local per node, which means that its contents aren't known to other nodes of the cluster. So sorting by this index is highly impossible. Also within the node, the secondary indexes are holding just pointers to corresponding partition key.

如果您需要由Cassandra执行排序,请将它们作为聚类列。否则,您可以在检索结果后按代码对它们进行排序。

If you need sorting to be performed by Cassandra, have them as clustering columns. Otherwise you can sort them in code, after you retrieve the results.

二级索引也不是Cassandra的理想选择,绝对更好的模型是不要将它们放在首位,以免将来头疼。

Also secondary indexes aren't ideal for Cassandra and definitely a better model is to not have them in first place, to save some headache for future.

这篇关于为什么不能将辅助索引(=?)和聚类列(排序依据)一起用于CQL查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆