Cassandra允许过滤 [英] Cassandra Allow filtering

查看:126
本文介绍了Cassandra允许过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下表

CREATE TABLE test (
 day int,
 id varchar,  
 start int,
 action varchar,  
 PRIMARY KEY((day),start,id)
);

我要运行此查询

Select * from test where day=1 and start > 1475485412 and start < 1485785654 
and action='accept' ALLOW FILTERING

这是允许过滤有效吗?

我希望cassandra会按此顺序进行过滤

I am expecting that cassandra will filter in this order

1. By Partitioning column(day)
2. By the range column(start) on the 1's result
3. By action column on 2's result. 

因此在此查询中,允许过滤将不是一个坏选择。

So the allow filtering will not be a bad choice on this query.

如果where子句上有多个过滤参数,而最后一个未索引的列是过滤参数,那么过滤器将如何工作?
请解释。

In case of the multiple filtering parameters on the where clause and the non indexed column is the last one, how will the filter work? Please explain.

推荐答案


此允许过滤有效吗?

Is this ALLOW FILTERING efficient?

写 this是指查询和模型的上下文,但是允许过滤查询的效率主要取决于数据必须过滤。除非您显示一些真实数据,否则这是一个很难回答的问题。

When you write "this" you mean in the context of your query and your model, however the efficiency of an ALLOW FILTERING query depends mostly on the data it has to filter. Unless you show some real data this is a hard to answer question.


我希望cassandra会按此顺序进行过滤...

I am expecting that cassandra will filter in this order...

是的,这将发生。但是,查询中包含ALLOW FILTERING子句通常意味着表设计不佳,也就是说,您没有遵循有关Cassandra建模的一些准则(特别是一个查询<->一张表)。

Yeah, this is what will happen. However, the inclusion of an ALLOW FILTERING clause in the query usually means a poor table design, that is you're not following some guidelines on Cassandra modeling (specifically the "one query <--> one table").

作为一种解决方案,我可以提示您在<$ c之前将 action 字段包含在聚类键中c $ c> start 字段,修改表定义:

As a solution, I could hint you to include the action field in the clustering key just before the start field, modifying your table definition:

CREATE TABLE test (
 day int,
 id varchar,  
 start int,
 action varchar,  
 PRIMARY KEY((day),action,start,id)
);

然后您将重写查询,而没有任何ALLOW FILTERING子句:

You then would rewrite your query without any ALLOW FILTERING clause:

SELECT * FROM test WHERE day=1 AND action='accept' AND start > 1475485412 AND start < 1485785654

只有 minor 问题,如果一个记录切换 action 的值,您无法在单个 action 字段上执行更新(因为它现在是集群键的一部分),因此您需要使用旧的 action 值执行删除,并使用正确的新值进行插入。但是,如果您拥有Cassandra 3.0+,则可以在新的Materialized View实现的帮助下完成所有这些操作。拥有参阅文档有关更多信息。

having only the minor issue that if one record "switches" action values you cannot perform an update on the single action field (because it's now part of the clustering key), so you need to perform a delete with the old action value and an insert it with the correct new value. But if you have Cassandra 3.0+ all this can be done with the help of the new Materialized View implementation. Have a look at the documentation for further information.

这篇关于Cassandra允许过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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