即使列是聚簇键,Cassandra也要求允许过滤 [英] Cassandra asks for ALLOW FILTERING even though column is clustering key

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

问题描述

对于Cassandra来说是新手,因此如果问题很简单,我们深表歉意。

Very new to Cassandra so apologies if the question is simple.

我创建了一个表格:

create table ApiLog (
LogId uuid,     
DateCreated timestamp,
ClientIpAddress varchar,
primary key (LogId, DateCreated));

此工作正常:

select * from apilog

如果我尝试在其中添加where子句日期创建方式如下:

If I try to add a where clause with the DateCreated like this:

select * from apilog where datecreated <= '2016-07-14'

我明白了:

无法执行此查询可能涉及数据过滤,因此可能具有不可预测的性能。如果您想在性能无法预测的情况下执行此查询,请使用ALLOW FILTERING

SO上的其他问题以及datas教程中的税收据我了解,由于创建日期的列是一个聚簇键,因此可以用来过滤数据。

From other questions here on SO and from the tutorials on datastax it is my understanding that since the datecreated column is a clustering key it can be used to filter data.

我也尝试创建索引,但是我得到了同样的信息。而且我尝试从主键中删除DateCreated,并将其仅作为索引,但仍然得到相同的答案:

I also tried to create an index but I get the same message back. And I tried to remove the DateCreated from the primary key and have it only as an index and I still get the same back:

create index ApiLog_DateCreated on dotnetdemo.apilog (datecreated);


推荐答案

分区键LogId确定每个分区将在哪个节点上被存储。因此,如果您未指定分区键,那么Cassandra必须过滤所有节点上此表的所有分区,以查找匹配的数据。这就是为什么不得不说允许过滤,因为该操作效率很低并且不鼓励使用。

The partition key LogId determines on which node each partition will be stored. So if you don't specify the partition key, then Cassandra has to filter all the partitions of this table on all the nodes to find matching data. That's why you have to say ALLOW FILTERING, since that operation is very inefficient and is discouraged.

如果您指定特定的LogId,则Cassandra可以在单个磁盘上找到分区

If you specify a specific LogId, then Cassandra can find the partition on a single node and efficiently do a range query by the clustering key.

因此,您需要计划架构,以便可以在单个分区内进行范围查询,而不必像您要尝试的那样进行全表扫描。

So you need to plan your schema such that you can do your range queries within a single partition and not have to do a full table scan like you're trying to do.

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

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