![](/img/trans.png)
[英]Cassandra batch query performance on tables having different partition keys
[英]Cassandra: Why do I not have to include all partition keys in query?
目前,我正在與Cassandra打交道。
閱讀博客文章時,據說:
發出CQL查詢時,必須至少包括所有分區鍵列。 ( https://shermandigital.com/blog/designing-a-cassandra-data-model/ )
但是,在我的數據庫中似乎可以不包含所有分區鍵。 下表:
CREATE TABLE usertable (
personid text,
name text,
"timestamp" timestamp,
active boolean,
PRIMARY KEY ((personid, name), timestamp)
) WITH
CLUSTERING ORDER BY ("timestamp" DESC)
AND comment=''
AND read_repair_chance=0
AND dclocal_read_repair_chance=0.1
AND gc_grace_seconds=864000
AND bloom_filter_fp_chance=0.01
AND compaction={ 'class':'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy',
'max_threshold':'32',
'min_threshold':'4' }
AND compression={ 'chunk_length_in_kb':'64',
'class':'org.apache.cassandra.io.compress.LZ4Compressor' }
AND caching={ 'keys':'ALL',
'rows_per_partition':'NONE' }
AND default_time_to_live=0
AND id='23ff16b0-c400-11e8-55c7-2b453518a213'
AND min_index_interval=128
AND max_index_interval=2048
AND memtable_flush_period_in_ms=0
AND speculative_retry='99PERCENTILE';
所以我可以select * from usertable where personid = 'ABC-02';
。 但是,根據博客文章,我還必須包括timestamp
。
有人可以解釋嗎?
在cassandra中,分區鍵可在群集周圍散布數據。 它計算分區鍵的哈希值,並確定數據在群集中的位置。
一個例外是,如果您使用ALLOW FILTERING或二級索引,則不需要在查詢的位置也包括所有分區鍵。
有關更多信息,請參閱博客文章:
分區鍵的目的是將數據拆分為多個分區,整個分區存儲在群集中的單個節點上(每個節點存儲多個分區)。 從群集讀取或寫入數據時,將使用一個名為Partitioner的函數來計算分區鍵的哈希值。 該哈希值用於確定包含該行的節點/分區。 聚類關鍵字還用於在給定分區內搜索一行。
Apache Cassandra中的選擇查詢看起來很像關系數據庫中的選擇查詢。 但是,它們受到的限制更大。 Cassandra查詢的“ where”子句中允許的屬性必須包括完整分區鍵,其他子句只能引用集群鍵列或所查詢表的二級索引。
通過允許Cassandra確定分區以及節點(甚至磁盤上的數據文件)來確定橫向擴展群集,在“ where”中要求分區鍵屬性可幫助Cassandra保持恆定的結果集檢索時間。查詢必須定向。
如果查詢未在'where'子句中指定主鍵中所有列的值,Cassandra將不執行它並給出以下警告:
''InvalidRequest:來自服務器的錯誤:代碼= 2200 [Invalid query] message =“”無法執行此查詢,因為它可能涉及數據過濾,因此可能具有不可預測的性能。 如果盡管性能不可預測但仍要執行此查詢,請使用ALLOW FILTERING”'
https://www.instaclustr.com/apache-cassandra-scalability-allow-filtering-partition-keys/
https://www.datastax.com/dev/blog/a-deep-look-to-the-cql-where-clause
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.