假设您连续有电影和类别列表,即
create table movie(
uuid timeuuid,
name text,
category list<text>
primary key (uuid)
);
insert into movie (uuid,name,category) values(now(), 'my movie', ['romance','comedy']);
insert into movie (uuid,name,category) values(now(), 'other movie', ['action','comedy']);
是否可以有效地执行以下操作:
select * from movie where category='comedy'
select * from movie where category='comedy' and category='action'
此用例是针对我们的MySQL数据库的最常见查询。
从cassandra 2.1开始,是的:
create table cinema.movie(
id timeuuid,
name text,
category list<text>,
primary key (id)
);
CREATE index ON cinema.movie (category);
INSERT INTO cinema.movie (id, name, category) VALUES (now(), 'my movie', ['romance','comedy']);
SELECT * FROM cinema.movie WHERE category CONTAINS 'romance';
uuid | category | name
--------------------------------------+------------------------+----------
b9e0d7f0-995f-11e3-b11c-c5d4ddc8930a | ['romance', 'comed`y'] | my movie
(1 rows)
PS,您的查询中有错误,,
类别的声明后,您的create table语句中缺少a ,并且您无法now()
在UUID上使用该函数,而是在寻找TIMEUUID类型。
切记,当使用这些集合时,性能不会很出色(对于定量而言,这是多么好),为这种事情创建一个单独的表可能会更好。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句