TerminusDB 12.1.0-rc1 makes counting fast everywhere you used to enumerate to count. These features are staged for the 12.1 release and available in the 12.1 release candidates.
- WOQL pattern and range counts —
triple_countaccepts partial patterns;triple_range_countcounts typed values in a half-open range. counteddocument listings —counted=truereturns just the number of documents a listing would yield.- Fast GraphQL
_count— empty-filter_countresolves from the store indexes.
All of them are answered from the persistent indexes in terminusdb-store, so no triples or documents are materialized. On one million documents, counting drops from seconds of streaming to about 20 milliseconds.
WOQL pattern and range counts
triple_count keeps its resource form and gains a pattern form (subject, predicate, object, count, [graph]). Each component can be bound or a variable acting as a wildcard:
WOQL.triple_count("v:s", "rdf:type", "scm:Person", "v:n")triple_range_count(subject, predicate, low, high, count, [graph]) counts triples whose typed object value falls in the half-open range [low, high), optionally restricted by subject and predicate. quad_range_count passes an explicit graph.
WOQL.triple_range_count("v:s", "scm:age", { "@type": "xsd:integer", "@value": 18 }, { "@type": "xsd:integer", "@value": 30 }, "v:n")counted document listings
Pass counted=true on the document listing endpoint to get the count the listing would yield, without the documents:
curl "http://localhost:6363/api/document/admin/db?type=Person&counted=true"{ "@type": "api:DocumentCountResponse", "api:count": 1000000 }Type-restricted counts include subclasses, and subdocuments follow the same rules as the listing (unfold=true excludes them). counted cannot be combined with id, ids or query — the server answers api:CountedNotSupportedForSelector.
Fast GraphQL _count
_count on a document field resolves through the indexes when the filter is empty:
{ _count(Person: {}) }Filtered _count traverses as before; the fast path applies to the unfiltered case. The same surface is available in the JavaScript and Python clients.