Sparql: COUNT(DISTINCT *) returns wrong result

Hi there,
I encountered an issue were COUNT(DISTINCT *) returns always '1' when there is only one variable in scope. Feels like a bug to me.

Stardog Version: 8.0.0

To reproduce:

  1. Load Dataset [1]
  2. Execute Query: select (count (distinct *) as ?cnt) { ?x a :A }

OUTCOME: The query returns 1
EXPECTED: The query should return 2


  1. When I explicitly count the variable '?x' I get the desired result. Query: select (count (distinct ?x) as ?cnt) { ?x a :A } -> returns 2
  2. I tested the queries with another system and it returned my expected result.

[1]: Example Dataset

PREFIX    : <>
PREFIX owl: <>

:A a owl:Class .

:i a :A .
:j a :A .

Thanks for the perfect bug report. I have created PLAT-4593. We will attempt to get a fix for this in the upcoming 8.0.1 release.

The only workaround I can think of in the meantime (except of using ?x, as you found) is to add to Note that it will make Stardog manage intermediate query results on Java heap so one should be aware of possible OOMs on complex queries.

Thanks again,

That's great to hear.

Thank you.