Reputation: 994
We have a simple table that we would like to count the amount of columns that contains in a specific row.
CREATE TABLE ourkeyspace.usersession (
date text,
time timeuuid,
encryptedtrackerid text,
PRIMARY KEY (date, time)
) WITH CLUSTERING ORDER BY (time ASC) AND
compaction={'class': 'SizeTieredCompactionStrategy'} AND
compression={'sstable_compression': 'SnappyCompressor'}
My question is, Why do I need to set the LIMIT on the query if I am counting the columns?
SELECT COUNT(*) FROM usersession WHERE date = '22-10-2013' LIMIT 99999999;
Upvotes: 3
Views: 2426
Reputation: 16576
The main reason is that Cassandra is not designed for that sort of request. When you make a call like this (which must scan all partition ranges) the request will most likely time out on a large enough data size. Because of this CQLSH and now DevCenter both have built in limiters to stop queries which may take a very long time (like a count(*)). Although you can use limit 999999999 as a workaround this will still timeout when there is enough data in the database.
If you actually want to know how many of rows there are (or count anything in general) It is best to use a counter column. You can then have your application increment the counter whenever an new row is added and decremented when a row is removed.
Upvotes: 2