"PER PARTITION LIMIT" 在 cassandra 的 cql 查询中意味着什么?
What does "PER PARTITION LIMIT" means in cql query in cassandra?
我有一个scylla table如下图:
cqlsh:sampleks> describe table test;
CREATE TABLE test (
client_id int,
when timestamp,
process_ids list<int>,
md text,
PRIMARY KEY (client_id, when) ) WITH CLUSTERING ORDER BY (when DESC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class': 'TimeWindowCompactionStrategy', 'compaction_window_size': '1', 'compaction_window_unit': 'DAYS'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 172800
AND max_index_interval = 1024
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';
我看到这就是我们查询它的方式。我在 cassandra 上工作了很长时间,所以这个 PER PARTITION LIMIT
对我来说是新事物(看起来是最近添加的)。有人可以用外行语言解释一些例子吗?我找不到任何容易解释的好文档。
SELECT * FROM test WHERE client_id IN ? PER PARTITION LIMIT 1;
PER PARTITION LIMIT
子句在 "wide partition scenario." 中很有用
它 return 只是分区中的前两行。
接受这个查询:
aploetz@cqlsh:Whosebug> SELECT client_id,when,md
FROM test PER PARTITION LIMIT 2 ;
考虑到 (client_id,when)
的 PRIMARY KEY 定义,该查询将遍历每个 client_id
。然后,Cassandra 将 return 仅来自该分区的前两行(由 when
聚类),而不管 when
可能出现多少次。
在这种情况下,我使用两个不同的 client_id
向您的 test
table 中插入了 7 行(总共 2 个分区)。使用 2 的 PER PARTITION LIMIT
,我得到 4 行 returned (2 client_id
x PER PARTITION LIMIT
2) == 4 行。
client_id | when | md
-----------+---------------------------------+-----
1 | 2020-05-06 12:00:00.000000+0000 | md1
1 | 2020-05-05 22:00:00.000000+0000 | md1
2 | 2020-05-06 19:00:00.000000+0000 | md2
2 | 2020-05-06 01:00:00.000000+0000 | md2
(4 rows)
我有一个scylla table如下图:
cqlsh:sampleks> describe table test;
CREATE TABLE test (
client_id int,
when timestamp,
process_ids list<int>,
md text,
PRIMARY KEY (client_id, when) ) WITH CLUSTERING ORDER BY (when DESC)
AND bloom_filter_fp_chance = 0.01
AND caching = {'keys': 'ALL', 'rows_per_partition': 'ALL'}
AND comment = ''
AND compaction = {'class': 'TimeWindowCompactionStrategy', 'compaction_window_size': '1', 'compaction_window_unit': 'DAYS'}
AND compression = {'sstable_compression': 'org.apache.cassandra.io.compress.LZ4Compressor'}
AND crc_check_chance = 1.0
AND dclocal_read_repair_chance = 0.1
AND default_time_to_live = 0
AND gc_grace_seconds = 172800
AND max_index_interval = 1024
AND memtable_flush_period_in_ms = 0
AND min_index_interval = 128
AND read_repair_chance = 0.0
AND speculative_retry = '99.0PERCENTILE';
我看到这就是我们查询它的方式。我在 cassandra 上工作了很长时间,所以这个 PER PARTITION LIMIT
对我来说是新事物(看起来是最近添加的)。有人可以用外行语言解释一些例子吗?我找不到任何容易解释的好文档。
SELECT * FROM test WHERE client_id IN ? PER PARTITION LIMIT 1;
PER PARTITION LIMIT
子句在 "wide partition scenario." 中很有用
它 return 只是分区中的前两行。
接受这个查询:
aploetz@cqlsh:Whosebug> SELECT client_id,when,md
FROM test PER PARTITION LIMIT 2 ;
考虑到 (client_id,when)
的 PRIMARY KEY 定义,该查询将遍历每个 client_id
。然后,Cassandra 将 return 仅来自该分区的前两行(由 when
聚类),而不管 when
可能出现多少次。
在这种情况下,我使用两个不同的 client_id
向您的 test
table 中插入了 7 行(总共 2 个分区)。使用 2 的 PER PARTITION LIMIT
,我得到 4 行 returned (2 client_id
x PER PARTITION LIMIT
2) == 4 行。
client_id | when | md
-----------+---------------------------------+-----
1 | 2020-05-06 12:00:00.000000+0000 | md1
1 | 2020-05-05 22:00:00.000000+0000 | md1
2 | 2020-05-06 19:00:00.000000+0000 | md2
2 | 2020-05-06 01:00:00.000000+0000 | md2
(4 rows)