簡體   English   中英

主鍵和列的Cassandra查詢引發錯誤

[英]Cassandra query by primary key and a column throws error

架構

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給了我一些線索。

鏈接可能對您有所幫助。 根據我的理解,如果你allow filtering那么使用cassandra會有性能損失(猜測它類似於SQL RBAR ,這很慢,為什么它會拋出並且有關過濾的錯誤)

我對cassandra還是比較新的,但是根據我的閱讀,你需要運行select查詢以包含主鍵中定義的所有列,如果你還沒有定義二級索引。 但二級索引存在局限性。

HTH祝你好運。

在Cassandra中,您無法查詢非分區或群集鍵列。

如果您希望確切的上述用例工作,則必須將作者包含在主鍵聲明中。

CREATE TABLE書籍(isbn text,author text,PRIMARY KEY(isbn,author))

注意 :使用此數據模型,您必須始終使用isbn進行查詢,但作者是可選的。

您不應該使用允許過濾。 會對性能產生影響。

如何在cassandra中聲明分區和群集密鑰非常重要,應該在查詢的基礎上使用。 如果您有一個新的用例來查詢相同的數據,但在另一個where子句中,請創建一個新表! :d

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM