![](/img/trans.png)
[英]Cassandra, query the primary key, skipping the clustering column (timeuuid)
[英]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給了我一些線索。
在Cassandra中,您無法查詢非分區或群集鍵列。
如果您希望確切的上述用例工作,則必須將作者包含在主鍵聲明中。
CREATE TABLE書籍(isbn text,author text,PRIMARY KEY(isbn,author))
注意 :使用此數據模型,您必須始終使用isbn進行查詢,但作者是可選的。
您不應該使用允許過濾。 會對性能產生影響。
如何在cassandra中聲明分區和群集密鑰非常重要,應該在查詢的基礎上使用。 如果您有一個新的用例來查詢相同的數據,但在另一個where子句中,請創建一個新表! :d
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.