4. Allow filtering
CREATE TABLE blogs (blogId int,
time1 int,
time2 int,
author text,
content text,
PRIMARY KEY(blogId, time1, time2));
SELECT * FROM blogs WHERE time1 = 1418306451235;
SELECT * FROM blogs WHERE author = ‘Jonathan Ellis’; Ok if author column is indexed
SELECT * FROM blogs WHERE author=’Jonathan Ellis’ and time2 = 1418306451235;
filtering is needed even author
and time2 column are indexed
DONOT always use allow filtering for your problem !
为了保持对cassandra和spark-Cassandra connector的兼容,以及对老数据集灵活查询的支持
7. Global Secondary Indexes
• Cassandra 二级索引 (local indexes)
• 数据在哪,索引就在哪
• 写很快,但读可能要查询其它节点;且不具备扩展性
• Scylla global indexing
CREATE TABLE ks.users (
userid uuid,
name text,
email text,
country text,
PRIMARY KEY (userid)
);
CREATE INDEX ON ks.users (email); CREATE MATERIALIZED VIEW
ks.users_email_idx_index AS
SELECT email, userid
FROM ks.users
WHERE email IS NOT NULL
PRIMARY KEY (email, userid)
WITH CLUSTERING ORDER BY
(userid ASC);
选用二级索引还是MV取决于应用