Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

leehuihua avatar image
leehuihua asked Erick Ramirez commented

Is it fine to use the IN() operator for queries on a single partition key?

Hi:

I know using in() query involving multiple partitions is a bad idea. How about in() query on one partition? If I provide the partition key and using IN on a clustering key,i 'll benefit from being able to retrieve data by hitting only one node . Is this a better way than running multiple parallel queries on the client side?

cql
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

It is fine to use the IN() operator on clustering keys if you restrict the query to a single partition. This is in fact the only valid use of the IN() operator since it will only filter the rows within a single partition.

For the second part of your question, it doesn't make sense to issue multiple queries since you're only retrieving a single partition from the database. Cheers!

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

thanks!

If there are many clustering keys (for example,100 ) ,the database searches them one by one? if so, maybe partition these clustering keys into ten parallel queries ,every query contains 10 clustering keys, will it be faster than one query containing 100 clustering keys?

0 Likes 0 ·
If you look at the schema, you'll see that the clustering columns are sorted either in ascending or descending order. This means that Cassandra knows not to keep iterating over the rows. Cheers!
0 Likes 0 ·