New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't filter by more than one indexed column #208
Comments
From the cassandra documentationCREATE TABLE ruling_stewards (
steward_name text,
king text,
reign_start int,
event text,
PRIMARY KEY (steward_name, king, reign_start)
); This query constructs a filter that selects data about stewards whose reign started by 2450 and ended before 2500. If king were not a component of the primary key, you would need to create an index on king to use this query: SELECT * FROM ruling_stewards
WHERE king = 'Brego'
AND reign_start >= 2450
AND reign_start < 2500 ALLOW FILTERING; The output is: steward_name | king | reign_start | event
--------------+-------+-------------+--------------------
Boromir | Brego | 2477 | Attacks continue
Cirion | Brego | 2489 | Defeat of Balchoth
To allow Cassandra to select a contiguous ordering of rows, you need to include the king component of the primary key in the filter using an equality condition. The ALLOW FILTERING clause is also required. ALLOW FILTERING clauseWhen you attempt a potentially expensive query, such as searching a range of rows, this prompt appears:
To run the query, use the ALLOW FILTERING clause. Imposing a limit using the LIMIT n clause is recommended to reduce memory used. I guess the solution is to add |
@Micka33 Cequel currently doesn't allow filtering, but I've been thinking it would be best to change that |
@outoftime Yes, I think it's should be accessible in some way. |
I tried to add allow_filtering to my query: this error raised before the query executed, it is from: but when my query filters by only one field: the problem is when I'm trying to filter by more than one field. Thanks |
@yeudit Also here is part of a model I have. class Propositions
include Cequel::Record
key :id, :bigint, { partition: true }
key :ending_period, :timestamp, { order: :desc }
key :starting_period, :timestamp
key :ia, :text
column :resourceType, :text
end I suggest that you read about compound keys and about what a partition key is. When you add Hint: When you query in your |
i'm not an cassandra expert, so i don't know if this considered a bad practice, but i would really like to use those are the use-cases:
something that might be explicit and easy to implement could be like # reference-id would have high cardinality, so not a good secondary index
# column :reference_id, :bigint, index: true
column :reference_id, :bigint, allow_filtering: true # i know what i'm doing here! |
I think it would be a bit too dangerous to globally allow filtering on a column. Whether or not filtering will have acceptable performance depends on the rest of the query, in addition to the table structure. I would merge a PR that provided a way to add |
I think @Micka33's suggestion of |
I'm getting an 'Cequel::Record::IllegalQuery: Can't scope by more than one indexed column in the same query' exception.
I have a record class:
I'm trying to get all spaces with name => x and type => y. Example:
Space.where({name: 'name', type: 'type'})
This raises 'Cequel::Record::IllegalQuery: Can't scope by more than one indexed column in the same query' error.
I want to know how can I filter records by 2 or more columns?
The text was updated successfully, but these errors were encountered: