Apache Cassandra中的二级索引 [英] Secondary index in Apache Cassandra

查看:209
本文介绍了Apache Cassandra中的二级索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下链接了解Cassandra中的二级索引:

I tried to understand the secondary Index in Cassandra using the following link:

  • https://www.youtube.com/watch?v=BPvZIj5fvl4

假设我们有5个节点N1,N2,N3,N4和N5群集,其复制因子为3,这意味着分区数据将被复制到群集中的3个节点(例如N1,N2和N3)。

Let's say we have 5 node N1, N2, N3, N4 and N5 cluster with Replication Factor of 3 which means a partition data will be replicated to 3 nodes in the cluster (say N1, N2 and N3).

现在执行此查询时:

SELECT *
FROM user
WHERE partitionKey = "somedata" AND ClusteringKey = "test";

读一致性为'2'

它将从节点N1,N2或N3中的任何两个查询

It will query from any two of the nodes N1, N2 or N3

如果我在任何列上应用二级索引,则以下查询将有多少个节点

If I apply a secondary index on any of the column, How many nodes will the following query be executed?

SELECT *
FROM user
WHERE partitionKey = "somedata" AND secondaryKey = "test";

我在此有两个查询:


  1. 根据视频,上面对二级索引的查询将从集群中的所有5个节点中读取,以便在secondaryIndexColumn上进行搜索?这是对的吗?

  2. 使用二级索引是否会对性能产生其他影响? -如果它解释了原因


推荐答案

Cassandra将联系节点,直到达到要返回的,满足您查询条件的LIMIT行,或者直到它与所有节点联系为止。为此,它首先与包含第一个令牌的节点联系,然后联系第一轮的一个节点,第二轮的两个节点,第三轮的四个节点,依此类推。

Cassandra will contact nodes until it reaches the LIMIT of rows to return, that satisfy your query, OR until it contacts all nodes. It does this by first contacting one node on the first round, two nodes on the 2nd round, four nodes on the third-round, and so on, starting with the node that contains the first token.

您可以在本文(E节)中查看完整的算法: https://www.datastax.com/dev/blog/cassandra-native-secondary-index-deep-dive

You can check the complete algorithm in this article (section E): https://www.datastax.com/dev/blog/cassandra-native-secondary-index-deep-dive

使用二级索引时要注意的一件事是,索引列的基数是否高,因为这将创建大量索引,从而占用大量磁盘空间。避免在这些列上使用二级索引。

One thing to look out for when using secondary indexes is if the indexed column has a high cardinality because this will create massive indexes, and hence use a lot of disk space. Avoid using secondary indexes on these columns.

这篇关于Apache Cassandra中的二级索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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