Cassandra DB:为什么小于查询失败?

Cassandra DB:为什么小于查询失败?,cassandra,Cassandra,我创建了一个键空间和一个表,其中uuid列作为主键,时间戳列使用索引。所有这些都成功了,如下图所示: cassandra@cqlsh:my_keyspace> insert into my_test ( id, insert_time, value ) values ( uuid(), '2015-03-12 09:10:30', '111' ); cassandra@cqlsh:my_keyspace> insert into my_test ( id, insert_time,

我创建了一个键空间和一个表,其中uuid列作为主键,时间戳列使用索引。所有这些都成功了,如下图所示:

cassandra@cqlsh:my_keyspace> insert into my_test ( id, insert_time, value ) values ( uuid(), '2015-03-12 09:10:30', '111' );
cassandra@cqlsh:my_keyspace> insert into my_test ( id, insert_time, value ) values ( uuid(), '2015-03-12 09:20:30', '222' );
cassandra@cqlsh:my_keyspace> select * from my_test;

 id                                   | insert_time              | value
--------------------------------------+--------------------------+-------
 9d7f88bc-5cb9-463f-b679-fd66e6469eb5 | 2015-03-12 09:20:30+0000 |   222
 69579f6f-bf88-493b-a1d6-2f89fac25650 | 2015-03-12 09:10:30+0000 |   111

(2 rows)
现在开始提问

cassandra@cqlsh:my_keyspace> select * from my_test where insert_time = '2015-03-12 09:20:30';

 id                                   | insert_time              | value
--------------------------------------+--------------------------+-------
 9d7f88bc-5cb9-463f-b679-fd66e6469eb5 | 2015-03-12 09:20:30+0000 |   222

(1 rows)
现在,使用小于:

cassandra@cqlsh:my_keyspace> select * from my_test where insert_time < '2015-03-12 09:20:30';
InvalidRequest: code=2200 [Invalid query] message="No secondary indexes on the restricted columns support the provided operators: 'insert_time < <value>'"

Cassandra范围查询非常有限。这取决于性能和数据存储机制。范围查询必须具有以下内容:

点击一个(或几个)分区键,并在所有连续的集群键上包括精确匹配,但查询中的最后一个键除外,您可以对其执行范围查询

假设您的PK为(a、b、c、d),则允许以下情况:

  • 其中a=a1,b
  • 其中a=a1,b=b1,c
以下不是:

  • 其中a=a1,c<1
[我不会在这里讨论允许过滤…避免它。]


二级索引必须完全匹配。不能对其进行范围查询。

这实际上是时间范围查询的副本,请参阅
CREATE TABLE my_test (
    id uuid PRIMARY KEY,
    insert_time timestamp,
    value text
) ;
CREATE INDEX my_test_insert_time_idx ON my_keyspace.my_test (insert_time);