I am wondering what is the best way to get the number of columns in a particular column family. I can get the number of columns directly but I am not sure if it is efficient solution. On the other hand I can maintain another column family with a counter column that holds the number of columns. Do you have any experience with similar problems?
Asked
Active
Viewed 4,377 times
1 Answers
6
http://wiki.apache.org/cassandra/API explains that the get_count method:
...is not O(1). It takes all the columns from disk to calculate the answer. The only benefit of the method is that you do not need to pull all the columns over Thrift interface to count them.
If you only need the count very occasionally, and/or the number of columns is small, then this may not matter.
If performance matters, then you'd be better off with counters.
See http://www.datastax.com/dev/blog/whats-new-in-cassandra-0-8-part-2-counters
-
1And since it isn't possible to put counters and data in the same CF yet, they won't be atomic. (though there is an issue open and being worked on to allow this to happen) – Zanson Sep 01 '11 at 16:00