【问题标题】:Slicing over partition rows using tuple operation in CQL在 CQL 中使用元组操作对分区行进行切片
【发布时间】:2015-09-06 07:38:46
【问题描述】:

我正在尝试了解具有聚类键的元组运算符的行为。这是我想要做的:

create table sampletable (a int,b int,c int, d int, e int, primary key((a,b,c),d,e));
insert into sampletable(a,b,c,d,e) values(1,1,1,1,1);
insert into sampletable(a,b,c,d,e) values(1,1,1,1,1);
insert into sampletable(a,b,c,d,e) values(1,1,1,1,2);
insert into sampletable(a,b,c,d,e) values(1,1,2,1,1);
insert into sampletable(a,b,c,d,e) values(1,1,2,1,2);
insert into sampletable(a,b,c,d,e) values(1,1,2,2,3);
insert into sampletable(a,b,c,d,e) values(1,1,2,1,2); 
insert into sampletable(a,b,c,d,e) values(1,1,1,2,3);

cqlsh:mapro> select * from sampletable;

 a | b | c | d | e
---+---+---+---+---
 1 | 1 | 1 | 1 | 1
 1 | 1 | 1 | 1 | 2
 1 | 1 | 1 | 2 | 3
 1 | 1 | 2 | 1 | 1
 1 | 1 | 2 | 1 | 2
 1 | 1 | 2 | 2 | 3

(6 rows)

-- Query1
cqlsh:mapro> select * from sampletable where a=1 and b=1 and c in (1,2) and (d,e)<(2,3);  
 a | b | c | d | e                                                                 
---+---+---+---+---                                                                
 1 | 1 | 1 | 1 | 1                                                                 
 1 | 1 | 1 | 1 | 2                                                                 
 1 | 1 | 2 | 1 | 1                                                                 
 1 | 1 | 2 | 1 | 2                                                                                                                                              
(4 rows)            


-- Query2
cqlsh:mapro> select * from sampletable where a=1 and b=1 and c in (1,2) and (d,e)<(2,9);                                                  
 a | b | c | d | e                                                                 
---+---+---+---+---                                                                
 1 | 1 | 1 | 1 | 1                                                                 
 1 | 1 | 1 | 1 | 2                                                                 
 1 | 1 | 1 | 2 | 3                                                                 
 1 | 1 | 2 | 1 | 1                                                                 
 1 | 1 | 2 | 1 | 2                                                                 
 1 | 1 | 2 | 2 | 3                                                                                                                                              
(6 rows)

我无法理解为什么查询 2 返回的结果与查询 1 不同。我的理解是 Cassandra 将首先应用所有分区键过滤,然后尝试应用元组排序,即 (d,e)

【问题讨论】:

    标签: cassandra cql datastax


    【解决方案1】:

    在集群列的情况下,(a1, a2) &lt; (b1, b2) 在以下任何一种情况下都可以为真:

    1) a1 < b1 
    2) a1=b1 and a2 < b2
    

    这就是 Cassandra 在内部根据聚类列进行排序的方式

    基于此,Query 1 和 2 的结果符合预期。

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-07
      • 2019-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多