Use COUNT(*) to count the number of matches for a query:
SELECT COUNT(*) FROM mock_items
WHERE id @@@ paradedb.all();
To exclude null values of a specific field from the final count, pass the field into COUNT:
SELECT COUNT(rating) FROM mock_items
WHERE id @@@ paradedb.all();
The field being counted, in this case rating, must be indexed as fast.
To verify that COUNT was pushed down, look for a ParadeDB Aggregate Scan with value_count in the EXPLAIN output:
EXPLAIN SELECT COUNT(rating) FROM mock_items
WHERE id @@@ paradedb.all();
Expected Response
                                      QUERY PLAN
---------------------------------------------------------------------------------------
 Custom Scan (ParadeDB Aggregate Scan) on mock_items  (cost=0.00..0.00 rows=0 width=8)
   Index: search_idx
   Tantivy Query: {"with_index":{"query":"all"}}
   Aggregate Definition: {"0":{"value_count":{"field":"rating"}}}
(4 rows)