Range Queries in Cassandra (CQL 3.0)

后端 未结 1 1044
[愿得一人]
[愿得一人] 2021-02-14 22:19

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 probabl

相关标签:
1条回答
  • 2021-02-14 22:29

    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...

    0 讨论(0)
  • 2021-02-14 22:47

    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.

    0 讨论(0)
提交回复
热议问题