cassandra materialized view And index

CREATE TABLE mytest1.wordstest (
    word text PRIMARY KEY,
    c1 int,
    count int
)


-. index




1. 不指定partition, 普通查询
select * from mytest1.wordstest  where count = 40 ALLOW FILTERING


2. 个人理解: 二级索引很耗 性能:表太大,还是不要建立
Secondary indexes are tricky to use and can impact performance greatly. The index table is stored on each node in a cluster, so a query involving a secondary index can rapidly become a performance nightmare if multiple nodes are accessed




CREATE INDEX c1_index ON mytest1.wordstest (c1);
select * from mytest1.wordstest  where c1 = 1;






二. materialized view 物化视图


A materialized view is a table that is built from another table's data with a new primary key and new properties


https://docs.datastax.com/en/cql/3.3/cql/cql_using/useCreateMV.html

https://www.datastax.com/dev/blog/new-in-cassandra-3-0-materialized-views





CREATE MATERIALIZED VIEW wordstest_mv 
AS SELECT count, word, c1 
FROM mytest1.wordstest 
WHERE count IS NOT NULL AND word IS NOT NULL 
PRIMARY KEY (count, word);


Nee to know: The columns of the source table's primary key must be part of the materialized view's primary key.




select * from mytest1.wordstest_mv  where c1 = 1;


Cassandra can only write data directly to source tables, not to materialized views. Cassandra updates a materialized view asynchronously after inserting data into the source table, so the update of materialized view is delayed. Cassandra performs a read repair to a materialized view only after updating the source table.


源表和物化视图的数据更新不是同步的,数据插入源表后,不会同步更新物化视图。通过执行repair 操作更新物化视图的数据




https://docs.datastax.com/en/cql/3.3/cql/cql_using/useCreateMV.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值