我是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_userid
和usercontacts_by_modifydate
如果我设置modifydate(timestamp)static:
,我需要以下查询update usercontacts set modifydate="newdate" where contactid="contactid"
select * from usercontacts_by_modifydate where modifydate="modifydate"
delete from usercontacts where contactid="contactid"
答案 0 :(得分:6)
目前无法创建包含静态列的物化视图,无论是作为主键的一部分还是作为常规列。
包含静态行将需要在更改静态列时读取整个基表(usercontacts
),以便可以重新计算视图行。这显着降低了性能。
将静态行作为视图的分区键意味着视图中只有一个条目用于分区的所有行。但是,在这种情况下,二级索引可以正常工作,您可以使用它。
目前这对Scylla和Cassandra都有效。