Repository navigation
Description
Three query fast paths fail with an internal error when the query names a predicate the index has never seen. They should return an empty result:
Query error: Internal error: predicate not found in binary index dict: http://example.org/nope
The same predicate in a shape no fast path takes (rows instead of a count, a count with no filter) correctly returns empty. It bites whenever a query targets a predicate that hasn't been written yet, such as an optional property no data uses so far.
Reproduction (main, v4.2.7, CLI)
@prefix ex: <http://example.org/> .
ex:p1 a ex:Person ; ex:name "abc one" ; ex:age 30 ; ex:knows ex:p2 .
ex:p2 a ex:Person ; ex:name "abd two" ; ex:age 40 ; ex:knows ex:p1 .
ex:p3 a ex:Person ; ex:name "xyz three" ; ex:age 50 ; ex:knows ex:p1 .fluree create t --from data.ttl, then each query below. Then fluree insert one triple, fluree index, and each query again.
| Query | Fresh import | After a commit and an index pass |
|---|---|---|
SELECT (COUNT(*) AS ?c) WHERE { ?s ex:nope ?o FILTER(STRSTARTS(?o, "abc")) } |
error | 0 |
JSON-LD: (as (count *) ?c) with ["filter", "(strStarts ?o \"ab\")"] |
error | 0 |
SELECT ?s ?l WHERE { ?s ex:nope ?l . ?s a ex:Person . FILTER regex(?l, "a") } (SPARQL and JSON-LD) |
error | error |
SELECT DISTINCT ?s ?l WHERE { ?s ex:knows ex:p1 . ?s ex:age ?v FILTER(?v > 1) . ?s ex:nope ?l } ORDER BY ?l LIMIT 5 |
error | error |
SELECT ?o WHERE { ?s ex:nope ?o FILTER(STRSTARTS(?o, "abc")) } |
empty | empty |
SELECT (COUNT(*) AS ?c) WHERE { ?s ex:nope ?o } |
0 | 0 |
- The STRSTARTS count fails only while its fast path is on: after a fresh import or a full reindex, with no commits since. After a commit that path stays off (STRSTARTS fast paths stop firing once a ledger takes a commit #2442), so the query falls back and correctly returns 0.
- The other two shapes fail on any indexed ledger whose index is current.
The bench also hit the STRSTARTS count on next-based builds, on a fresh 2M-string import and a fresh BSBM 100M import.
Cause
ref_to_p_id in fluree-db-query/src/fast_path_common.rs returns an execution error when find_predicate_id misses. Three operators propagate that error with ?:
fast_string_prefix_count_all, forCOUNT(*)andSUM(STRSTARTS(...))with aSTRSTARTSfilter;fast_label_regex_type, for label +rdf:type+regex;fast_star_const_order_topk, for a constant-object star with a numeric filter andORDER BY ?label LIMIT k.
The same operators already treat a missing object or class as an empty result: term_to_ref_s_id returns None and they return an empty batch. A missing predicate is the inconsistent case. All three run only with no novelty and to_t == max_t, so a predicate missing from the index dictionary has no rows at the query's t, and empty is the correct answer.
Fix
Have ref_to_p_id report a miss rather than an error, and have each caller return its empty result: 0 for the counts, an empty batch for the other two. Each shape needs a regression test with a MustFire routing stamp, so the test exercises the fast path, and SPARQL and JSON-LD twins.
Related: #2442 (the STRSTARTS count fast path turns off after any commit).
Activity