Search code examples
cassandradatabase-performancequery-performancecassandra-3.0

COUNT(*) vs. COUNT(1) performance in Cassandra


According to the docs:

A SELECT expression using COUNT(*) returns the number of rows that matched the query. Alternatively, you can use COUNT(1) to get the same result.

Are there any performance benefits (as in RDBMSes) from using the latter approach?


Solution

  • There is no difference between COUNT(*) and COUNT(1). COUNT(1) is just for backwards compatibility I think with some older stuff. selectCountClause returns empty RawSelector list regardless of the contents, but if its a number and not 1 or not '*' it will throw an exception.

    You might wanna avoid count in general if worried about performance. Instead use a counter or maintain count at higher level instead.