Skip to content

COUNT ?s rdf:type rdfs:Class returns 0 on indexed data when rdfs:Class is mid-leaflet #1208

Closed

Description

@aaj3f

Symptom

After bulk-importing an RDFS-style ontology, a COUNT(?c) WHERE { ?c a rdfs:Class } query returns 0 even though the triples are present in the index. The same data is reachable via other query shapes:

# Query Result
A ?c a rdfs:Class (prefixed) 0 ❌
B ?c <rdf:type-IRI> <rdfs:Class-IRI> (full IRIs) 0 ❌
C ?c rdf:type ?t . FILTER(?t = rdfs:Class) (FILTER rewrite) correct count ✅
D ?s rdf:type ?t GROUP BY ?t (aggregate) shows the correct rdfs:Class count ✅
E <some-instance> ?p ?o (describe a class instance) yields rdf:type rdfs:Class ✅
F ?p a rdf:Property (parallel of A for rdf:Property) correct count ✅
G ?c a <user-class> (parallel of A for a user class) correct count ✅

?s rdf:type rdf:Property and arbitrary user classes work — only rdfs:Class is invisible to the bound-object form.

Reproduction

Bulk-import an RDFS ontology declaring multiple classes via a rdfs:Class plus a moderate amount of instance data, then run a COUNT query against ?c a rdfs:Class.

@prefix ex:   <http://example.org/ns/> .
@prefix exd:  <http://example.org/data/> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .

ex:ClassA  a rdfs:Class .
ex:ClassB  a rdfs:Class .
ex:ClassC  a rdfs:Class .
# … (more classes) …

ex:propX a rdf:Property ; rdfs:domain ex:ClassA ; rdfs:range xsd:string .
# … (more properties) …

# Plus several thousand instance triples
exd:item-1 a ex:ClassA ; ex:propX "value-1" .
# …
fluree create my-db --from path/to/ttl/dir
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (COUNT(?c) AS ?n) WHERE { ?c a rdfs:Class }
# expected: count of declared classes, actual: 0

A self-contained regression test that builds a small bulk-imported ledger and reproduces the asymmetry deterministically lives at fluree-db-api/tests/it_query_rdfs_class_repro.rs::count_bound_object_mixed_leaflet_regression.

Workarounds (until fixed)

Any of these return the correct count:

  1. Rewrite as a FILTER form: ?c rdf:type ?t . FILTER(?t = rdfs:Class)
  2. Use a plain SELECT ?c (no aggregate) — only the COUNT path is broken
  3. Add "reasoning": "none" to a JSON-LD query

Scope

  • Affects bulk-imported / indexed datasets, not pure-novelty (memory-only) ledgers.
  • Triggered for any class IRI whose first instance lands inside a POST leaflet rather than at its boundary; rdfs:Class happens to be a frequent victim because it sorts between rdf:Property and any user-namespaced class.
  • Affects both JSON-LD and SPARQL forms of the query.
  • Branch reproduced on: main (worktree at commit efa05951), Fluree CLI v4.0.1 release build.

Notes

The data is correct on disk: range_with_overlay(OPST, p=rdf:type, o=rdfs:Class) returns the expected flakes, and snapshot.encode_iri(...) produces matching SIDs. The bug is in the COUNT fast-path's leaflet-skip heuristic — see linked PR for details.

Activity

  1. changed the title [-]COUNT `?s rdf:type rdfs:Class` returns 0 on indexed data when rdfs:Class is mid-leaflet[/-] [+]COUNT `?s rdf:type rdfs:Class` returns 0 on indexed data when `rdfs:Class` is mid-leaflet[/+] on Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions