Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Faster way of counting total number of columns in a cassandra row with hector

I want to count the total number of columns for a Cassandra row using Hector client. Currently I am doing this with a CountQuery, but it seems really slow to me. Also for a row, with just 60k columns it's taking nearly 2 seconds. My code currently looks like this:

QueryResult<Integer> qr = HFactory.createCountQuery(ksp, se, se).
    setColumnFamily("ColumnFamily1").
    setKey("RowKey").
    setRange(null, null, 1000000000).execute();

PS: I have to set the range to such a high number, otherwise it only counts me max. to the number I've provided in the range.

Any ideas how I can improve this?

like image 761
H6. Avatar asked Jan 03 '12 15:01

H6.


1 Answers

Counting columns in Cassandra is inherently slow. Cassandra has to iterate over the whole row in order to return the count.

You probably want to denormalize the count. You could use a counter column which you update every time you insert.

like image 133
psanford Avatar answered Oct 21 '22 12:10

psanford