按主键和列进行cassandra查询时抛出错误

ha5z0ras  于 2021-06-10  发布在  Cassandra
关注(0)|答案(2)|浏览(413)

架构

CREATE TABLE books (
   isbn text PRIMARY KEY,
   author text
);

insert into books (isbn, author) values ('111', 'Sally');
insert into books (isbn, author) values ('112', 'Fred');
insert into books (isbn, author) values ('113', 'Joe');

有了以上数据,我可以通过主键进行查询
111 select * from books where isbn = '111'; 然而,当我把 author 在where条件下抛出错误 select * from books where isbn = '111' and author = 'Fred'; ```
Query 1 ERROR: Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING

我不明白,如果数据已经被主键过滤了(只有一条记录),为什么会抛出错误?
第二,如果我使用 `allow filtering` 是否有任何性能影响?
编辑:https://dzone.com/articles/apache-cassandra-and-allow-filtering 给了我一些线索。
qv7cva1a

qv7cva1a1#

在cassandra中,不能查询非分区或集群键列。
如果您想让上述用例正常工作,那么必须在主键声明中包含author。
创建table books(isbn文本,作者文本,主键(isbn,作者))
注意:使用此数据模型时,必须始终使用isbn进行查询,但作者是可选的。
不应使用“允许筛选”。会对性能产生影响。
如何在cassandra中声明分区和集群密钥非常重要,应该逐个查询地使用。如果您有一个查询相同数据但在不同where子句中的新用例,请创建一个新表!:d

new9mtju

new9mtju2#

此链接可能会对您有所帮助。据我所知,Cassandra的表演很成功,如果你 allow filtering (猜测它类似于sqlrbar,它很慢,为什么它会抛出和过滤错误)
我对cassandra还是比较陌生的,但是从我所读到的内容来看,如果您还没有定义辅助索引,您需要运行select查询来包含在主键中定义的所有列。但二级索引也有局限性。
祝你好运。

相关问题