允许过滤对cassandra中相同分区查询的性能影响

时间:2017-03-21 16:26:08

标签: cassandra

我有这样的表格。

CREATE TABLE posts (
topic text
country text,
bookmarked text,
id uuid,
PRIMARY KEY (topic,id)
);

首先使用允许过滤查询单个分区。

select * from posts where topic='cassandra' allow filtering;

单个分区的第二个查询,不允许过滤。

select * from posts where topic='cassandra';

我的问题是第一个查询和第二个查询之间的性能差异是什么?首先查询(使用允许过滤)在过滤之前从所有分区获取结果,尽管我们已从单个分区请求。

感谢。

2 个答案:

答案 0 :(得分:3)

允许过滤将允许您在不指定分区键的情况下运行查询。但是如果你使用一个,它将只使用特定的分区。

在这个具体的例子中,您应该看不出任何区别。

在我的测试表上查询两个查询,并在两个执行计划中获得单个分区:

 Executing single-partition query on table_name

答案 1 :(得分:2)

使用分区键查询时,不需要使用foreach ($category_info as $result) { $data['categories'][] = array( 'name' => $result['name'], 'parent_id' => $result['parent_id'], 'thumb' => $this->model_tool_image->resize($result['image'], $this->config->get('config_image_category_width'), this->config->get('config_image_category_height')), 'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..', /*'href' => $this->url->link('product/filter', '&category_id=' . $result['category_id']) 'href' => $this->url->link('product/sub_category')*/ if($result['category_id']==24) { 'href' => $this->url->link('product/transmission', 'sub_category_id='.$result['parent_id'].'&category_id=' . $result['category_id']) } elseif { /*some code for href*/ } ); } 。因此,对于您提到的两个查询,将没有性能差异。

对于Cassandra 3.0及更高版本,ALLOW FILTERING可用于查询除分区键以外的任何字段。例如,您可以运行如下查询:

ALLOW FILTERING

对于3.0以下的Cassandra版本,SELECT * FROM posts where country='Bangladesh'; 只能用于主键。 虽然使用ALLOW FILTERING查询是不明智的。 因为,Cassandra执行此查询的唯一方法是从表ALLOW FILTERING中检索所有行,然后筛选出那些没有posts列所请求值的行。 所以你应该自担风险使用country