Range Queries in Cassandra (CQL 3.0)

寵の児 提交于 2019-12-03 12:37:01

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

for example definition like this one

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;

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.

emgsilva

Apart from the queries you mentioned, you can also have queries on "Composite Key" column families (well you need to design your DB using composite keys, if that fits your constrains). For an example/discussion on this take a look at Query using composite keys, other than Row Key in Cassandra. When using Composite Keys you can perform other types of queries, namely "range" queries that do not use the "partition key" (first element of the composite key) - normally you need to set the "allow filtering" parameter to allow these queries, and also can perform "order by" operations on those elements, which can be very interesting in many situations. I do think that composite key column families allow to overcome several (necessary) "limitations" (to grant performance) of the cassandra data model when compared with the "extremely flexible" (but slow) model of RDBMS...

y durga prasad

1) Create table:

create table test3(name text,id int,address text,num int,primary    key(name,id,address))with compact storage;

2) Inserting data into table:

insert into test3(name,id,address,num) values('prasad',1,'bangalore',1)  ;

insert into test3(name,id,address,num) values('prasad',2,'bangalore',2)  ;

insert into test3(name,id,address,num) values('prasad',3,'bangalore',3)  ;

insert into test3(name,id,address,num) values('prasad',4,'bangalore',4)  ;

3)

select * from test3  where name='prasad' and id <3;

4)

name   | id | address   | num


--------+----+-----------+-----

prasad |  1 | bangalore |   1

prasad |  2 | bangalore |   2
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!