What’s the difference between fetchCount and c3Count?

#1

What’s the difference between fetchCount and c3Count? Is one better than the other?

0 Likes

#2

There is no functional difference between the two—they both make the same API call internally. c3Count is only available as a helper function in the client-side C3 JavaScript Type System, so it is not available in the server-side runtime. fetchCount is defined as a static method on the Persistable type and is therefore available beyond just the client-side C3 JavaScript Type System (e.g., via REST API, in the server-side JS runtime, etc.).

1 Like

#3

Is this expected?

41%20PM

0 Likes

#4

It seems that there is actually a difference at least for Cassandra entities (in 7.6), I have an example for calling c3Count(Measurement) and Measurement.fetchCount() the first one returns a big number (after a very long time) and the latest returns 2 pretty quickly.

0 Likes

#5

c3Count actually executes %type%.evaluate({projection: "count(id)", limit:-1}). It is possible that for Cassandra types, fetchCount() is not implemented the same way.

0 Likes

#6

Regarding the slow evaluation of the c3Count, I have found this interesting article explaining the difference between Cassandra count and relational databases:

0 Likes

#7

fetchCount actually does:

%type%.evaluate({projection: "count()", limit:1})

Note that count() doesn’t specify id and the limit is 1. The limit is “supposed” to apply to the number of tuples returned from the evaluate. I wouldn’t expect this to produce different results than c3Count so if it does, please file a ticket. Keep in mind that when we are counting in cassandra, we aren’t counting keys, but counting all of the objs in the table, which is extremely slow on large cassandra types so it isn’t recommended.

0 Likes