virtuoso-opensource icon indicating copy to clipboard operation
virtuoso-opensource copied to clipboard

Wrong result of SPARQL queries with UNION and OPTIONALs

Open edom opened this issue 3 years ago • 1 comments

Version

Virtuoso version 08.03.3323 on Linux (x86_64-generic-linux-glibc25) Single Server Edition (61 GB total memory, 48 GB memory in use)

How to reproduce

  1. Open two tabs of https://dbpedia.org/sparql/ in a browser.
  2. Uncheck "Strict checking of void variables" in both tabs.
  3. Run Q1 below in tab 1.
  4. Run Q2 below in tab 2.

Q1:

SELECT ?a ?b ?c WHERE {
  { VALUES ?a { 0 } } UNION { VALUES ?a { 1 } }
  OPTIONAL { VALUES (?a ?b) { (0 1) } }
  OPTIONAL { VALUES (?a ?c) { (1 2) } }
}

Q2 (Q1 with swapped OPTIONAL clauses):

SELECT ?a ?b ?c WHERE {
  { VALUES ?a { 0 } } UNION { VALUES ?a { 1 } }
  OPTIONAL { VALUES (?a ?c) { (1 2) } }
  OPTIONAL { VALUES (?a ?b) { (0 1) } }
}

Actual result

Tab 1:

?a ?b ?c
       2

Tab 2:

?a ?b ?c
    1

Expected result

Both queries should produce the following result (modulo ordering):

?a ?b ?c
 0  1
 1     2

SPARQL playground and Wikidata also produce the correct result.

edom avatar Jun 12 '22 22:06 edom

We have been able to recreate this issue and are looking into it ...

HughWilliams avatar Jun 13 '22 08:06 HughWilliams