在 Cassandra 中允许过滤功能(哪个选项是正确的?)

Allow filtering function in Cassandra (which choice is correct?)

我目前正在尝试在 Cassandra 的基础上对一些时间序列数据进行建模。 例如,我有一个 table bigint_table,它是通过以下查询创建的

**

CREATE TABLE bigint_table (name_id int,tuuid timeuuid, timestamp timestamp, value text, PRIMARY KEY ((name_id),tuuid, timestamp)) WITH CLUSTERING ORDER BY (tuuid asc, timestamp asc)

** 添加了 tuuid 列,因为没有它我遇到了问题,并且在将它们插入数据库时​​丢失了一些数据。 name_id 代表频道的 ID 数据来了 from.tuuid 列被添加是因为没有它我遇到了问题并且我在将它们插入数据库时​​丢失了一些数据。在一个 table 中有很多具有相同 ID 的数据,但它们在 timestamptuuid 中是唯一的(values 有时也可以相同)。 我一直执行 2 个不同的查询来获取值和时间戳

  1. select value from bigint_table where name_id=6 and timestamp>' 2017-11-01 8:26:47.970+0000' and timestamp<'2017-11-30 8:26:52.048+0000' order by tuuid asc, timestamp asc allow filtering

2.

select timestamp from bigint_table where name_id=6 and timestamp>' 2017-11-01 8:26:47.970+0000' and timestamp<'2017-11-30 8:26:52.048+0000' order by tuuid asc, timestamp asc allow filtering

In this post 作者说需要抵制只向其添加 ALLOW FILTERING 的冲动,并且应该考虑数据、模型以及尝试做的事情。

关于是否使用 ALLOW FILTERING 函数,我想了很多,我发现在我的情况下我别无选择,我需要使用它。但是我上面提到的 post 中的那些话让我怀疑。我想知道您的建议以及您对我的问题有何看法。是否有另一种方法可以对我的数据 table 进行建模,其查询不需要 ALLOW FILTERING?我会非常非常感谢你的建议。

您需要允许过滤的原因是您的集群列(tuuid、时间戳)顺序错误。在这种情况下,数据首先由 tuuid 存储,然后由 timestamp.But 存储,您实际上是按时间戳选择数据,然后按 tuuid 排序,因此 Cassandra 无法使用您指定的索引。定义主键时的顺序很重要。