Skip to content

Three fast-path shapes return wrong results (fast ≠ generic under the kill switch) #1652

Closed

Description

@arnaud-fluree

Summary

Three indexed-lane fast paths violate the differential contract — the same query
returns different results with FLUREE_DISABLE_QUERY_FAST_PATHS=1 on a
read-only ledger with no live novelty. In all three cases the generic pipeline's
answer is the correct one (SPARQL bag semantics); the fast path returns a
plausible wrong number with HTTP 200. Same failure class as #1628, but none of
these shapes is covered by its six cases: reproduced on the v4.1.5 release
binary and on main @ 11a8ceab8 (post-#1628).

Dataset used below: a 50M-line prefix of the DBLP N-Triples dump imported with
fluree create (any sizeable DBLP prefix reproduces; the invariant being
violated is ON == OFF, so no external reference values are needed — though for
what it's worth, two third-party engines agree with the OFF values on the same
data).

Case 1 — group-by object-count top-k drops join multiplicity (worst: ×3.5)

PREFIX dblp: <https://dblp.org/rdf/schema#>
SELECT ?o1 (COUNT(?s) AS ?count) {
  ?s dblp:bibtexType ?o1 .
  ?s dblp:hasSignature ?o2 .
} GROUP BY ?o1 ORDER BY DESC(?count) LIMIT 10
group fast path generic
bibtex#Inproceedings 735,327 2,563,236
bibtex#Incollection 34,299 77,658
bibtex#Book 4,671 10,648

The star constraint ?s dblp:hasSignature ?o2 multiplies each subject by its
number of signatures under bag semantics; the group-by top-k lane appears to
count base rows (or distinct subjects) instead of joined rows. The same
mechanism corrupts the multi-aggregate variant (COUNT + MIN + MAX +
SAMPLE over the same pattern): identical wrong counts, correct min/max/sample
columns.

Case 2 — chain fold with OPTIONAL / MINUS tail loses rows (−434)

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dblp: <https://dblp.org/rdf/schema#>
SELECT (COUNT(*) AS ?count) WHERE {
  ?a dblp:signaturePublication ?b .
  ?b rdf:type ?c .
  OPTIONAL { ?c rdfs:subClassOf ?d . }   # MINUS variant: same delta
}
  • OPTIONAL variant: fast 5,587,940 vs generic 5,588,374 (−434)
  • MINUS variant: fast 5,587,940 vs generic 5,588,374 (−434)
  • Plain inner-join variant of the same chain: fast == generic (correct)

The two modifiers lose exactly the same 434 rows while the inner join is
unaffected. That pattern points at one shared misclassification in the chain
fold's tail-weight machinery (execute_chain step 1): some "no-successor"
?c values get weight 0 through a default/edge-case path where OPTIONAL
requires max(1, ·) and MINUS requires counting them — weight 0 happens to be
correct only for the inner join, which is why only the modifier variants
diverge.

Case 3 — composite (s,o) multicolumn join count (−88)

PREFIX dblp: <https://dblp.org/rdf/schema#>
SELECT (COUNT(*) AS ?count) WHERE {
  ?s dblp:createdBy ?o .
  ?s dblp:authoredBy ?o
}

Fast 2,762,863 vs generic 2,762,951 (−88).

Repro

fluree create dblp --from dblp-prefix.nt   # any large DBLP prefix
fluree server start --listen-addr 0.0.0.0:8090
# run each query, then restart with FLUREE_DISABLE_QUERY_FAST_PATHS=1 and rerun
# fast != generic on all three shapes; ledger is read-only throughout

Notes

  • Not covered by tighten indexed fast-path eligibility guards #1628's six eligibility narrowings (verified on main after its
    merge).
  • These shapes would make good must-fire/must-not-fire pins for the span-capture
    harness introduced there — the current differential suite does not cover the
    group-by top-k bag-multiplicity case, the chain-fold OPTIONAL/MINUS tail, or
    the composite-key join.
  • A side observation while verifying: SUM(DAY(?o)) / SUM(MONTH(?o)) over an
    xsd:gYear predicate answers with day/month defaulted to 1 (fast and generic
    agree with each other), where SPARQL semantics arguably make DAY(gYear) a
    type error ignored by the aggregate (SUM over no valid values). Possibly
    intended, but worth a deliberate decision since the constant-fold fast path
    bakes it in.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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