# Using IN in CQL Queries, Performance

**URL:** <https://forum.scylladb.com/t/using-in-in-cql-queries-performance/893>\
**Category:** ScyllaDB\
**Tags:** data-model, cql\
**Created:** [October 5, 2023, 10:46am UTC](https://forum.scylladb.com/t/using-in-in-cql-queries-performance/893 "2023-10-05T10:46:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guy](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.scylladb.com/guy/32/9_2.png) [@Guy](https://forum.scylladb.com/u/Guy)\
**Post date:** [October 5, 2023, 10:46am UTC](https://forum.scylladb.com/t/using-in-in-cql-queries-performance/893/1 "2023-10-05T10:46:05Z")

</div>

> [@](#):
>
> [**View in #general on Slack**](https://slack.com/archives/C2NLNBXLN/p1696446720212539)
> 
> ![Hartmut](https://us1.discourse-cdn.com/flex016/uploads/scylladb/original/1X/30999c3e82aa56f02ef8170f1eea35f2897d26cf.jpeg) **@Hartmut:** Hi, which would be the recommended/preferred query pattern or anti-pattern?  
> (A vs. B)
> 
> ```auto
> CREATE TABLE test (
> pk text,
> val1 text,
> val2 text,
> PRIMARY KEY (pk)
> );
> 
> INSERT INTO test (pk, val1, val2) VALUES ('a', 'foo', 'bar');
> INSERT INTO test (pk, val1, val2) VALUES ('b', 'some', 'data');
> INSERT INTO test (pk, val1, val2) VALUES ('c', 'scylla', 'db');
> 
> -- A) individual queries (in parallel, pooled)
> SELECT * FROM test WHERE pk='a';
> SELECT * FROM test WHERE pk='c';
> -- B) `IN ()`
> SELECT * FROM test WHERE pk IN ('a', 'c');
> 
> ```
> 
> B) obviously isn’t shard-aware but needs to be orchestrated  
> I guess it may depend on the actual use case, how many rows are to be fetched and so on…  
> But still, I wonder if anyone has any experience or insights to share…? 🙂
> 
> ![avi](https://us1.discourse-cdn.com/flex016/uploads/scylladb/original/1X/b5e08becda8d9df1abff1d3a2d9ffe1126ac3fc6.jpeg) **@avi:** Individual queries are generally better. You’ve moving some of the coordination from the server to the client, which is more easily scaled. The single IN query cannot be made shard/token aware, so you pay with an extra hop.
> 
> ![Hartmut](https://us1.discourse-cdn.com/flex016/uploads/scylladb/original/1X/30999c3e82aa56f02ef8170f1eea35f2897d26cf.jpeg) **@Hartmut:**
> 
> ```auto
> CREATE TABLE test2 (
> pk text,
> ck text,
> val1 text,
> PRIMARY KEY (pk, ck)
> );
> SELECT * FROM test2 WHERE pk='a' AND ck IN ('x', 'y');
> 
> ```
> 
> On the contrary, when querying a specific partition, it should be perfectly valid, correct?
> 
> ![avi](https://us1.discourse-cdn.com/flex016/uploads/scylladb/original/1X/b5e08becda8d9df1abff1d3a2d9ffe1126ac3fc6.jpeg) **@avi:** Yes, in this case IN is preferable
