Cassandra timeuuid 比较

Cassandra timeuuid comparison

我有一个table,

CREATE TABLE log (
    uuid uuid,
    time timeuuid,
    user text,
    ....
    PRIMARY KEY (uuid, time, user)
)  

CREATE CUSTOM INDEX time_idx on Log(time) USING 'org.apache.cassandra.index.sasi.SASIIndex';

那我想select根据时间

select * from Log where time > 84bfd880-b001-11e6-918c-24eda6ab1677;

什么都没有 return,如果我使用 equal(=),它将 return。我哪一步做错了?

您需要将 time_idx 索引设为 SPARSE 索引。

The SPARSE index is meant to improve performance of querying large, dense number ranges like timestamps for data inserted every millisecond. If the data is numeric, millions of columns values with a small number of partition keys characterize the data, and range queries will be performed against the index, then SPARSE is the best choice. For numeric data that does not meet this criteria, PREFIX is the best choice.

删除 time_idx 并使用以下查询创建

CREATE CUSTOM INDEX time_idx on Log(time) USING 'org.apache.cassandra.index.sasi.SASIIndex' WITH OPTIONS = { 'mode': 'SPARSE' };

现在您可以使用 The inequalities >=, > and <= 进行查询。

限制:SPARSE 索引仅用于数字数据,因此 LIKE 查询不适用。

还有一件事你的 table 创作是不对的。应该是

CREATE TABLE log (
    uuid uuid,
    time timeuuid,
    user text,
    PRIMARY KEY (uuid, time, user)
)