【发布时间】:2019-06-04 03:25:52
【问题描述】:
我尝试在索引列中选择包含至少一行具有特定值的分区键。
使用当前解决方案可以满足所有其他要求:
- 能够根据办公室选择报告。
- 给定办公室,可以使用类型和日期范围进行选择。
- 无需根据日期选择报告,无需排放办公室和/或报告类型。
最后,我需要能够选择某个用户已创建报告的所有办公室。根据 cassadra 文档,我在用户列上添加了一个索引。
表定义为:
create table report(
office uuid,
type text,
insert_date timestamp,
...
created_by uuid,
...
primary key(office, type, insert_date));
create index created_by_idx on report (created_by);
如果我没记错的话,使用该索引就像有一个如下描述的辅助表:
create table report2(
created_by uuid,
office uuid,
type text,
insert_date timestamp,
...
primary key(created_by ,office, type, insert_date));
我可以成功运行如下查询:
select office from report where created_by = ?
但这会导致多行具有相同的办公室密钥,这是正确的:每个用户可以在每个办公室创建多个报告。
现在我在软件级别过滤重复的办公室,但我问自己是否可以在提取过程中直接过滤这些数据。
我试过了:
select distinct office from report where created_by = ?
这导致
SELECT DISTINCT with WHERE clause only supports restriction by partition key and/or static columns.
然后我尝试:
select office from report where created_by = ? group by office
这给了我正确的结果,但发出警告:
Aggregation query used without partition key
这可能是个问题吗?如何处理 cassandra 这样的查询,在这种情况下可以忽略此警告吗?最后,真的是一个更好的选择,使用这样的查询来对抗
select * ... 有相同的 where 子句吗?
【问题讨论】: