Details
-
Bug
-
Status: Resolved
-
Urgent
-
Resolution: Invalid
-
None
-
None
-
Critical
Description
There is a strange behaviour of the IN clause with lots of keys when used outside a QueryBuilder. Here is the test I did using the Java Driver 2.0.3 and Cassandra 2.0.7
CREATE TABLE inlimit (
key int,
value text,
PRIMARY KEY (key)
)
I've populated the table with 105000 entries (key from 0 to 104999).
cqlsh:test> select count(*) from inlimit limit 200000; count -------- 105000
Here the test:
String query = "SELECT * FROM inlimit WHERE key IN :key"; PreparedStatement ps = Cassandra.DB.getSession().prepare(query); BoundStatement bs = new BoundStatement(ps); List<Integer> l = new ArrayList<>(); for (int i = 0; i < 100000; i++) { l.add(i); } bs.setList("key", l); ResultSet rs = Cassandra.DB.getSession().execute(bs); System.out.println("counted rows: " + rs.all().size());
Here the output:
counted rows: 34464
While with QueryBuilder everything changes:
List<Integer> l = new ArrayList<>(); for (int i = 0; i < 100000; i++) { l.add(i); } BuiltStatement bs = QueryBuilder.select().all().from("inlimit").where(in("key", l.toArray())); ResultSet rs = Cassandra.DB.getSession().execute(bs); System.out.println("counted rows: " + rs.all().size());
The new output
counted rows: 100000
BTW: I'd suggest to write somewhere if the IN clause has some limitations cause I found this question without answer in many forums.
Cheers,
Carlo