cassandra materialized view And index

来源:互联网 发布:js圆形进度条插件 编辑:程序博客网 时间:2024/05/19 12:36
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