Cassandra 二级索引与物化 View

标签 cassandra

我正在为 Cassandra 3.0+ 建模我的表。目标是构建一个存储用户事件的表,这是我到目前为止所做的:
(userid来自另一个数据库Mysql)

CREATE TABLE activity (
    userid int,
    type int,
    remoteid text,
    time timestamp,
    imported timestamp,
    visibility int,
    title text,
    description text,
    img text,
    customfields MAP<text,text>,
PRIMARY KEY (userid, type, remoteid, time, imported))

这是我使用的主要查询:
SELECT * FROM activity WHERE userid = ? AND remoteid = ?;
SELECT * FROM activity WHERE userid = ? AND type = ? AND LIMIT 10;

现在我需要添加列 visibility在第二个查询中。因此,根据我的了解,我可以在二级索引或物化 View 之间进行选择。
这是事实:
  • 这里每个用户有一个分区,里面有数千行(事件)。
  • 我用 总是 我所有查询中的分区键(用户 ID)以访问数据。
  • 全局事件数量为 3000 万,并且在不断增长。
  • visibility列的基数较低(只有 3 个值)并且可以更新,但很少。

  • 那我应该选择什么?物化 View 或索引?我知道基数低的索引是不好的选择,但我的查询总是包括分区键和限制,所以也许还不错。

    最佳答案

    如果您总是要使用分区键,我建议您使用二级索引。

    当您不知道分区键时,物化 View 会更好

    引用文献:

    主要文章!

    Cassandra Secondary Index Preview #1

    这是与物化 View 和二级索引的比较

    Materialized View Performance in Cassandra 3.x

    这里是已知 PK 使用索引更有效的地方

    Cassandra Native Secondary Index Deep Dive

    关于Cassandra 二级索引与物化 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42158945/

    相关文章:

    python - CQLSH 连接错误 : Bad Request: unconfigured columnfamily local

    java - Cassandra SSTableLoader : failed to list files in <directory_path>

    cassandra cqlsh 给出错误的计数

    cassandra - 在 Cassandra 中如何表示金钱?

    cassandra - thrift_max_message_length_in_mb 无法识别 Cassandra

    mysql - 如何将应用程序移动到 Cassandra?

    c - 哪个 NoSQL 数据库适合 MoSTLy 写作

    Cassandra 压力测试在大量插入后失败

    cassandra - hector的indexedslicesquery和rangeslicesquery哪个性能更好?

    c# - 如何在 C# 中将时间 UUID 转换为日期时间戳