【问题标题】:How to use static column in scylladb and cassandra?如何在 scylladb 和 cassandra 中使用静态列?
【发布时间】:2018-04-09 04:18:51
【问题描述】:

我是 scylladb 和 cassandra 的新手,我在从表中查询数据时遇到了一些问题,以下是我创建的架构:

CREATE TABLE usercontacts (
  userID bigint,                        -- userID 
  contactID bigint,                     -- Contact ID lynkApp userID  
  contactDeviceToken text,              -- Device Token    
  modifyDate timestamp static ,     
  PRIMARY KEY  (contactID,userID)
);



CREATE MATERIALIZED VIEW usercontacts_by_contactid 
AS SELECT userID, contactID, contactDeviceToken,
FROM usercontacts 
contactID IS NOT NULL AND userID IS NOT NULL AND modifyDate IS NOT NULL 
-- Need to not null as these are the primary keys in main
-- table same structure as the main table
PRIMARY KEY(userID,contactID);



CREATE MATERIALIZED VIEW usercontacts_by_modifyDate 
AS SELECT userID,contactID,contactDeviceToken,modifyDate
FROM usercontacts WHERE
contactID IS NOT NULL AND userID IS NOT NULL AND modifyDate IS NOT NULL
-- Need to not null as these are the primary keys in main
-- table same structure as the main table
PRIMARY KEY (modifyDate,contactID);

我想为usercontacts_by_useridusercontacts_by_modifydate 的联系人表创建物化视图

当我将 modifydate (timestamp) 设置为静态时,我需要以下查询:

update usercontacts set modifydate="newdate" where contactid="contactid"
select * from usercontacts_by_modifydate where modifydate="modifydate"
delete from usercontacts where contactid="contactid"

【问题讨论】:

    标签: cassandra scylla


    【解决方案1】:

    目前无法创建包含静态列(作为主键的一部分或仅作为常规列的一部分)的物化视图。

    包含静态行需要在更改静态列时读取整个基表 (usercontacts),以便重新计算视图行。这会对性能造成重大影响。

    将静态行作为视图的分区键意味着对于分区的所有行,视图中只有一个条目。但是,二级索引在这种情况下确实有效,您可以使用它来代替。

    目前这对 Scylla 和 Cassandra 都有效。

    【讨论】:

      猜你喜欢
      • 2017-11-23
      • 2018-01-05
      • 2021-03-10
      • 1970-01-01
      • 1970-01-01
      • 2019-12-21
      • 2018-03-29
      • 2013-09-18
      • 2016-01-01
      相关资源
      最近更新 更多