Cassandra 3.0:查询模式与Allow Filtering

官方介绍:

https://www.datastax.com/dev/blog/allow-filtering-explained-2

表结构

我们以这张表为例:

create table test(c1 int,c2 int, c3 int,c4 int, primary key(c1,c2,c3));

这里写图片描述

  • c1 是分区键(partition key)
  • c2、c3 是排序键(clustering key)
  • c4 是普通列

正常查询

Cassandra 支持的查询语句很严格,首先 partition key 必须精确查询。其次:

# clustering key 全部精确查询
select * from test where c1=1 and c2=1 and c3=1;

# clustering key 精确查询后跟一个范围查询
select * from test where c1=1 and c2=1 and c3>1;

需要加 Allow Filtering 的情况

  • 缺少 partition key 的等值过滤条件
select * from test where c2=2;

InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"
  • 对普通列值过滤
select * from test where c1=1 and c2=1 and c3=1 and c4>10;

InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"
  • 范围查询后跟精确查询
select * from test where c1=1 and c2>20 and c3=10;

InvalidRequest: Error from server: code=2200 [Invalid query] message="Clustering column "c3" cannot be restricted (preceding column "c2" is restricted by a non-EQ relation)"

个人公众号:数据库漫游指南

Cassandra 3.0:查询模式与Allow Filtering_第1张图片

你可能感兴趣的:(Cassandra)