Cassandra中的范围查询(CQL 3.0) [英] Range Queries in Cassandra (CQL 3.0)

查看:3706
本文介绍了Cassandra中的范围查询(CQL 3.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Cassandra的一个主要部分,我不完全理解是它的范围查询。我知道Cassandra强调分布式环境并专注于性能,但是可能因为这样,它目前只支持几种类型的范围查询,它可以有效地完成,我想知道的是:支持哪些类型的范围查询

One main part of Cassandra that I don't fully understand is its range queries. I know that Cassandra emphasizes distributed environment and focuses on performance, but probably because of that, it currently only support several types of ranges queries that it can finish efficiently, and what I would like to know is that: which types of range queries are supported by Cassandra.

据我所知,Cassandra支持以下范围查询:

As far as I know, Cassandra supports the following range queries:

1:范围查询on主键与关键字 TOKEN ,例如:

1: Range Queries on Primary key with keyword TOKEN, for example:

 CREATE TABLE only_int (int_key int PRIMARY KEY);
 ...
 select * from only_int where token(int_key) > 500;

2:范围在次要索引上具有一个相等条件的查询,关键字 ALLOW FILTERING ,例如:

2: Range Queries with one equality condition on a secondary index with keyword ALLOW FILTERING, for example:

CREATE TABLE example (
  int_key int PRIMARY KEY,
  int_non_key int,
  str_2nd_idx ascii
);
CREATE INDEX so_example_str_2nd_idx ON example (str_2nd_idx);
...
select * from example where str_2nd_idx = 'hello' and int_non_key < 5 allow filtering;

但我想知道如果我错过了什么,并寻找一个规范的答案,列出所有类型的范围查询支持当前CQL(或一些允许更多类型的范围查询的解决方案)。

But I am wondering if I miss something and looking for a canonical answer which lists all types of range queries supported by the current CQL (or some work-around that allows more types of range queries).

推荐答案

strong>群集键。
主键可以通过分区键,然后通过聚类键形成。

You can look for clustering keys. A primary key can be formed by a partitioning key and then by clustering keys.

例如这样的定义

CREATE TABLE example (
  int_key int,
  int_non_key int,
  str_2nd_idx ascii,
  PRIMARY KEY((int_key), str_2nd_idx)
);

将允许您在不使用令牌的情况下进行这些查询

will allow to you make queries like these without using token

select * from example where str_2nd_idx < 'hello' allow filtering;

在cassandra中创建TABLE之前,你应该先考虑查询和你想从数据模型在cassandra。

Before creating a TABLE in cassandra you should start from thinking about queries and what you want to ask from the data model in cassandra.

这篇关于Cassandra中的范围查询(CQL 3.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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