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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章