I try to select the partition keys that contain at least one row with a specific value in an indexed column.
With the current solution all the other requirements are met:
- Ability to select reports based on their office.
- Given an office, ability to select using type and date range.
- No needs to select reports based on date without emission office and/or reports type.
Last, i need the ability to select all the offices where a certain user has created a report. Based on cassadra documentation i have added an index on the user column.
The table is defined as:
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);
Using that index, if i'm not wrong, is like having a secondary table described as follow:
create table report2(
created_by uuid,
office uuid,
type text,
insert_date timestamp,
...
primary key(created_by ,office, type, insert_date));
I can successfully run a query like:
select office from report where created_by = ?
but that results in multiple row with the same office key, that it is correct: each user can create multiple report in each office.
Now i filter duplicated offices at software level, but i'm asking myself if it was possible to filter that data directly during extraction.
I tried:
select distinct office from report where created_by = ?
that results in
SELECT DISTINCT with WHERE clause only supports restriction by partition key and/or static columns.
Then i tried:
select office from report where created_by = ? group by office
that give me the correct results, but raise a warning:
Aggregation query used without partition key
Could this be a problem somehow? How handle cassandra a query like this and can this warning, in this case, be ignorated? And finally, is really a better choise use a query like this against a
select * ... whit the same where clause?