【问题标题】:Cassandra - Best table modelling for following query?Cassandra - 以下查询的最佳表建模?
【发布时间】:2020-08-13 23:32:48
【问题描述】:

我希望执行以下查询:

SELECT value,occurredAt,venueName FROM Transaction_by_card WHERE card = 1234123412341234

并期望每张卡有几百个结果,就像您的常规信用卡账单一样。

我正在考虑将表格建模为:

(card int, occurredAt timestamp,venueName text, value int PRIMARY KEY (card,timestamp) WITH CLUSTERING ORDER BY occurredAt desc)

这是最适合我的用例的模型吗?

【问题讨论】:

    标签: cassandra cql


    【解决方案1】:

    只要确保每张卡的总记录数应小于 100 mb(Cassandra 中的一种拇指规则),但我希望比这更有价值。

    如果您假设您的结果大小可以更大,您可以进行基于时间的打包
    例如,基于月份的存储桶看起来像

    (card int, occurredAt timestamp, year int, month int, venueName text, value int PRIMARY KEY ( (card, year, month) timestamp) WITH CLUSTERING ORDER BY occurredAt desc)
    

    month:04 和 year 2020 将来自于发生的时间标记。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-01
      • 2015-10-31
      • 2016-08-20
      • 2016-06-12
      • 2018-11-12
      • 2016-02-23
      • 1970-01-01
      相关资源
      最近更新 更多