Speed up c3Count trick/s?


When I perform c3Count(TypeName), it takes an extraordinary long time when there are millions of records in the type object. Is there a way that this can be expedited?

By way of example: if I did a ‘select count ( * ) as recs from TABLE_NAME ‘ in Oracle, it would also take very long, but when I gave it a hint, as in
‘select /*+ ALL_ROWS */ count ( ‘a’ ) as recs from TABLE_NAME’, it would then alter the optimizer path and force it to find a unique index (preferably a PK index) and do a scan on the index using multi-block read-ahead and return the results in second, often sub-second.

Is there anything like this available for C3 so that we are not forced to watch the screen like animals at the zoo waiting to be fed?



c3Count is a helper function that under the hood calls evaluate({projection: "count(id)", filter: ...}) on the given type. Which means, it is already using the trick of using the indexed field id!

If you did define unique indexes for your type (i.e. through @db(unique=[. . .]) annotation) then you can try to use them when counting your objects:

c3Grid(TargetType.evaluate({projection: "count(UNIQUE_INDEX)"}))


Got this trick from Yaroslav, works very nicely.

what it does is kicks off a MapReduce job to calculate statistics (on an object called PointPhysicalMeasurementSeries) and then the count is persisted and queried very fast.

MeasurementSeries.startUpdateStats(100, “typeIdent==’” + PointPhysicalMeasurementSeries.getTypeIdent() + “’”)

To check on the status of the job calculating the statistics, run:

Then once it is done, perform the following query:
3Table(PointPhysicalMeasurementSeries.evaluate({projection:“metricName, sum(stats.count)”, group:“metricName”}))

|c1 |

The above returns sub-second once the stats exist.

1 Like