首页 > 解决方案 > Cassandra 通过主键查询和列抛出错误

问题描述

架构

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给了我一些线索。

标签: databasecassandracql

解决方案


链接可能会对您有所帮助。据我了解,如果您使用 cassandra 会降低性能allow filtering(猜测它类似于 SQL RBAR,它很慢,以及为什么它会抛出和过滤错误)

我对 cassandra 还比较陌生,但是从我读过的内容来看,如果您没有定义二级索引,您需要运行选择查询以包含主键中定义的所有列。但是二级索引有局限性。

HTH 祝你好运。


推荐阅读