Cassandra二级索引是否优化

Cassandra二级索引是否优化

本文介绍了如果指定分区键,Cassandra二级索引是否优化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于在WHERE子句中指定分区键的辅助索引查询,辅助索引查找是否命中所有集群节点,或者只是指定分区键的节点?

如果后者正确,那么辅助索引也将适用于高基数字段(仅适用于满足分区键的查询)。

For secondary index queries that the partition key is specified in the WHERE clause, does the secondary index lookup hits all cluster nodes, or just the node of the specified partition key?
If the latter is correct, then secondary index will be a good fit also for high cardinality fields (only for queries that satisfies the partition key).

编辑:例如,对于以下供稿模式,查询特定Feed(指定的feed_id)以检索现有或删除的Feed项应该非常有效:

For example, for the following feed schema, query of a specific feed (feed_id specified) to retrieve existing or deleted feed items should be very efficient:

CREATE TABLE my_feed (
   feed_id int,
   item_id timeuuid,
   is_deleted boolean,
   data text,
   PRIMARY KEY (feed_id, item_id)
) WITH CLUSTERING ORDER BY (item_id DESC);

CREATE INDEX my_feed_is_deleted_idx ON my_feed (is_deleted);

==> SELECT * FROM my_feed WHERE feed_id=1 AND is_deleted=false; --efficient?


推荐答案

如果你先打一个分区键,不是群集操作。只有目标分区将被命中。如果你有一个分区中有很多行的宽行,二级索引将是一种有效的方法,一旦一个分区被击中就过滤它们。

If you hit a partition key first, then it won't be a cluster wide operation. Only the target partition will be hit. If you have wide rows with many rows in a partition, a secondary index will be an efficient way to filter them down once a partition is hit.

这篇关于如果指定分区键,Cassandra二级索引是否优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 16:00